@@ -7,46 +7,49 @@ import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
77import { registerInstrumentations } from '@opentelemetry/instrumentation' ;
88import { getWebAutoInstrumentations } from '@opentelemetry/auto-instrumentations-web' ;
99import { Resource , browserDetector } from '@opentelemetry/resources' ;
10- import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions' ;
10+ import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions' ;
1111import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http' ;
1212import { SessionIdProcessor } from './SessionIdProcessor' ;
1313import { detectResourcesSync } from '@opentelemetry/resources/build/src/detect-resources' ;
14- import { ZoneContextManager } from '@opentelemetry/context-zone' ;
1514
1615const {
1716 NEXT_PUBLIC_OTEL_SERVICE_NAME = '' ,
1817 NEXT_PUBLIC_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '' ,
1918 IS_SYNTHETIC_REQUEST = '' ,
2019} = typeof window !== 'undefined' ? window . ENV : { } ;
2120
22- const FrontendTracer = ( ) => {
21+ const FrontendTracer = async ( ) => {
22+ const { ZoneContextManager } = await import ( '@opentelemetry/context-zone' ) ;
23+
2324 let resource = new Resource ( {
24- [ SemanticResourceAttributes . SERVICE_NAME ] : NEXT_PUBLIC_OTEL_SERVICE_NAME ,
25+ [ SEMRESATTRS_SERVICE_NAME ] : NEXT_PUBLIC_OTEL_SERVICE_NAME ,
2526 } ) ;
26-
2727 const detectedResources = detectResourcesSync ( { detectors : [ browserDetector ] } ) ;
2828 resource = resource . merge ( detectedResources ) ;
29- const provider = new WebTracerProvider ( { resource } ) ;
30-
31- provider . addSpanProcessor ( new SessionIdProcessor ( ) ) ;
3229
33- provider . addSpanProcessor (
34- new BatchSpanProcessor (
35- new OTLPTraceExporter ( {
36- url : NEXT_PUBLIC_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT || 'http://localhost:4318/v1/traces' ,
37- } ) ,
38- {
39- scheduledDelayMillis : 500 ,
40- }
41- )
42- ) ;
30+ const provider = new WebTracerProvider ( {
31+ resource,
32+ spanProcessors : [
33+ new SessionIdProcessor ( ) ,
34+ new BatchSpanProcessor (
35+ new OTLPTraceExporter ( {
36+ url : NEXT_PUBLIC_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT || 'http://localhost:4318/v1/traces' ,
37+ } ) ,
38+ {
39+ scheduledDelayMillis : 500 ,
40+ }
41+ ) ,
42+ ] ,
43+ } ) ;
4344
4445 const contextManager = new ZoneContextManager ( ) ;
4546
4647 provider . register ( {
4748 contextManager,
4849 propagator : new CompositePropagator ( {
49- propagators : [ new W3CBaggagePropagator ( ) , new W3CTraceContextPropagator ( ) ] ,
50+ propagators : [
51+ new W3CBaggagePropagator ( ) ,
52+ new W3CTraceContextPropagator ( ) ] ,
5053 } ) ,
5154 } ) ;
5255
0 commit comments