Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
urlEncoding: false,
metrics: this._metrics,
};
let textCodec = new TextMapCodec(codecOptions);
this.registerInjector(opentracing.FORMAT_TEXT_MAP, textCodec);
this.registerExtractor(opentracing.FORMAT_TEXT_MAP, textCodec);
codecOptions.urlEncoding = true;
let httpCodec = new TextMapCodec(codecOptions);
this.registerInjector(opentracing.FORMAT_HTTP_HEADERS, httpCodec);
this.registerExtractor(opentracing.FORMAT_HTTP_HEADERS, httpCodec);
let binaryCodec = new BinaryCodec();
this.registerInjector(opentracing.FORMAT_BINARY, binaryCodec);
this.registerExtractor(opentracing.FORMAT_BINARY, binaryCodec);
const uuid = uuidv4();
this._tags[constants.TRACER_CLIENT_ID_TAG_KEY] = uuid;
this._process = {
serviceName: serviceName,
tags: Utils.convertObjectToTags(this._tags),
uuid: uuid,
};
this._debugThrottler.setProcess(this._process);
// TODO update reporter to implement ProcessSetter
this._reporter.setProcess(this._process.serviceName, this._process.tags);
this._traceId128bit = options.traceId128bit;
this._shareRpcSpan = options.shareRpcSpan;
}
switch (format) {
case opentracing.FORMAT_TEXT_MAP:
case opentracing.FORMAT_HTTP_HEADERS:
const headerName = 'traceparent';
const headerValue: string = `00-${context.traceId}-${context.spanId}-00`;
if (typeof carrier.setRequestHeader === 'function') {
carrier.setRequestHeader(headerName, headerValue);
} else if (carrier.headers && typeof carrier.headers.append === 'function') {
carrier.headers.append(headerName, headerValue);
} else {
carrier[headerName] = headerValue;
}
break;
case opentracing.FORMAT_BINARY:
break;
default:
// We do nothing
}
// tslint:enable: no-unsafe-any
}
_inject(
spanContext: opentracing.SpanContext,
format: string,
carrier: unknown
): void {
const opentelemSpanContext: types.SpanContext = (spanContext as SpanContextShim).getSpanContext();
switch (format) {
// tslint:disable-next-line:no-switch-case-fall-through
case opentracing.FORMAT_HTTP_HEADERS:
case opentracing.FORMAT_TEXT_MAP:
this._tracer
.getHttpTextFormat()
.inject(opentelemSpanContext, format, carrier);
return;
case opentracing.FORMAT_BINARY:
this._logger.warn(
'OpentracingShim.inject() does not support FORMAT_BINARY'
);
// @todo: Implement binary format
return;
default:
}
}
metrics: this._metrics,
};
let textCodec = new TextMapCodec(codecOptions);
this.registerInjector(opentracing.FORMAT_TEXT_MAP, textCodec);
this.registerExtractor(opentracing.FORMAT_TEXT_MAP, textCodec);
codecOptions.urlEncoding = true;
let httpCodec = new TextMapCodec(codecOptions);
this.registerInjector(opentracing.FORMAT_HTTP_HEADERS, httpCodec);
this.registerExtractor(opentracing.FORMAT_HTTP_HEADERS, httpCodec);
let binaryCodec = new BinaryCodec();
this.registerInjector(opentracing.FORMAT_BINARY, binaryCodec);
this.registerExtractor(opentracing.FORMAT_BINARY, binaryCodec);
const uuid = uuidv4();
this._tags[constants.TRACER_CLIENT_ID_TAG_KEY] = uuid;
this._process = {
serviceName: serviceName,
tags: Utils.convertObjectToTags(this._tags),
uuid: uuid,
};
this._debugThrottler.setProcess(this._process);
// TODO update reporter to implement ProcessSetter
this._reporter.setProcess(this._process.serviceName, this._process.tags);
this._traceId128bit = options.traceId128bit;
this._shareRpcSpan = options.shareRpcSpan;
}
it('should support extract of binary format', () => {
BinaryPropagator.returns(propagator)
propagator.extract.withArgs(carrier).returns('spanContext')
tracer = new Tracer({ service: 'service' })
const spanContext = tracer.extract(opentracing.FORMAT_BINARY, carrier)
expect(spanContext).to.equal('spanContext')
})
})
it('should support inject of binary format', () => {
BinaryPropagator.returns(propagator)
tracer = new Tracer({ service: 'service' })
tracer.inject(spanContext, opentracing.FORMAT_BINARY, carrier)
expect(propagator.inject).to.have.been.calledWith(spanContext, carrier)
})
expect(function () {
tracer.extract(ot.FORMAT_BINARY, binCarrier)
}).not.toThrow(Error)
expect(function () {
expect(function () {
tracer.inject(spanContext, ot.FORMAT_BINARY, binCarrier)
}).not.toThrow(Error)
expect(function () {
constructor (config) {
super()
EventEmitter.call(this)
const service = config.service
const endpoint = config.endpoint
const hostname = config.hostname || 'localhost'
const port = config.port || 8126
const protocol = config.protocol || 'http'
this._service = service
this._endpoint = new Endpoint(endpoint || `${protocol}://${hostname}:${port}`)
this._propagators = {
[opentracing.FORMAT_TEXT_MAP]: new TextMapPropagator(),
[opentracing.FORMAT_HTTP_HEADERS]: new TextMapPropagator(),
[opentracing.FORMAT_BINARY]: new BinaryPropagator()
}
}