Skip to content

Commit 6484775

Browse files
committed
[#229] Support TraceRoot
* Refactoring Trace, AsyncTrace, DisableTrace and AsyncDisableTrace With TraceRoot * continueTrace parent Information header parsing * implements TraceId
1 parent 10f5e38 commit 6484775

38 files changed

+857
-186
lines changed

lib/config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ const path = require('path')
1010
const fs = require('fs')
1111
const defaultConfig = require('./pinpoint-config-default')
1212
const log = require('./utils/logger')
13-
const { setLog } = require('./supports')
14-
const { makeLogLevelLog } = require('./utils/log/log-level-logger')
1513
const ServiceConfigBuilder = require('./client/retry/service-config-builder')
1614

1715
const valueOfString = (envName) => {
@@ -147,7 +145,6 @@ const init = (initOptions = {}) => {
147145
readConfigJson(initOptions))
148146

149147
log.init(agentConfig.logLevel)
150-
setLog(makeLogLevelLog(agentConfig.logLevel))
151148

152149
Object.entries(REQUIRE_CONFIG).forEach(([propertyName, description]) => {
153150
if (agentConfig.enable && !agentConfig[propertyName]) {

lib/context/async-id.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ class AsyncId {
1313
static asyncIdGenerator = new SequenceGenerator(1)
1414
static nonAsyncId = new AsyncId(0, 0)
1515

16+
// DefaultAsyncIdGenerator.java: nextAsyncId()
17+
static make() {
18+
return new AsyncId(AsyncId.asyncIdGenerator.next, 0)
19+
}
20+
1621
constructor(asyncId, sequence) {
1722
this.asyncId = asyncId
1823
this.sequence = sequence
@@ -31,6 +36,11 @@ class AsyncId {
3136
return new AsyncId(asyncId, this.sequence + 1)
3237
}
3338

39+
// DefaultAsyncId.java: nextLocalAsyncId
40+
nextLocalAsyncId2() {
41+
return new AsyncId(this.asyncId, this.sequence + 1)
42+
}
43+
3444
sequenceNextLocalAsyncId() {
3545
if (this === AsyncId.nonAsyncId) {
3646
return this.nextLocalAsyncId()

lib/context/disable-span-recorder.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ class DisableSpanRecorder {
2424
recordRemoteAddr() {}
2525

2626
recordException() {}
27-
28-
recordSpanEvent() {}
2927
}
3028

3129
module.exports = DisableSpanRecorder

lib/context/disable-trace.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class DisableTrace {
1616
this.spanRecorder = new DisableSpanRecorder()
1717
}
1818

19+
getTraceRoot() {
20+
return this.traceRoot
21+
}
22+
1923
traceBlockBegin() {
2024
return new DisableSpanEventRecorder()
2125
}

lib/context/remote-trace-root-builder.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
'use strict'
88

9-
const TraceRootBuilder = require("./trace-root-builder")
10-
const TraceIdBuilder = require("./trace/trace-id-builder")
9+
const TraceRootBuilder = require('./trace-root-builder')
10+
const TraceIdBuilder = require('./trace/trace-id-builder')
1111

1212
class RemoteTraceRoot {
1313
constructor(traceId, traceRoot) {
@@ -18,6 +18,10 @@ class RemoteTraceRoot {
1818
getTraceStartTime() {
1919
return this.traceRoot.getTraceStartTime()
2020
}
21+
22+
isSampled() {
23+
return true
24+
}
2125
}
2226

2327
class RemoteTraceRootBuilder {

lib/context/sequence-generator.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ class SequenceGenerator {
2424
return this.next.toString()
2525
}
2626

27+
getAndIncrement() {
28+
if (this.sequence > this.maxValue) {
29+
this.sequence = this.initValue
30+
}
31+
return this.sequence++
32+
}
33+
2734
// for test
2835
reset() {
2936
this.sequence = this.initValue

lib/context/span-builder.js

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,74 @@
99
class Span {
1010
constructor(traceRoot) {
1111
this.traceRoot = traceRoot
12-
this.startTime = traceRoot.getTraceStartTime()
1312
}
1413
}
1514

1615
class SpanBuilder {
1716
constructor(traceRoot) {
1817
this.traceRoot = traceRoot
18+
this.annotations = []
19+
this.startTime = traceRoot.getTraceStartTime()
20+
}
21+
22+
setApiId(apiId) {
23+
this.apiId = apiId
24+
return this
25+
}
26+
27+
setRpc(rpc) {
28+
this.rpc = rpc
29+
return this
30+
}
31+
32+
setEndPoint(endPoint) {
33+
this.endPoint = endPoint
34+
return this
35+
}
36+
37+
setRemoteAddress(remoteAddress) {
38+
this.remoteAddress = remoteAddress
39+
return this
40+
}
41+
42+
addAnnotation(annotation) {
43+
this.annotations.push(annotation)
44+
return this
45+
}
46+
47+
setExceptionInfo(id, message) {
48+
this.exceptionInfo = { id, message }
49+
return this
50+
}
51+
52+
setAcceptorHost(acceptorHost) {
53+
this.acceptorHost = acceptorHost
54+
return this
55+
}
56+
57+
setParentApplicationName(parentApplicationName) {
58+
this.parentApplicationName = parentApplicationName
59+
return this
60+
}
61+
62+
setParentApplicationType(parentApplicationType) {
63+
this.parentApplicationType = parentApplicationType
64+
return this
1965
}
2066

2167
build() {
22-
return new Span(this.traceRoot)
68+
const span = new Span(this.traceRoot)
69+
this.startTime = this.startTime || Date.now()
70+
span.apiId = this.apiId
71+
span.rpc = this.rpc
72+
span.endPoint = this.endPoint
73+
span.remoteAddress = this.remoteAddress
74+
span.annotations = this.annotations
75+
span.exceptionInfo = this.exceptionInfo
76+
span.acceptorHost = this.acceptorHost
77+
span.parentApplicationName = this.parentApplicationName
78+
span.parentApplicationType = this.parentApplicationType
79+
return span
2380
}
2481
}
2582

lib/context/span-chunk-builder.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
*/
66

77
'use strict'
8-
class SpanChunk {
9-
constructor(traceRoot, spanEventList) {
10-
this.traceRoot = traceRoot
11-
this.spanEventList = spanEventList
12-
}
13-
}
8+
9+
const SpanChunk = require('./trace/span-chunk2')
1410

1511
class SpanChunkBuilder {
1612
constructor(traceRoot) {

lib/context/span-id.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
// SpanId.java in Java agent
1010
class SpanId {
11+
static nullSpanId = -1
12+
1113
constructor () {
1214
this.MAX_NUM = Number.MAX_SAFE_INTEGER
1315
}

lib/context/span-recorder.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ class SpanRecorder {
7777
this.span.err = 1
7878
}
7979
}
80-
81-
recordSpanEvent(spanEvent) {
82-
if (this.span && spanEvent) {
83-
this.span.spanEventList.push(spanEvent)
84-
}
85-
}
8680
}
8781

8882
module.exports = SpanRecorder

0 commit comments

Comments
 (0)