Skip to content

Commit

Permalink
[Frontend] Use browserDetector to populate browser information into f…
Browse files Browse the repository at this point in the history
…rontend tel… (open-telemetry#760)
  • Loading branch information
mervinyan authored and juliangiuca committed Apr 12, 2023
1 parent d6defb4 commit d4e59f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ tls_certificate_check and bump to OTP-25
([#756](https://github.com/open-telemetry/opentelemetry-demo/pull/756))
* Bump up OTEL Java Agent version to 1.23.0
([#757](https://github.com/open-telemetry/opentelemetry-demo/pull/757))
* Use browserDetector to populate browser info to frontend-web telemetry
([#760](https://github.com/open-telemetry/opentelemetry-demo/pull/760))

## v0.1.0

Expand Down
12 changes: 8 additions & 4 deletions src/frontend/utils/telemetry/FrontendTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { getWebAutoInstrumentations } from '@opentelemetry/auto-instrumentations-web';
import { Resource } from '@opentelemetry/resources';
import { Resource, detectResources, browserDetector } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';

Expand All @@ -13,10 +13,14 @@ const { NEXT_PUBLIC_OTEL_SERVICE_NAME = '', NEXT_PUBLIC_OTEL_EXPORTER_OTLP_TRACE
const FrontendTracer = async (collectorString: string) => {
const { ZoneContextManager } = await import('@opentelemetry/context-zone');

let resource = new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: NEXT_PUBLIC_OTEL_SERVICE_NAME,
});

const detectedResources = await detectResources({detectors:[browserDetector]});
resource = resource.merge(detectedResources);
const provider = new WebTracerProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: NEXT_PUBLIC_OTEL_SERVICE_NAME,
}),
resource
});

provider.addSpanProcessor(
Expand Down

0 comments on commit d4e59f2

Please sign in to comment.