Skip to content

Commit

Permalink
tracing: Adds isRemote to the span context (#4153)
Browse files Browse the repository at this point in the history
* tracing: Adds isRemote to the span context

* convert default value to true to align with python
  • Loading branch information
mabdinur authored and juan-fernandez committed Mar 20, 2024
1 parent 4138bf5 commit 9144242
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/dd-trace/src/opentracing/propagation/text_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ class TextMapPropagator {
return new DatadogSpanContext({
traceId: id(),
spanId: null,
sampling: { priority }
sampling: { priority },
isRemote: true
})
}

Expand Down Expand Up @@ -327,6 +328,7 @@ class TextMapPropagator {
const spanContext = new DatadogSpanContext({
traceId: id(traceId, 16),
spanId: id(spanId, 16),
isRemote: true,
sampling: { priority: parseInt(flags, 10) & 1 ? 1 : 0 },
traceparent,
tracestate
Expand Down Expand Up @@ -379,7 +381,8 @@ class TextMapPropagator {

return new DatadogSpanContext({
traceId: id(carrier[traceKey], radix),
spanId: id(carrier[spanKey], radix)
spanId: id(carrier[spanKey], radix),
isRemote: true
})
}

Expand Down
2 changes: 2 additions & 0 deletions packages/dd-trace/src/opentracing/span.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ class DatadogSpan {
if (startTime) {
spanContext._trace.startTime = startTime
}
// SpanContext was NOT propagated from a remote parent
spanContext._isRemote = false

return spanContext
}
Expand Down
1 change: 1 addition & 0 deletions packages/dd-trace/src/opentracing/span_context.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DatadogSpanContext {

this._traceId = props.traceId
this._spanId = props.spanId
this._isRemote = props.isRemote ?? true
this._parentId = props.parentId || null
this._name = props.name
this._isFinished = props.isFinished || false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('TextMapPropagator', () => {
const spanContext = new SpanContext({
traceId: id('123', 10),
spanId: id('456', 10),
isRemote: true,
baggageItems,
...params,
trace: {
Expand Down Expand Up @@ -326,6 +327,7 @@ describe('TextMapPropagator', () => {
expect(spanContext.toTraceId()).to.equal(carrier['x-datadog-trace-id'])
expect(spanContext.toSpanId()).to.equal(carrier['x-datadog-parent-id'])
expect(spanContext._baggageItems['foo']).to.equal(carrier['ot-baggage-foo'])
expect(spanContext._isRemote).to.equal(true)
})

it('should convert signed IDs to unsigned', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/dd-trace/test/opentracing/span.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('Span', () => {

expect(span.context()._traceId).to.deep.equal('123')
expect(span.context()._spanId).to.deep.equal('123')
expect(span.context()._isRemote).to.deep.equal(false)
})

it('should add itself to the context trace started spans', () => {
Expand Down Expand Up @@ -148,6 +149,7 @@ describe('Span', () => {
expect(span.context()._parentId).to.deep.equal('456')
expect(span.context()._baggageItems).to.deep.equal({ foo: 'bar' })
expect(span.context()._trace).to.equal(parent._trace)
expect(span.context()._isRemote).to.equal(false)
})

it('should generate a 128-bit trace ID when configured', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/dd-trace/test/opentracing/span_context.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('SpanContext', () => {
traceId: '123',
spanId: '456',
parentId: '789',
isRemote: false,
name: 'test',
isFinished: true,
tags: {},
Expand All @@ -41,6 +42,7 @@ describe('SpanContext', () => {
_traceId: '123',
_spanId: '456',
_parentId: '789',
_isRemote: false,
_name: 'test',
_isFinished: true,
_tags: {},
Expand Down Expand Up @@ -68,6 +70,7 @@ describe('SpanContext', () => {
_traceId: '123',
_spanId: '456',
_parentId: null,
_isRemote: true,
_name: undefined,
_isFinished: false,
_tags: {},
Expand Down

0 comments on commit 9144242

Please sign in to comment.