Skip to content

Commit

Permalink
feat: allow users to specify a propagation mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
kjin committed May 17, 2019
1 parent 220b6a5 commit f700581
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ export interface Config {
*/
tracePolicy?: TracePolicy;

/**
* If specified, the Trace Agent will use this context header propagation
* implementation instead of @opencensus/propagation-stackdriver, the default
* trace context header format.
*/
propagation?: OpenCensusPropagation;

/**
* Buffer the captured traces for `flushDelaySeconds` seconds before
* publishing to the Stackdriver Trace API, unless the buffer fills up first.
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ function initConfig(userConfig: Forceable<Config>): Forceable<TopLevelConfig> {
contextHeaderBehavior: mergedConfig.contextHeaderBehavior as
TraceContextHeaderBehavior
},
overrides: {tracePolicy: mergedConfig.tracePolicy}
overrides: {
tracePolicy: mergedConfig.tracePolicy,
propagation: mergedConfig.propagation
}
};
}

Expand Down
8 changes: 5 additions & 3 deletions src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {v1 as stackdriverPropagation} from '@opencensus/propagation-stackdriver'
import * as path from 'path';

import {cls, TraceCLSConfig} from './cls';
import {TracePolicy} from './config';
import {OpenCensusPropagation, TracePolicy} from './config';
import {LEVELS, Logger} from './logger';
import {StackdriverTracer} from './trace-api';
import {pluginLoader, PluginLoaderConfig} from './trace-plugin-loader';
Expand All @@ -31,7 +31,8 @@ export type TopLevelConfig = {
writerConfig: TraceWriterConfig;
pluginLoaderConfig: PluginLoaderConfig;
tracePolicyConfig: TracePolicyConfig;
overrides: {tracePolicy?: TracePolicy;};
overrides:
{tracePolicy?: TracePolicy; propagation?: OpenCensusPropagation;};
}|{
enabled: false;
};
Expand Down Expand Up @@ -121,7 +122,8 @@ export class Tracing implements Component {

const tracePolicy = this.config.overrides.tracePolicy ||
new BuiltinTracePolicy(this.config.tracePolicyConfig);
const propagation = stackdriverPropagation;
const propagation =
this.config.overrides.propagation || stackdriverPropagation;

const tracerComponents = {logger: this.logger, tracePolicy, propagation};

Expand Down

0 comments on commit f700581

Please sign in to comment.