Skip to content

Commit

Permalink
fix: make no option flags behave the same as o=1 (#910)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjin authored Nov 9, 2018
1 parent 015f088 commit 67379f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/trace-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ export class StackdriverTracer implements Tracer {
parsedContext = util.parseContextFromHeader(options.traceContext);
}
if (parsedContext) {
if (parsedContext.options === undefined) {
// If there are no incoming option flags, default to 0x1.
parsedContext.options = 1;
}
Object.assign(incomingTraceContext, parsedContext);
} else if (
this.config!.contextHeaderBehavior ===
Expand Down
11 changes: 11 additions & 0 deletions test/test-trace-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,17 @@ describe('Trace Interface', () => {
testTraceModule.getSpans(span => span.name === 'root3').length, 0);
});

it('should trace if no option flags are provided', () => {
createTraceAgent({enhancedDatabaseReporting: false})
.runInRootSpan(
{name: 'root', traceContext: '123456/667'}, (rootSpan) => {
rootSpan.endSpan();
});
const foundTrace =
testTraceModule.getOneTrace(trace => trace.traceId === '123456');
assert.strictEqual(foundTrace.spans.length, 1);
});

describe('getting response trace context', () => {
it('should behave as expected', () => {
const fakeTraceId = 'ffeeddccbbaa99887766554433221100';
Expand Down

0 comments on commit 67379f8

Please sign in to comment.