Inject tracer as a dependency
@@ -87,7 +87,6 @@ const discovery = require("clever-discovery");
const kayvee = require("kayvee");
const request = require("request");
const opentracing = require("opentracing");
-const globalTracing = require("opentracing/lib/global_tracer");
const {commandFactory} = require("hystrixjs");
const RollingNumberEvent = require("hystrixjs/lib/metrics/RollingNumberEvent");
@@ -263,6 +262,11 @@ class {{.ClassName}} {
} else {
this.logger = new kayvee.logger("{{.ServiceName}}-wagclient");
}
+ if (options.tracer) {
+ this.tracer = options.tracer;
+ } else {
+ this.tracer = opentracing.globalTracer();
+ }
const circuitOptions = Object.assign({}, defaultCircuitOptions, options.circuit);
this._hystrixCommand = commandFactory.getOrCreate("{{.ServiceName}}").
@@ -383,6 +387,7 @@ var methodTmplStr = `
}
const timeout = options.timeout || this.timeout;
+ const tracer = options.tracer || this.tracer;
const span = options.span;
const headers = {};
@@ -408,7 +413,7 @@ var methodTmplStr = `
if (span) {
// Need to get tracer to inject. Use HTTP headers format so we can properly escape special characters
- globalTracing.globalTracer().inject(span, opentracing.FORMAT_HTTP_HEADERS, headers);
+ tracer.inject(span, opentracing.FORMAT_HTTP_HEADERS, headers);
{{- if not .IterMethod}}
span.logEvent("{{.Method}} {{.Path}}");
{{- end}}
