@@ -89,6 +89,7 @@ The instrumentation file is required to setup the `OTLPTraceExporter` and `WebTr
8989 import { XMLHttpRequestInstrumentation } from ' @opentelemetry/instrumentation-xml-http-request' ;
9090 import { registerInstrumentations } from ' @opentelemetry/instrumentation' ;
9191 import { resourceFromAttributes } from ' @opentelemetry/resources' ;
92+ import { ZoneContextManager } from ' @opentelemetry/context-zone' ;
9293
9394 const exporter = new OTLPTraceExporter ({
9495 // For self-hosted version, please use the collector url instead.
@@ -106,7 +107,9 @@ The instrumentation file is required to setup the `OTLPTraceExporter` and `WebTr
106107 spanProcessors: [new BatchSpanProcessor (exporter )],
107108 });
108109
109- provider .register ();
110+ provider .register ({
111+ contextManager: new ZoneContextManager (),
112+ });
110113
111114 registerInstrumentations ({
112115 instrumentations: [
@@ -141,6 +144,7 @@ The instrumentation file is required to setup the `OTLPTraceExporter` and `WebTr
141144 import { XMLHttpRequestInstrumentation } from ' @opentelemetry/instrumentation-xml-http-request' ;
142145 import { registerInstrumentations } from ' @opentelemetry/instrumentation' ;
143146 import { resourceFromAttributes } from ' @opentelemetry/resources' ;
147+ import { ZoneContextManager } from ' @opentelemetry/context-zone' ;
144148
145149 const exporter = new OTLPTraceExporter ({
146150 // For self-hosted version, please use the collector url instead.
@@ -158,7 +162,9 @@ The instrumentation file is required to setup the `OTLPTraceExporter` and `WebTr
158162 spanProcessors: [new BatchSpanProcessor (exporter)],
159163 });
160164
161- provider .register ();
165+ provider .register ({
166+ contextManager: new ZoneContextManager (),
167+ });
162168
163169 registerInstrumentations ({
164170 instrumentations: [
@@ -430,41 +436,6 @@ Going through each of the 3 instrumentations set up:
430436To link your frontend and backend traces, you need to instrument your backend to send traces. Check out this [ document] ( https://signoz.io/docs/instrumentation/overview/ ) to instrument your backend.
431437Once done, your frontend traces should automatically get linked with your backend traces.
432438
433- For the purpose of this guide, we have setup a simple Node.js API with instrumentation.
434-
435- ``` ts:backend.ts
436- import { NodeSDK } from ' @opentelemetry/sdk-node'
437- import { OTLPTraceExporter } from ' @opentelemetry/exporter-trace-otlp-http'
438- import { resourceFromAttributes } from ' @opentelemetry/resources'
439- import { getNodeAutoInstrumentations } from ' @opentelemetry/auto-instrumentations-node'
440-
441- const sdk = new NodeSDK ({
442- resource: resourceFromAttributes ({
443- ' service.name' : ' <SERVICE_NAME>' ,
444- }),
445- traceExporter: new OTLPTraceExporter ({
446- url: ` https://ingest.<INGESTION_REGION>.signoz.cloud:443/v1/traces ` ,
447- headers: {
448- // Optional for the self-hosted version
449- ' signoz-ingestion-key' : ' <INGESTION_KEY>' ,
450- },
451- }),
452- instrumentations: [getNodeAutoInstrumentations ()],
453- })
454-
455- sdk .start ()
456- ```
457-
458- ``` ts:backend.ts
459- app .post (' <api-endpoint>' , (req , res ) => {
460- try {
461- // Your api logic
462- } catch (error ) {
463- // Your error handling logic
464- }
465- })
466- ```
467-
468439### Step 5: Viewing Captured Traces in SigNoz
469440
470441The captured traces can then be viewed in the [ Traces Explorer] ( https://signoz.io/docs/product-features/trace-explorer/ ) .
0 commit comments