|
6 | 6 |
|
7 | 7 | 'use strict' |
8 | 8 |
|
| 9 | +const spanId = require('../span-id') |
| 10 | + |
| 11 | +// DefaultTraceId.java |
9 | 12 | class TraceId { |
10 | | - constructor(agentId, agentStartTime, transactionId) { |
| 13 | + constructor(agentId, agentStartTime, transactionId, parentSpanId, spanId, flags) { |
11 | 14 | this.agentId = agentId |
12 | 15 | this.agentStartTime = agentStartTime |
13 | 16 | this.transactionId = transactionId |
| 17 | + this.parentSpanId = parentSpanId |
| 18 | + this.spanId = spanId |
| 19 | + this.flags = flags |
| 20 | + } |
| 21 | + |
| 22 | + getAgentId() { |
| 23 | + return this.agentId |
| 24 | + } |
| 25 | + |
| 26 | + getAgentStartTime() { |
| 27 | + return this.agentStartTime |
| 28 | + } |
| 29 | + |
| 30 | + getTransactionId() { |
| 31 | + return this.transactionId |
| 32 | + } |
| 33 | + |
| 34 | + getParentSpanId() { |
| 35 | + return this.parentSpanId |
| 36 | + } |
| 37 | + |
| 38 | + getSpanId() { |
| 39 | + return this.spanId |
| 40 | + } |
| 41 | + |
| 42 | + isRoot() { |
| 43 | + return this.parentSpanId === spanId.nullSpanId |
| 44 | + } |
| 45 | + |
| 46 | + toString() { |
| 47 | + return `TraceId(agentId=${this.agentId}, agentStartTime=${this.agentStartTime}, transactionId=${this.transactionId}, parentSpanId=${this.parentSpanId} |
| 48 | + , spanId=${this.spanId}, flags=${this.flags})` |
14 | 49 | } |
15 | 50 | } |
16 | 51 |
|
17 | 52 | class TraceIdBuilder { |
18 | 53 | constructor(agentInfo, transactionId) { |
19 | 54 | this.agentInfo = agentInfo |
20 | 55 | this.transactionId = transactionId |
| 56 | + this.parentSpanId = spanId.nullSpanId |
| 57 | + } |
| 58 | + |
| 59 | + setSpanId(spanId) { |
| 60 | + this.spanId = spanId |
| 61 | + return this |
| 62 | + } |
| 63 | + |
| 64 | + setParentSpanId(parentSpanId) { |
| 65 | + this.parentSpanId = parentSpanId |
| 66 | + return this |
21 | 67 | } |
22 | 68 |
|
23 | 69 | build() { |
24 | | - return new TraceId(this.agentInfo.agentId, this.agentInfo.agentStartTime, this.transactionId) |
| 70 | + const spanId = this.spanId ?? spanId.newSpanId() |
| 71 | + return new TraceId(this.agentInfo.agentId, this.agentInfo.agentStartTime, this.transactionId, this.parentSpanId, spanId, 0) |
25 | 72 | } |
26 | 73 | } |
27 | 74 |
|
|
0 commit comments