Module @opentelemetry/sdk-trace-web

OpenTelemetry Web SDK

NPM Published Version Apache License

This module provides automated instrumentation and tracing for Web applications.

For manual instrumentation see the @opentelemetry/sdk-trace-base package.

This package exposes a class WebTracerProvider that will be able to automatically trace things in Browser only.

See the example how to use it.

OpenTelemetry comes with a growing number of instrumentations for well know modules (see supported modules) and an API to create custom instrumentations (see the instrumentation developer guide).

Web Tracer currently supports one plugin for document load. Unlike Node Tracer (NodeTracerProvider), the plugins needs to be initialized and passed in configuration. The reason is to give user full control over which plugin will be bundled into web page.

You can choose to use the ZoneContextManager if you want to trace asynchronous operations. Please note that the ZoneContextManager does not work with JS code targeting ES2017+. In order to use the ZoneContextManager, please transpile back to ES2015.

npm install --save @opentelemetry/sdk-trace-web
import {
ConsoleSpanExporter,
SimpleSpanProcessor,
WebTracerProvider,
} from '@opentelemetry/sdk-trace-web';
import { DocumentLoad } from '@opentelemetry/plugin-document-load';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { registerInstrumentations } from '@opentelemetry/instrumentation';

const provider = new WebTracerProvider({
spanProcessors: [new SimpleSpanProcessor(new ConsoleSpanExporter())]
});

provider.register({
// Changing default contextManager to use ZoneContextManager - supports asynchronous operations - optional
contextManager: new ZoneContextManager(),
});

// Registering instrumentations / plugins
registerInstrumentations({
instrumentations: [
new DocumentLoad(),
],
});

Apache 2.0 - See LICENSE for more information.

Enumerations

PerformanceTimingNames
SamplingDecision

Classes

AlwaysOffSampler
AlwaysOnSampler
BasicTracerProvider
BatchSpanProcessor
ConsoleSpanExporter
InMemorySpanExporter
NoopSpanProcessor
ParentBasedSampler
RandomIdGenerator
SimpleSpanProcessor
StackContextManager
TraceIdRatioBasedSampler
WebTracerProvider

Interfaces

BatchSpanProcessorBrowserConfig
BufferConfig
GeneralLimits
IdGenerator
PerformanceLegacy
PerformanceResourceTimingInfo
ReadableSpan
Sampler
SamplingResult
SDKRegistrationConfig
SpanExporter
SpanLimits
SpanProcessor
TimedEvent
TracerConfig
URLLike

Type Aliases

PerformanceEntries
PropagateTraceHeaderCorsUrls
Span
WebTracerConfig

Functions

addSpanNetworkEvent
addSpanNetworkEvents
getElementXPath
getResource
hasKey
normalizeUrl
parseUrl
sortResources