@@ -7,46 +7,49 @@ import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
7
7
import { registerInstrumentations } from '@opentelemetry/instrumentation' ;
8
8
import { getWebAutoInstrumentations } from '@opentelemetry/auto-instrumentations-web' ;
9
9
import { Resource , browserDetector } from '@opentelemetry/resources' ;
10
- import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions' ;
10
+ import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions' ;
11
11
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http' ;
12
12
import { SessionIdProcessor } from './SessionIdProcessor' ;
13
13
import { detectResourcesSync } from '@opentelemetry/resources/build/src/detect-resources' ;
14
- import { ZoneContextManager } from '@opentelemetry/context-zone' ;
15
14
16
15
const {
17
16
NEXT_PUBLIC_OTEL_SERVICE_NAME = '' ,
18
17
NEXT_PUBLIC_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '' ,
19
18
IS_SYNTHETIC_REQUEST = '' ,
20
19
} = typeof window !== 'undefined' ? window . ENV : { } ;
21
20
22
- const FrontendTracer = ( ) => {
21
+ const FrontendTracer = async ( ) => {
22
+ const { ZoneContextManager } = await import ( '@opentelemetry/context-zone' ) ;
23
+
23
24
let resource = new Resource ( {
24
- [ SemanticResourceAttributes . SERVICE_NAME ] : NEXT_PUBLIC_OTEL_SERVICE_NAME ,
25
+ [ SEMRESATTRS_SERVICE_NAME ] : NEXT_PUBLIC_OTEL_SERVICE_NAME ,
25
26
} ) ;
26
-
27
27
const detectedResources = detectResourcesSync ( { detectors : [ browserDetector ] } ) ;
28
28
resource = resource . merge ( detectedResources ) ;
29
- const provider = new WebTracerProvider ( { resource } ) ;
30
-
31
- provider . addSpanProcessor ( new SessionIdProcessor ( ) ) ;
32
29
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
+ } ) ;
43
44
44
45
const contextManager = new ZoneContextManager ( ) ;
45
46
46
47
provider . register ( {
47
48
contextManager,
48
49
propagator : new CompositePropagator ( {
49
- propagators : [ new W3CBaggagePropagator ( ) , new W3CTraceContextPropagator ( ) ] ,
50
+ propagators : [
51
+ new W3CBaggagePropagator ( ) ,
52
+ new W3CTraceContextPropagator ( ) ] ,
50
53
} ) ,
51
54
} ) ;
52
55
0 commit comments