Skip to content

Commit 5507950

Browse files
committed
[#254] Fix wrong startElapsedTime bug
* Fix toString method
1 parent 9799b40 commit 5507950

File tree

10 files changed

+103
-47
lines changed

10 files changed

+103
-47
lines changed

demo/express/ecosystem.config.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,48 @@
11
module.exports = {
2-
apps : [{
3-
name: 'agent',
2+
apps: [{
3+
name: 'ServiceWithAgent',
44
script: './bin/www',
55

66
// Options reference: https://pm2.keymetrics.io/docs/usage/application-declaration/
77
autorestart: true,
8-
watch: false,
98
max_memory_restart: '1G',
10-
instances: 0,
9+
instances: 1,
1110
env: {
1211
NODE_ENV: 'development',
13-
"PINPOINT_CONTAINER": "false",
14-
// "PINPOINT_AGENT_ID": "express-node-js-id",
1512
"PINPOINT_APPLICATION_NAME": "express.node.js",
1613
"PINPOINT_COLLECTOR_IP": "localhost",
17-
"PINPOINT_LOG_LEVEL": "DEBUG",
18-
// "PINPOINT_SAMPLING_RATE": "1",
14+
"PINPOINT_LOG_LEVEL": "WARN",
15+
"PINPOINT_SAMPLING_RATE": "10",
16+
},
17+
env_production: {
18+
NODE_ENV: 'production',
19+
"PINPOINT_APPLICATION_NAME": "express.node.js",
20+
"PINPOINT_COLLECTOR_IP": "localhost",
21+
"PINPOINT_LOG_LEVEL": "WARN",
22+
"PINPOINT_SAMPLING_RATE": "10",
23+
},
24+
"io": {
25+
"conf": {
26+
"metrics": {
27+
"http": false
28+
}
29+
}
30+
},
31+
}, {
32+
name: 'Service',
33+
script: './bin/www',
34+
35+
// Options reference: https://pm2.keymetrics.io/docs/usage/application-declaration/
36+
autorestart: true,
37+
max_memory_restart: '1G',
38+
instances: 0,
39+
env: {
40+
NODE_ENV: 'development',
41+
PINPOINT_ENABLE: 'false'
1942
},
2043
env_production: {
2144
NODE_ENV: 'production',
45+
PINPOINT_ENABLE: 'false'
2246
}
2347
}],
24-
};
48+
}

demo/express/package-lock.json

Lines changed: 47 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/express/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
"morgan": "~1.9.1",
1717
"mysql": "^2.18.1",
1818
"mysql2": "^3.9.1",
19-
"pinpoint-node-agent": "^0.8.6"
19+
"pinpoint-node-agent": "^0.9.0"
2020
}
2121
}

lib/context/async-id.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class AsyncId {
5757
return pLocalAsyncId
5858
}
5959

60-
tosString() {
60+
toString() {
6161
return `AsyncId(asyncId=${this.asyncId}, sequence=${this.sequence})`
6262
}
6363
}

