Skip to content

Commit d46e32a

Browse files
authored
Adds B3 propagator (#177)
* initial commit * ckpt * ftb * adds options * Update README.md * propagate sampled flag * add test and cleanup
1 parent 8c04546 commit d46e32a

14 files changed

+722
-300
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ The OpenTracing standard JavaScript API is [documented here](https://doc.esdoc.o
103103
* `transport` `string` *optional*, *default=proto* - when `transport` is set to `thrift`, the Tracer will use Thrift as its transport instead of Proto over HTTP.
104104
* `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.
105105
* `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.
106+
* `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.
106107

107108
### SpanImp
108109

dist/lightstep-tracer.js

+394-156
Large diffs are not rendered by default.

dist/lightstep-tracer.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lightstep-tracer.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+48-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/constants.js

+2
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ export const LS_META_INJECT = 'lightstep.inject_span';
3434
export const LS_META_SP_START = 'lightstep.span_start';
3535
export const LS_META_SP_FINISH = 'lightstep.span_finish';
3636
export const LS_META_TRACER_CREATE = 'lightstep.tracer_create';
37+
38+
export const FORMAT_B3 = 'format.b3';

src/imp/propagator.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default class UnsupportedPropagator {
2+
constructor(tracer, name) {
3+
this._tracer = tracer;
4+
this._name = name;
5+
}
6+
inject(spanContext, carrier) {
7+
this._tracer._error(`Unsupported format: ${this._name}`);
8+
return null;
9+
}
10+
extract(carrier) {
11+
this._tracer._error(`Unsupported format: ${this._name}`);
12+
}
13+
}
14+

src/imp/propagator_b3.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import LightStepPropagator from './propagator_ls';
2+
3+
const CARRIER_B3_TRACER_STATE_PREFIX = 'x-b3-';
4+
5+
export default class B3Propagator extends LightStepPropagator {
6+
constructor(tracer) {
7+
super(tracer);
8+
this._carrierPrefix = CARRIER_B3_TRACER_STATE_PREFIX;
9+
}
10+
11+
inject(spanContext, carrier) {
12+
if (!carrier) {
13+
this._tracer._error('Unexpected null carrier in call to inject');
14+
return;
15+
}
16+
if (typeof carrier !== 'object') {
17+
this._tracer._error(`Unexpected '${typeof carrier}' FORMAT_TEXT_MAP carrier in call to inject`);
18+
return;
19+
}
20+
21+
carrier[`${this._carrierPrefix}spanid`] = spanContext._guid;
22+
carrier[`${this._carrierPrefix}traceid`] = spanContext.traceGUID();
23+
if (spanContext._sampled) {
24+
carrier[`${this._carrierPrefix}sampled`] = '1';
25+
} else {
26+
carrier[`${this._carrierPrefix}sampled`] = '0';
27+
}
28+
spanContext.forEachBaggageItem((key, value) => {
29+
carrier[`${this._baggagePrefix}${key}`] = value;
30+
});
31+
return carrier;
32+
}
33+
}

0 commit comments

Comments
 (0)