Skip to content

OpenTelemetry

LiveStore has built-in support for OpenTelemetry.

import {
class ZoneContextManager

ZoneContextManager This module provides an easy functionality for tracing action between asynchronous operations in web. It was not possible with standard [StackContextManager]

https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-sdk-trace-web/src/StackContextManager.ts

. It heavily depends on [zone.js]

https://www.npmjs.com/package/zone.js

. It stores the information about context in zone. Each Context will have always new Zone; It also supports binding a certain Span to a target that has "addEventListener" and "removeEventListener". When this happens a new zone is being created and the provided Span is being assigned to this zone.

ZoneContextManager
} from '@opentelemetry/context-zone'
import {
class W3CTraceContextPropagator

Propagates

SpanContext

through Trace Context format propagation.

Based on the Trace Context specification: https://www.w3.org/TR/trace-context/

W3CTraceContextPropagator
} from '@opentelemetry/core'
import {
class OTLPTraceExporter

Collector Trace Exporter for Node

OTLPTraceExporter
} from '@opentelemetry/exporter-trace-otlp-http'
import {
function resourceFromAttributes(attributes: DetectedResourceAttributes, options?: ResourceOptions): Resource
resourceFromAttributes
} from '@opentelemetry/resources'
import {
class SimpleSpanProcessor

An implementation of the

SpanProcessor

that converts the

Span

to

ReadableSpan

and passes it to the configured exporter.

Only spans that are sampled are converted.

NOTE: This

SpanProcessor

exports every ended span individually instead of batching spans together, which causes significant performance overhead with most exporters. For production use, please consider using the

BatchSpanProcessor

instead.

SimpleSpanProcessor
} from '@opentelemetry/sdk-trace-base'
import {
class WebTracerProvider

This class represents a web tracer with

StackContextManager

WebTracerProvider
} from '@opentelemetry/sdk-trace-web'
/**
* Configure a browser tracer that preserves parent/child spans across async work.
* Requires a zone.js runtime (e.g. provided by many frameworks) so the ZoneContextManager
* can keep context during timers, promises, and event callbacks.
*/
export const
const makeTracer: (serviceName: string) => Tracer

Configure a browser tracer that preserves parent/child spans across async work. Requires a zone.js runtime (e.g. provided by many frameworks) so the ZoneContextManager can keep context during timers, promises, and event callbacks.

makeTracer
= (
serviceName: string
serviceName
: string) => {
const
const url: any
url
= import.

The type of import.meta.

If you need to declare that a given property exists on import.meta, this type may be augmented via interface merging.

meta
.
ImportMeta.env: ImportMetaEnv
env
.
any
VITE_OTEL_EXPORTER_OTLP_ENDPOINT
const
const provider: WebTracerProvider
provider
= new
new WebTracerProvider(config?: WebTracerConfig): WebTracerProvider

Constructs a new Tracer instance.

@paramconfig Web Tracer config

WebTracerProvider
({
TracerConfig.spanProcessors?: SpanProcessor[]

List of SpanProcessor for the tracer

spanProcessors
:
const url: any
url
!==
var undefined
undefined
? [new
new SimpleSpanProcessor(_exporter: SpanExporter): SimpleSpanProcessor

An implementation of the

SpanProcessor

that converts the

Span

to

ReadableSpan

and passes it to the configured exporter.

Only spans that are sampled are converted.

NOTE: This

SpanProcessor

exports every ended span individually instead of batching spans together, which causes significant performance overhead with most exporters. For production use, please consider using the

BatchSpanProcessor

instead.

SimpleSpanProcessor
(new
new OTLPTraceExporter(config?: OTLPExporterNodeConfigBase): OTLPTraceExporter

Collector Trace Exporter for Node

OTLPTraceExporter
({
OTLPExporterConfigBase.url?: string
url
: `${
const url: any
url
}/v1/traces` }))] : [],
TracerConfig.resource?: Resource

Resource associated with trace telemetry

resource
:
function resourceFromAttributes(attributes: DetectedResourceAttributes, options?: ResourceOptions): Resource
resourceFromAttributes
({ 'service.name':
serviceName: string
serviceName
}),
})
const provider: WebTracerProvider
provider
.
WebTracerProvider.register(config?: SDKRegistrationConfig): void

Register this TracerProvider for use with the OpenTelemetry API. Undefined values may be replaced with defaults, and null values will be skipped.

@paramconfig Configuration object for SDK registration

register
({
SDKRegistrationConfig.contextManager?: ContextManager | null

Context manager to register as the global context manager

contextManager
: new
new ZoneContextManager(): ZoneContextManager

ZoneContextManager This module provides an easy functionality for tracing action between asynchronous operations in web. It was not possible with standard [StackContextManager]

https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-sdk-trace-web/src/StackContextManager.ts

. It heavily depends on [zone.js]

https://www.npmjs.com/package/zone.js

. It stores the information about context in zone. Each Context will have always new Zone; It also supports binding a certain Span to a target that has "addEventListener" and "removeEventListener". When this happens a new zone is being created and the provided Span is being assigned to this zone.

ZoneContextManager
(),
SDKRegistrationConfig.propagator?: TextMapPropagator<any> | null

Propagator to register as the global propagator

propagator
: new
new W3CTraceContextPropagator(): W3CTraceContextPropagator

Propagates

SpanContext

through Trace Context format propagation.

Based on the Trace Context specification: https://www.w3.org/TR/trace-context/

W3CTraceContextPropagator
(),
})
return
const provider: WebTracerProvider
provider
.
BasicTracerProvider.getTracer(name: string, version?: string, options?: {
schemaUrl?: string;
}): Tracer

Returns a Tracer, creating one if one with the given name and version is not already created.

This function may return different Tracer types (e.g.

NoopTracerProvider

vs. a functional tracer).

@paramname The name of the tracer or instrumentation library.

@paramversion The version of the tracer or instrumentation library.

@paramoptions The options of the tracer or instrumentation library.

@returnsTracer A Tracer with the given name and version

getTracer
('livestore')
}
export const
const tracer: Tracer
tracer
=
const makeTracer: (serviceName: string) => Tracer

Configure a browser tracer that preserves parent/child spans across async work. Requires a zone.js runtime (e.g. provided by many frameworks) so the ZoneContextManager can keep context during timers, promises, and event callbacks.

makeTracer
('my-app')