Skip to content

Commit 1c6ba70

Browse files
authored
[frontend] update browser tracer provider config (#2092)
* updated deprecated calls * remove deprecated calls
1 parent f249237 commit 1c6ba70

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ the release.
1313
([#2072](https://github.com/open-telemetry/opentelemetry-demo/pull/2072))
1414
* [grafana] Update dashboards with service map
1515
([#2085](https://github.com/open-telemetry/opentelemetry-demo/pull/2085))
16+
* [frontend] Update OpenTelemetry Browser SDK initialization
17+
([#2092](https://github.com/open-telemetry/opentelemetry-demo/pull/2092))
1618

1719
## 2.0.0
1820

src/frontend/utils/telemetry/FrontendTracer.ts

+22-19
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,49 @@ import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
77
import { registerInstrumentations } from '@opentelemetry/instrumentation';
88
import { getWebAutoInstrumentations } from '@opentelemetry/auto-instrumentations-web';
99
import { Resource, browserDetector } from '@opentelemetry/resources';
10-
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
10+
import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
1111
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
1212
import { SessionIdProcessor } from './SessionIdProcessor';
1313
import { detectResourcesSync } from '@opentelemetry/resources/build/src/detect-resources';
14-
import { ZoneContextManager } from '@opentelemetry/context-zone';
1514

1615
const {
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

Comments
 (0)