@opentelemetry/tracing
- Version 0.24.0
- Published
- 230 kB
- 4 dependencies
- Apache-2.0 license
Install
npm i @opentelemetry/tracing
yarn add @opentelemetry/tracing
pnpm add @opentelemetry/tracing
Overview
OpenTelemetry Tracing
Index
Classes
Interfaces
Enums
Type Aliases
Classes
class BasicTracerProvider
class BasicTracerProvider implements TracerProvider {}
This class represents a basic tracer provider which platform libraries can extend
constructor
constructor(config?: TracerConfig);
property activeSpanProcessor
activeSpanProcessor: SpanProcessor;
property resource
readonly resource: Resource;
method addSpanProcessor
addSpanProcessor: (spanProcessor: SpanProcessor) => void;
Adds a new SpanProcessor to this tracer.
Parameter spanProcessor
the new SpanProcessor to be added.
method forceFlush
forceFlush: () => Promise<void>;
method getActiveSpanProcessor
getActiveSpanProcessor: () => SpanProcessor;
method getTracer
getTracer: (name: string, version?: string) => Tracer;
method register
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.
Parameter config
Configuration object for SDK registration
method shutdown
shutdown: () => Promise<void>;
class BatchSpanProcessor
class BatchSpanProcessor extends BatchSpanProcessorBase<BufferConfig> {}
method onShutdown
protected onShutdown: () => void;
class ConsoleSpanExporter
class ConsoleSpanExporter implements SpanExporter {}
This is implementation of SpanExporter that prints spans to the console. This class can be used for diagnostic purposes.
class InMemorySpanExporter
class InMemorySpanExporter implements SpanExporter {}
This class can be used for testing purposes. It stores the exported spans in a list in memory that can be retrieved using the
getFinishedSpans()
method.
method export
export: ( spans: ReadableSpan[], resultCallback: (result: ExportResult) => void) => void;
method getFinishedSpans
getFinishedSpans: () => ReadableSpan[];
method reset
reset: () => void;
method shutdown
shutdown: () => Promise<void>;
class NoopSpanProcessor
class NoopSpanProcessor implements SpanProcessor {}
No-op implementation of SpanProcessor
method forceFlush
forceFlush: () => Promise<void>;
method onEnd
onEnd: (_span: ReadableSpan) => void;
method onStart
onStart: (_span: Span, _context: Context) => void;
method shutdown
shutdown: () => Promise<void>;
class SimpleSpanProcessor
class SimpleSpanProcessor implements SpanProcessor {}
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.
constructor
constructor(_exporter: SpanExporter);
method forceFlush
forceFlush: () => Promise<void>;
method onEnd
onEnd: (span: ReadableSpan) => void;
method onStart
onStart: (_span: Span) => void;
method shutdown
shutdown: () => Promise<void>;
class Span
class Span implements api.Span, ReadableSpan {}
This class represents a span.
constructor
constructor( parentTracer: Tracer, context: Context, spanName: string, spanContext: api.SpanContext, kind: api.SpanKind, parentSpanId?: string, links?: api.Link[], startTime?: api.TimeInput);
Constructs a new Span instance.
property attributes
readonly attributes: api.SpanAttributes;
property duration
readonly duration: api.HrTime;
property ended
readonly ended: boolean;
property endTime
endTime: api.HrTime;
property events
readonly events: TimedEvent[];
property instrumentationLibrary
readonly instrumentationLibrary: InstrumentationLibrary;
property kind
readonly kind: api.SpanKind;
property links
readonly links: api.Link[];
property name
name: string;
property parentSpanId
readonly parentSpanId?: string;
property resource
readonly resource: Resource;
property startTime
readonly startTime: api.HrTime;
property status
status: api.SpanStatus;
method addEvent
addEvent: ( name: string, attributesOrStartTime?: api.SpanAttributes | api.TimeInput, startTime?: api.TimeInput) => this;
Parameter name
Span Name
Parameter attributesOrStartTime
Span attributes or start time if type is and 3rd param is undefined
Parameter startTime
Specified start time for the event
method end
end: (endTime?: api.TimeInput) => void;
method isRecording
isRecording: () => boolean;
method recordException
recordException: (exception: api.Exception, time?: api.TimeInput) => void;
method setAttribute
setAttribute: (key: string, value?: SpanAttributeValue) => this;
method setAttributes
setAttributes: (attributes: api.SpanAttributes) => this;
method setStatus
setStatus: (status: api.SpanStatus) => this;
method spanContext
spanContext: () => api.SpanContext;
method updateName
updateName: (name: string) => this;
class Tracer
class Tracer implements api.Tracer {}
This class represents a basic tracer.
constructor
constructor( instrumentationLibrary: InstrumentationLibrary, config: TracerConfig, _tracerProvider: BasicTracerProvider);
Constructs a new Tracer instance.
property instrumentationLibrary
readonly instrumentationLibrary: InstrumentationLibrary;
property resource
readonly resource: Resource;
method getActiveSpanProcessor
getActiveSpanProcessor: () => import('./SpanProcessor').SpanProcessor;
method getSpanLimits
getSpanLimits: () => SpanLimits;
Returns the active SpanLimits.
method startActiveSpan
startActiveSpan: { <F extends (span: api.Span) => ReturnType<F>>( name: string, fn: F ): ReturnType<F>; <F extends (span: api.Span) => ReturnType<F>>( name: string, opts: api.SpanOptions, fn: F ): ReturnType<F>; <F extends (span: api.Span) => ReturnType<F>>( name: string, opts: api.SpanOptions, ctx: api.Context, fn: F ): ReturnType<F>;};
Starts a new Span and calls the given function passing it the created span as first argument. Additionally the new span gets set in context and this context is activated for the duration of the function call.
Parameter name
The name of the span
Parameter options
SpanOptions used for span creation
Parameter context
Context to use to extract parent
Parameter fn
function called in the context of the span and receives the newly created span as an argument
Returns
return value of fn
Example 1
const something = tracer.startActiveSpan('op', span => { try { do some work span.setStatus({code: SpanStatusCode.OK}); return something; } catch (err) { span.setStatus({ code: SpanStatusCode.ERROR, message: err.message, }); throw err; } finally { span.end(); } });
Example 2
const span = tracer.startActiveSpan('op', span => { try { do some work return span; } catch (err) { span.setStatus({ code: SpanStatusCode.ERROR, message: err.message, }); throw err; } }); do some more work span.end();
method startSpan
startSpan: ( name: string, options?: api.SpanOptions, context?: api.Context) => api.Span;
Starts a new Span or returns the default NoopSpan based on the sampling decision.
Interfaces
interface BatchSpanProcessorBrowserConfig
interface BatchSpanProcessorBrowserConfig extends BufferConfig {}
Interface configuration for BatchSpanProcessor on browser
property disableAutoFlushOnDocumentHide
disableAutoFlushOnDocumentHide?: boolean;
Disable flush when a user navigates to a new page, closes the tab or the browser, or, on mobile, switches to a different app. Auto flush is enabled by default.
interface BufferConfig
interface BufferConfig {}
Interface configuration for a buffer.
property exportTimeoutMillis
exportTimeoutMillis?: number;
How long the export can run before it is cancelled. The default value is 30000ms
property maxExportBatchSize
maxExportBatchSize?: number;
The maximum batch size of every export. It must be smaller or equal to maxQueueSize. The default value is 512.
property maxQueueSize
maxQueueSize?: number;
The maximum queue size. After the size is reached spans are dropped. The default value is 2048.
property scheduledDelayMillis
scheduledDelayMillis?: number;
The delay interval in milliseconds between two consecutive exports. The default value is 5000ms.
interface ReadableSpan
interface ReadableSpan {}
property attributes
readonly attributes: SpanAttributes;
property duration
readonly duration: HrTime;
property ended
readonly ended: boolean;
property endTime
readonly endTime: HrTime;
property events
readonly events: TimedEvent[];
property instrumentationLibrary
readonly instrumentationLibrary: InstrumentationLibrary;
property kind
readonly kind: SpanKind;
property links
readonly links: Link[];
property name
readonly name: string;
property parentSpanId
readonly parentSpanId?: string;
property resource
readonly resource: Resource;
property spanContext
readonly spanContext: () => SpanContext;
property startTime
readonly startTime: HrTime;
property status
readonly status: SpanStatus;
interface SDKRegistrationConfig
interface SDKRegistrationConfig {}
Configuration options for registering the API with the SDK. Undefined values may be substituted for defaults, and null values will not be registered.
property contextManager
contextManager?: ContextManager | null;
Context manager to register as the global context manager
property propagator
propagator?: TextMapPropagator | null;
Propagator to register as the global propagator
interface SpanExporter
interface SpanExporter {}
An interface that allows different tracing services to export recorded data for sampled spans in their own format.
To export data this MUST be register to the Tracer SDK using a optional config.
method export
export: ( spans: ReadableSpan[], resultCallback: (result: ExportResult) => void) => void;
Called to export sampled ReadableSpans.
Parameter spans
the list of sampled Spans to be exported.
method shutdown
shutdown: () => Promise<void>;
Stops the exporter.
interface SpanLimits
interface SpanLimits {}
Global configuration of trace service
property attributeCountLimit
attributeCountLimit?: number;
attributeCountLimit is number of attributes per span
property eventCountLimit
eventCountLimit?: number;
eventCountLimit is number of message events per span
property linkCountLimit
linkCountLimit?: number;
linkCountLimit is number of links per span
interface SpanProcessor
interface SpanProcessor {}
method forceFlush
forceFlush: () => Promise<void>;
Forces to export all finished spans
method onEnd
onEnd: (span: ReadableSpan) => void;
Called when a ReadableSpan is ended, if the
span.isRecording()
returns true.Parameter span
the Span that just ended.
method onStart
onStart: (span: Span, parentContext: Context) => void;
Called when a Span is started, if the
span.isRecording()
returns true.Parameter span
the Span that just started.
method shutdown
shutdown: () => Promise<void>;
Shuts down the processor. Called when SDK is shut down. This is an opportunity for processor to do any cleanup required.
interface TimedEvent
interface TimedEvent {}
Represents a timed event. A timed event is an event with a timestamp.
property attributes
attributes?: SpanAttributes;
The attributes of the event.
property name
name: string;
The name of the event.
property time
time: HrTime;
interface TracerConfig
interface TracerConfig {}
TracerConfig provides an interface for configuring a Basic Tracer.
property forceFlushTimeoutMillis
forceFlushTimeoutMillis?: number;
How long the forceFlush can run before it is cancelled. The default value is 30000ms
property idGenerator
idGenerator?: IdGenerator;
Generator of trace and span IDs The default idGenerator generates random ids
property resource
resource?: Resource;
Resource associated with trace telemetry
property sampler
sampler?: Sampler;
Sampler determines if a span should be recorded or should be a NoopSpan.
property spanLimits
spanLimits?: SpanLimits;
Span Limits
Enums
enum ForceFlushState
enum ForceFlushState { 'resolved' = 0, 'timeout' = 1, 'error' = 2, 'unresolved' = 3,}
member 'error'
'error' = 2
member 'resolved'
'resolved' = 0
member 'timeout'
'timeout' = 1
member 'unresolved'
'unresolved' = 3
Type Aliases
type EXPORTER_FACTORY
type EXPORTER_FACTORY = () => SpanExporter;
type PROPAGATOR_FACTORY
type PROPAGATOR_FACTORY = () => TextMapPropagator;
Package Files (14)
- build/src/BasicTracerProvider.d.ts
- build/src/Span.d.ts
- build/src/SpanProcessor.d.ts
- build/src/TimedEvent.d.ts
- build/src/Tracer.d.ts
- build/src/export/ConsoleSpanExporter.d.ts
- build/src/export/InMemorySpanExporter.d.ts
- build/src/export/NoopSpanProcessor.d.ts
- build/src/export/ReadableSpan.d.ts
- build/src/export/SimpleSpanProcessor.d.ts
- build/src/export/SpanExporter.d.ts
- build/src/index.d.ts
- build/src/platform/node/export/BatchSpanProcessor.d.ts
- build/src/types.d.ts
Dependencies (4)
Dev Dependencies (22)
Peer Dependencies (1)
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@opentelemetry/tracing
.
- Markdown[](https://www.jsdocs.io/package/@opentelemetry/tracing)
- HTML<a href="https://www.jsdocs.io/package/@opentelemetry/tracing"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 5976 ms. - Missing or incorrect documentation? Open an issue for this package.