From 67379f8c3418417d7c4f1901475b7b06d45571a6 Mon Sep 17 00:00:00 2001 From: Kelvin Jin Date: Thu, 8 Nov 2018 16:21:29 -0800 Subject: [PATCH] fix: make no option flags behave the same as o=1 (#910) --- src/trace-api.ts | 4 ++++ test/test-trace-api.ts | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/trace-api.ts b/src/trace-api.ts index 9f38938ab..b58eb477c 100644 --- a/src/trace-api.ts +++ b/src/trace-api.ts @@ -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 === diff --git a/test/test-trace-api.ts b/test/test-trace-api.ts index bc57ac765..aae53d644 100644 --- a/test/test-trace-api.ts +++ b/test/test-trace-api.ts @@ -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';