Skip to content

Add B3 format #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ The OpenTracing standard JavaScript API is [documented here](https://doc.esdoc.o
* `transport` `string` *optional*, *default=proto* - when `transport` is set to `thrift`, the Tracer will use Thrift as its transport instead of Proto over HTTP.
* `logger` `function(level: string, message: string, payload: any): void` *optional* - specify a custom logger function. Possible `level` values are `debug`, `info`, `warn` and `error`. By default messages will be logged to the console.
* `disable_meta_event_reporting` `bool` *optional*, *default=false* - when `disable_meta_event_reporting` is set to `true`, the tracer will disable meta event reporting even if requested by the Satellite.
* `propagator` `dictionary` *optional*, *defaults=*`{opentracing.FORMAT_HTTP: LightStepPropagator, opentracing.FORMAT_TEXT_MAP: LightStepPropagator, opentracing.FORMAT_BINARY: UnsupportedPropagator}`: Allows inject/extract to use custom propagators for different formats. This package includes a `B3Propagator` that supports B3 headers on text maps and http headers.

### SpanImp

Expand Down
523 changes: 369 additions & 154 deletions dist/lightstep-tracer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lightstep-tracer.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/lightstep-tracer.min.js

Large diffs are not rendered by default.

64 changes: 48 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ export const LS_META_INJECT = 'lightstep.inject_span';
export const LS_META_SP_START = 'lightstep.span_start';
export const LS_META_SP_FINISH = 'lightstep.span_finish';
export const LS_META_TRACER_CREATE = 'lightstep.tracer_create';

export const FORMAT_B3 = 'format.b3';
14 changes: 14 additions & 0 deletions src/imp/propagator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default class UnsupportedPropagator {
constructor(tracer, name) {
this._tracer = tracer;
this._name = name;
}
inject(spanContext, carrier) {
this._tracer._error(`Unsupported format: ${this._name}`);
return null;
}
extract(carrier) {
this._tracer._error(`Unsupported format: ${this._name}`);
}
}

29 changes: 29 additions & 0 deletions src/imp/propagator_b3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import LightStepPropagator from './propagator_ls';

const CARRIER_B3_TRACER_STATE_PREFIX = 'x-b3-';

export default class B3Propagator extends LightStepPropagator {
constructor(tracer) {
super(tracer);
this._carrierPrefix = CARRIER_B3_TRACER_STATE_PREFIX;
}

inject(spanContext, carrier) {
if (!carrier) {
this._tracer._error('Unexpected null carrier in call to inject');
return;
}
if (typeof carrier !== 'object') {
this._tracer._error(`Unexpected '${typeof carrier}' FORMAT_TEXT_MAP carrier in call to inject`);
return;
}

carrier[`${this._carrierPrefix}spanid`] = spanContext._guid;
carrier[`${this._carrierPrefix}traceid`] = spanContext.traceGUID();
carrier[`${this._carrierPrefix}sampled`] = 'true';
spanContext.forEachBaggageItem((key, value) => {
carrier[`${this._baggagePrefix}${key}`] = value;
});
return carrier;
}
}
Loading