diff --git a/libs/index.mjs b/libs/index.mjs index 7e5616b..e4c25a5 100644 --- a/libs/index.mjs +++ b/libs/index.mjs @@ -68,7 +68,12 @@ export function setupTracing(options = {}) { concurrencyLimit = 10, } = options; + // Register the span processor with the tracer provider + const exporter = new OTLPTraceExporter(exportOptions); + const spanProcessor = new BatchSpanProcessor(exporter); + tracerProvider = new NodeTracerProvider({ + spanProcessors: [spanProcessor], resource: new Resource({ [SemanticResourceAttributes.CONTAINER_NAME]: containerName || serviceName, [SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: deploymentEnvironment, @@ -84,13 +89,13 @@ export function setupTracing(options = {}) { // Initialize the tracer provider with propagators tracerProvider.register({ propagator: new CompositePropagator({ - propagators: [ - new W3CBaggagePropagator(), - new W3CTraceContextPropagator(), - new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER }), - ], -}), -}); + propagators: [ + new W3CBaggagePropagator(), + new W3CTraceContextPropagator(), + new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER }), + ], + }), + }); // Configure exporter with the Collector endpoint - uses gRPC const exportOptions = { @@ -99,11 +104,6 @@ export function setupTracing(options = {}) { timeoutMillis: 1000, }; - // Register the span processor with the tracer provider - const exporter = new OTLPTraceExporter(exportOptions); - const spanProcessor = new BatchSpanProcessor(exporter); - tracerProvider.activeSpanProcessor(spanProcessor); - // Ignore spans from static assets. const ignoreIncomingRequestHook = (req) => { const isStaticAsset = !!req.url.match(/^\/metrics|\/healthz.*$/); @@ -121,8 +121,8 @@ export function setupTracing(options = {}) { new AwsInstrumentation({ sqsExtractContextPropagationFromPayload: true, }), new DnsInstrumentation(), new RedisInstrumentation(), - ], -}); + ], + }); // Return the tracer for the service return tracerProvider.getTracer(serviceName); diff --git a/package.json b/package.json index 6a56c56..618b64d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@saidsef/tracing-node", - "version": "3.2.1", + "version": "3.2.2", "description": "tracing NodeJS - This is a wrapper for OpenTelemetry instrumentation packages", "main": "libs/index.mjs", "scripts": {