From 7a9bc44f572a923f0b9ff7517683bf38a0ce9967 Mon Sep 17 00:00:00 2001 From: Nick Humrich Date: Thu, 2 Jul 2020 10:35:26 -0600 Subject: [PATCH] Make the google header configurable --- .../src/stackdriver-format.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/opencensus-propagation-stackdriver/src/stackdriver-format.ts b/packages/opencensus-propagation-stackdriver/src/stackdriver-format.ts index aee305869..7be36164b 100644 --- a/packages/opencensus-propagation-stackdriver/src/stackdriver-format.ts +++ b/packages/opencensus-propagation-stackdriver/src/stackdriver-format.ts @@ -42,13 +42,23 @@ const TRACE_TRUE = 0x1; /** Propagates span context through Stackdriver Format propagation. */ export class StackdriverFormat implements Propagation { + headerName: string; + + constructor(config?: { headerName?: string }) { + if ((config || {}).headerName) { + // @ts-ignore + this.headerName = config.headerName; + } else { + this.headerName = TRACE_CONTEXT_HEADER_NAME; + } + } /** * Gets the span context from a request headers. If there is no span context * in the headers, null is returned. * @param getter */ extract(getter: HeaderGetter): SpanContext | null { - const traceContextHeader = getter.getHeader(TRACE_CONTEXT_HEADER_NAME); + const traceContextHeader = getter.getHeader(this.headerName); if (typeof traceContextHeader !== 'string') { return null; } @@ -83,7 +93,7 @@ export class StackdriverFormat implements Propagation { header += `;o=${spanContext.options}`; } - setter.setHeader(TRACE_CONTEXT_HEADER_NAME, header); + setter.setHeader(this.headerName, header); } /** Generate SpanContexts */