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

Commit

Permalink
Make the google header configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
nhumrich committed Jul 2, 2020
1 parent b1edb7e commit 3d197d3
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 3d197d3

Please sign in to comment.