lib/context/span-builder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class SpanBuilder {
151151
build() {
152152
const span = new Span(this.traceRoot)
153153
span.serviceType = this.serviceType
154-
span.startTime = this.startTime || Date.now()
154+
span.startTime = this.startTime ?? Date.now()
155155
span.elapsedTime = this.elapsedTime
156156
span.apiId = this.apiId
157157
span.rpc = this.rpc

lib/context/trace/span-event-builder.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class SpanEvent {
5151

5252
return pSpanEvent
5353
}
54+
55+
toString() {
56+
return `SpanEvent(sequence=${this.sequence}, depth=${this.depth}, startElapsedTime=${this.startElapsedTime}, elapsedTime=${this.elapsedTime}, startTime=${this.startTime}, serviceType=${this.serviceType}, apiId=${this.apiId}, asyncId=${this.asyncId}, nextSpanId=${this.nextSpanId}, destinationId=${this.destinationId}, endPoint=${this.endPoint}, exceptionInfo=${this.exceptionInfo}, annotations=${this.annotations})`
57+
}
5458
}
5559

5660

@@ -190,7 +194,7 @@ class SpanEventBuilder {
190194
return SpanEvent.nullObject
191195
}
192196

193-
if (!this.elapsedTime) {
197+
if (typeof this.elapsedTime === 'undefined') {
194198
this.markAfterTime()
195199
}
196200

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"internal-ip": "^3.0.1",
5959
"loglevel": "^1.6.1",
6060
"murmur-128": "^1.0.0",
61-
"require-in-the-middle": "^5.0.3",
61+
"require-in-the-middle": "^5.2.0",
6262
"semver": "^7.5.3"
6363
},
6464
"devDependencies": {

test/client/grpc-data-sender.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ test('sendSpanChunk redis.SET.end', function (t) {
210210
t.equal(pSpanEvent.getDepth(), 2, 'depth')
211211

212212
const expectedSpanChunk = repository.dataSender.findSpanChunk(childTraceBuilder.localAsyncId)
213-
const expectedSpanEvent = expectedSpanChunk.spanEventList[0]
213+
const expectedSpanEvent = expectedSpanChunk.spanEventList[1]
214214
t.equal(pSpanEvent.getStartelapsed(), expectedSpanEvent.startElapsedTime, `pSpanEvent.getStartelapsed() : ${pSpanEvent.getStartelapsed()}, expectedSpanEvent.startElapsedTime : ${expectedSpanEvent.startElapsedTime}`)
215215
t.equal(pSpanEvent.getEndelapsed(), expectedSpanEvent.elapsedTime, `pSpanEvent.getEndelapsed() : ${pSpanEvent.getEndelapsed()}, expectedSpanEvent.elapsedTime : ${expectedSpanEvent.elapsedTime}`)
216216
t.equal(pSpanEvent.getServicetype(), 8200, 'serviceType')

test/instrumentation/context/nested-async-trace.test.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const resetSpanOrSpanChunks = () => {
5353
const getSpanOrSpanChunks = () => {
5454
return spanOrSpanChunks
5555
}
56-
const getSpanChunk = (asyncId) =>{
56+
const getSpanChunk = (asyncId) => {
5757
return getSpanOrSpanChunks().find(spanOrSpanChunk => spanOrSpanChunk.getLocalasyncid().getAsyncid() === asyncId.getAsyncId() && spanOrSpanChunk.getLocalasyncid().getSequence() === asyncId.getSequence())
5858
}
5959

@@ -68,7 +68,7 @@ const spanMessageStreamService = (call) => {
6868
spanMessageEndEventCallback?.()
6969
}
7070
})
71-
call.on('end', () => {})
71+
call.on('end', () => { })
7272
}
7373

7474
function sendAgentStat(call, callback) {
@@ -283,6 +283,11 @@ test(`nested mysql async query with express`, async (t) => {
283283
trace.repository.dataSender.close()
284284
}
285285

286+
app.use(express.json())
287+
app.use(express.urlencoded({
288+
extended: false
289+
}))
290+
286291
const server = app.listen(5006, async () => {
287292
const result = await axios.get('http://localhost:5006/test1')
288293
t.equal(result.status, 200, 'status is 200')
@@ -376,7 +381,7 @@ test(`nested mysql2 async query with express`, async (t) => {
376381
t.true(trace.spanBuilder.remoteAddress === '127.0.0.1' || trace.spanBuilder.remoteAddress === '::1', `remoteAddress is ${trace.spanBuilder.remoteAddress}`)
377382
let actualBuilder = new MethodDescriptorBuilder(expected('get', 'app.get'))
378383
.setClassName(expected('app', 'Function'))
379-
.setLineNumber(332)
384+
.setLineNumber(337)
380385
.setFileName('nested-async-trace.test.js')
381386
let actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
382387
let actualSpanEvent = trace.spanBuilder.spanEventList.find(spanEvent => spanEvent.sequence === 0)
@@ -389,7 +394,7 @@ test(`nested mysql2 async query with express`, async (t) => {
389394
t.equal(actualSpanEvent.serviceType, expressServiceType.getCode(), 'serviceType is express')
390395

391396
actualBuilder = new MethodDescriptorBuilder('createConnection')
392-
.setLineNumber(333)
397+
.setLineNumber(338)
393398
.setFileName('nested-async-trace.test.js')
394399
actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
395400
actualSpanEvent = trace.spanBuilder.spanEventList.find(spanEvent => spanEvent.sequence === 1)
@@ -402,7 +407,7 @@ test(`nested mysql2 async query with express`, async (t) => {
402407

403408
actualBuilder = new MethodDescriptorBuilder('query')
404409
.setClassName('Connection')
405-
.setLineNumber(343)
410+
.setLineNumber(348)
406411
.setFileName('nested-async-trace.test.js')
407412
actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
408413
actualSpanEvent = trace.spanBuilder.spanEventList.find(spanEvent => spanEvent.sequence === 2)
@@ -424,7 +429,7 @@ test(`nested mysql2 async query with express`, async (t) => {
424429

425430
actualBuilder = new MethodDescriptorBuilder('query')
426431
.setClassName('Connection')
427-
.setLineNumber(349)
432+
.setLineNumber(354)
428433
.setFileName('nested-async-trace.test.js')
429434
actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
430435
actualSpanEvent = actualSpanChunk.spanEventList[1]

0 commit comments

Comments
 (0)