Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add IsRemote field to SpanContext, set by propagators #451

Merged
merged 5 commits into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class B3Format implements HttpTextFormat {
return {
traceId,
spanId,
isRemote: true,
traceFlags: isNaN(Number(options))
? TraceFlags.UNSAMPLED
: Number(options),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ export class BinaryTraceContext implements BinaryFormat {
) {
return null;
}

result.isRemote = true;

// See serializeSpanContext for byte offsets.
result.traceId = toHex(buf.slice(TRACE_ID_OFFSET, SPAN_ID_FIELD_ID_OFFSET));
result.spanId = toHex(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export class HttpTraceContext implements HttpTextFormat {
const spanContext = parse(traceParent);
if (!spanContext) return null;

spanContext.isRemote = true;

const traceStateHeader = carrier[TRACE_STATE_HEADER];
if (traceStateHeader) {
// If more than one `tracestate` header is found, we merge them into a
Expand Down
6 changes: 6 additions & 0 deletions packages/opentelemetry-core/test/context/B3Format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe('B3Format', () => {
spanId: '6e0c63257de34c92',
traceFlags: TraceFlags.UNSAMPLED,
traceState: new TraceState('foo=bar,baz=qux'),
isRemote: false,
};

b3Format.inject(spanContext, 'B3Format', carrier);
Expand Down Expand Up @@ -101,6 +102,7 @@ describe('B3Format', () => {
assert.deepStrictEqual(extractedSpanContext, {
spanId: 'b7ad6b7169203331',
traceId: '0af7651916cd43dd8448eb211c80319c',
isRemote: true,
traceFlags: TraceFlags.UNSAMPLED,
});
});
Expand All @@ -114,6 +116,7 @@ describe('B3Format', () => {
assert.deepStrictEqual(extractedSpanContext, {
spanId: 'b7ad6b7169203331',
traceId: '0af7651916cd43dd8448eb211c80319c',
isRemote: true,
traceFlags: TraceFlags.SAMPLED,
});
});
Expand All @@ -127,6 +130,7 @@ describe('B3Format', () => {
assert.deepStrictEqual(extractedSpanContext, {
spanId: 'b7ad6b7169203331',
traceId: '0af7651916cd43dd8448eb211c80319c',
isRemote: true,
traceFlags: TraceFlags.SAMPLED,
});
});
Expand All @@ -140,6 +144,7 @@ describe('B3Format', () => {
assert.deepStrictEqual(extractedSpanContext, {
spanId: 'b7ad6b7169203331',
traceId: '0af7651916cd43dd8448eb211c80319c',
isRemote: true,
traceFlags: TraceFlags.UNSAMPLED,
});
});
Expand Down Expand Up @@ -173,6 +178,7 @@ describe('B3Format', () => {
assert.deepStrictEqual(extractedSpanContext, {
spanId: 'b7ad6b7169203331',
traceId: '0af7651916cd43dd8448eb211c80319c',
isRemote: true,
traceFlags: TraceFlags.SAMPLED,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('BinaryTraceContext', () => {
binaryTraceContext.fromBytes(testCase.binary),
testCase.structured &&
Object.assign(
{ traceFlags: TraceFlags.UNSAMPLED },
{ isRemote: true, traceFlags: TraceFlags.UNSAMPLED },
testCase.structured
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('HttpTraceContext', () => {
assert.deepStrictEqual(extractedSpanContext, {
spanId: 'b7ad6b7169203331',
traceId: '0af7651916cd43dd8448eb211c80319c',
isRemote: true,
traceFlags: TraceFlags.SAMPLED,
});
});
Expand Down Expand Up @@ -106,6 +107,7 @@ describe('HttpTraceContext', () => {
assert.deepStrictEqual(extractedSpanContext, {
spanId: 'b7ad6b7169203331',
traceId: '0af7651916cd43dd8448eb211c80319c',
isRemote: true,
traceFlags: TraceFlags.SAMPLED,
});
});
Expand Down Expand Up @@ -139,6 +141,7 @@ describe('HttpTraceContext', () => {
assert.deepStrictEqual(extractedSpanContext, {
spanId: 'b7ad6b7169203331',
traceId: '0af7651916cd43dd8448eb211c80319c',
isRemote: true,
traceFlags: TraceFlags.SAMPLED,
traceState: new TraceState('foo=bar,baz=qux,quux=quuz'),
});
Expand Down
4 changes: 4 additions & 0 deletions packages/opentelemetry-types/src/trace/span_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export interface SpanContext {
* lowercase hex characters corresponding to 64 bits.
*/
spanId: string;
/**
* Only true if the SpanContext was propagated from a remote parent.
*/
isRemote?: boolean;
/**
* Trace flags to propagate.
*
Expand Down