Skip to content

Commit 25a90f5

Browse files
Maurice PetersMaurice Peters
authored andcommitted
Frontend tracing: update tracer after provider init and add FetchInstrumentation for context propagation + client spans
1 parent cb29b9c commit 25a90f5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Abies/wwwroot/abies.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff 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

6983
function withSpan(name, fn) {
7084
return async (...args) => {

0 commit comments

Comments
 (0)