overleaf/services/web/frontend/js/tracing.js
Mathias Jakobsen 50b346b4ed Merge pull request #10279 from overleaf/jpa-tracing-optimizations
[misc] do not load the tracing module unless enabled

GitOrigin-RevId: 8a3b9da3e9451e3060b852dd44e078c99cf43cfa
2022-11-04 09:05:00 +00:00

37 lines
1.3 KiB
JavaScript

import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'
import { Resource } from '@opentelemetry/resources'
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http/build/esnext'
import { WebTracerProvider } from '@opentelemetry/sdk-trace-web'
import { ZoneContextManager } from '@opentelemetry/context-zone'
import { registerInstrumentations } from '@opentelemetry/instrumentation'
import { getWebAutoInstrumentations } from '@opentelemetry/auto-instrumentations-web'
import getMeta from './utils/meta'
if (getMeta('ol-useOpenTelemetry')) {
const resource = new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'frontend',
[SemanticResourceAttributes.SERVICE_NAMESPACE]: 'Overleaf',
})
const provider = new WebTracerProvider({ resource })
provider.addSpanProcessor(
new SimpleSpanProcessor(
new OTLPTraceExporter({
url: `https://${window.location.hostname}/otlp/v1/traces`,
})
)
)
provider.register({
// Changing default contextManager to use ZoneContextManager - supports asynchronous operations - optional
contextManager: new ZoneContextManager(),
})
// Registering instrumentations
registerInstrumentations({
instrumentations: [getWebAutoInstrumentations()],
})
}