Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 25ffeb7

Browse files
committed
Make the google header configurable
1 parent b1edb7e commit 25ffeb7

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/opencensus-propagation-stackdriver/src/stackdriver-format.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,22 @@ const TRACE_TRUE = 0x1;
4242

4343
/** Propagates span context through Stackdriver Format propagation. */
4444
export class StackdriverFormat implements Propagation {
45+
headerName: string;
46+
47+
constructor(config?: { headerName?: string }) {
48+
if (config && config.headerName) {
49+
this.headerName = config.headerName;
50+
} else {
51+
this.headerName = TRACE_CONTEXT_HEADER_NAME;
52+
}
53+
}
4554
/**
4655
* Gets the span context from a request headers. If there is no span context
4756
* in the headers, null is returned.
4857
* @param getter
4958
*/
5059
extract(getter: HeaderGetter): SpanContext | null {
51-
const traceContextHeader = getter.getHeader(TRACE_CONTEXT_HEADER_NAME);
60+
const traceContextHeader = getter.getHeader(this.headerName);
5261
if (typeof traceContextHeader !== 'string') {
5362
return null;
5463
}
@@ -83,7 +92,7 @@ export class StackdriverFormat implements Propagation {
8392
header += `;o=${spanContext.options}`;
8493
}
8594

86-
setter.setHeader(TRACE_CONTEXT_HEADER_NAME, header);
95+
setter.setHeader(this.headerName, header);
8796
}
8897

8998
/** Generate SpanContexts */

0 commit comments

Comments
 (0)