File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,20 @@ void (async () => {
5656 const { setGlobalTracerProvider } = api ?? await import ( 'https://unpkg.com/@opentelemetry/api@1.8.0/build/esm/index.js' ) ;
5757 setGlobalTracerProvider ( provider ) ;
5858 } catch { }
59+ // Auto-instrument browser fetch to propagate trace context to the API and capture client spans
60+ try {
61+ const { registerInstrumentations } = await import ( 'https://unpkg.com/@opentelemetry/instrumentation@0.50.0/build/esm/index.js' ) ;
62+ const { FetchInstrumentation } = await import ( 'https://unpkg.com/@opentelemetry/instrumentation-fetch@0.50.0/build/esm/index.js' ) ;
63+ registerInstrumentations ( {
64+ instrumentations : [
65+ new FetchInstrumentation ( {
66+ propagateTraceHeaderCorsUrls : [ / .* / ]
67+ } )
68+ ]
69+ } ) ;
70+ } catch { }
71+ // Refresh tracer reference now that a real provider is registered
72+ try { tracer = trace . getTracer ( 'Abies.JS' ) ; } catch { }
5973 } ) ( ) ;
6074
6175 // Cap OTel init time so poor connectivity doesn't delay the app
@@ -64,7 +78,7 @@ void (async () => {
6478 } catch { }
6579} ) ( ) ;
6680
67- const tracer = trace . getTracer ( 'Abies.JS' ) ;
81+ let tracer = trace . getTracer ( 'Abies.JS' ) ;
6882
6983function withSpan ( name , fn ) {
7084 return async ( ...args ) => {
You can’t perform that action at this time.
0 commit comments