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

Commit 7a9bc44

Browse files
committed
Make the google header configurable
1 parent b1edb7e commit 7a9bc44

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,23 @@ 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 || {}).headerName) {
49+
// @ts-ignore
50+
this.headerName = config.headerName;
51+
} else {
52+
this.headerName = TRACE_CONTEXT_HEADER_NAME;
53+
}
54+
}
4555
/**
4656
* Gets the span context from a request headers. If there is no span context
4757
* in the headers, null is returned.
4858
* @param getter
4959
*/
5060
extract(getter: HeaderGetter): SpanContext | null {
51-
const traceContextHeader = getter.getHeader(TRACE_CONTEXT_HEADER_NAME);
61+
const traceContextHeader = getter.getHeader(this.headerName);
5262
if (typeof traceContextHeader !== 'string') {
5363
return null;
5464
}
@@ -83,7 +93,7 @@ export class StackdriverFormat implements Propagation {
8393
header += `;o=${spanContext.options}`;
8494
}
8595

86-
setter.setHeader(TRACE_CONTEXT_HEADER_NAME, header);
96+
setter.setHeader(this.headerName, header);
8797
}
8898

8999
/** Generate SpanContexts */

0 commit comments

Comments
 (0)