@opentelemetry/core
- Version 1.26.0
- Published
- 908 kB
- 1 dependency
- Apache-2.0 license
Install
npm i @opentelemetry/core
yarn add @opentelemetry/core
pnpm add @opentelemetry/core
Overview
OpenTelemetry Core provides constants and utilities shared by all OpenTelemetry SDK packages.
Index
Variables
Functions
- addHrTimes()
- callWithTimeout()
- deleteRPCMetadata()
- getEnv()
- getEnvWithoutDefaults()
- getRPCMetadata()
- getTimeOrigin()
- globalErrorHandler()
- hexToBase64()
- hexToBinary()
- hrTime()
- hrTimeDuration()
- hrTimeToMicroseconds()
- hrTimeToMilliseconds()
- hrTimeToNanoseconds()
- hrTimeToTimeStamp()
- isAttributeKey()
- isAttributeValue()
- isTimeInput()
- isTimeInputHrTime()
- isTracingSuppressed()
- isUrlIgnored()
- isWrapped()
- loggingErrorHandler()
- merge()
- millisToHrTime()
- parseEnvironment()
- parseTraceParent()
- sanitizeAttributes()
- setGlobalErrorHandler()
- setRPCMetadata()
- suppressTracing()
- timeInputToHrTime()
- unrefTimer()
- unsuppressTracing()
- urlMatches()
Classes
Interfaces
Enums
Type Aliases
Variables
variable baggageUtils
const baggageUtils: { getKeyPairs: typeof getKeyPairs; serializeKeyPairs: typeof serializeKeyPairs; parseKeyPairsIntoRecord: typeof parseKeyPairsIntoRecord; parsePairKeyValue: typeof parsePairKeyValue;};
variable DEFAULT_ATTRIBUTE_COUNT_LIMIT
const DEFAULT_ATTRIBUTE_COUNT_LIMIT: number;
variable DEFAULT_ATTRIBUTE_VALUE_LENGTH_LIMIT
const DEFAULT_ATTRIBUTE_VALUE_LENGTH_LIMIT: number;
variable DEFAULT_ENVIRONMENT
const DEFAULT_ENVIRONMENT: Required<ENVIRONMENT>;
Default environment variables
variable DEFAULT_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT
const DEFAULT_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT: number;
variable DEFAULT_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT
const DEFAULT_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT: number;
variable internal
const internal: { _export: typeof _export };
variable otperformance
const otperformance: any;
variable SDK_INFO
const SDK_INFO: { 'telemetry.sdk.name': string; 'process.runtime.name': string; 'telemetry.sdk.language': string; 'telemetry.sdk.version': string;};
Constants describing the SDK in use
variable TRACE_PARENT_HEADER
const TRACE_PARENT_HEADER: string;
variable TRACE_STATE_HEADER
const TRACE_STATE_HEADER: string;
variable VERSION
const VERSION: string;
Functions
function addHrTimes
addHrTimes: (time1: api.HrTime, time2: api.HrTime) => api.HrTime;
Given 2 HrTime formatted times, return their sum as an HrTime.
function callWithTimeout
callWithTimeout: <T>(promise: Promise<T>, timeout: number) => Promise<T>;
Adds a timeout to a promise and rejects if the specified timeout has elapsed. Also rejects if the specified promise rejects, and resolves if the specified promise resolves.
NOTE: this operation will continue even after it throws a TimeoutError.
Parameter promise
promise to use with timeout.
Parameter timeout
the timeout in milliseconds until the returned promise is rejected.
function deleteRPCMetadata
deleteRPCMetadata: (context: Context) => Context;
function getEnv
getEnv: () => Required<ENVIRONMENT>;
Gets the environment variables
function getEnvWithoutDefaults
getEnvWithoutDefaults: () => ENVIRONMENT;
function getRPCMetadata
getRPCMetadata: (context: Context) => RPCMetadata | undefined;
function getTimeOrigin
getTimeOrigin: () => number;
function globalErrorHandler
globalErrorHandler: (ex: Exception) => void;
Return the global error handler
Parameter ex
function hexToBase64
hexToBase64: (hexStr: string) => string;
function hexToBinary
hexToBinary: (hexStr: string) => Uint8Array;
function hrTime
hrTime: (performanceNow?: number) => api.HrTime;
Returns an hrtime calculated via performance component.
Parameter performanceNow
function hrTimeDuration
hrTimeDuration: (startTime: api.HrTime, endTime: api.HrTime) => api.HrTime;
Returns a duration of two hrTime.
Parameter startTime
Parameter endTime
function hrTimeToMicroseconds
hrTimeToMicroseconds: (time: api.HrTime) => number;
Convert hrTime to microseconds.
Parameter time
function hrTimeToMilliseconds
hrTimeToMilliseconds: (time: api.HrTime) => number;
Convert hrTime to milliseconds.
Parameter time
function hrTimeToNanoseconds
hrTimeToNanoseconds: (time: api.HrTime) => number;
Convert hrTime to nanoseconds.
Parameter time
function hrTimeToTimeStamp
hrTimeToTimeStamp: (time: api.HrTime) => string;
Convert hrTime to timestamp, for example "2019-05-14T17:00:00.000123456Z"
Parameter time
function isAttributeKey
isAttributeKey: (key: unknown) => key is string;
function isAttributeValue
isAttributeValue: (val: unknown) => val is SpanAttributeValue;
function isTimeInput
isTimeInput: (value: unknown) => value is any;
check if input value is a correct types.TimeInput
Parameter value
function isTimeInputHrTime
isTimeInputHrTime: (value: unknown) => value is api.HrTime;
check if time is HrTime
Parameter value
function isTracingSuppressed
isTracingSuppressed: (context: Context) => boolean;
function isUrlIgnored
isUrlIgnored: (url: string, ignoredUrls?: Array<string | RegExp>) => boolean;
Check if should be ignored when comparing against
Parameter url
Parameter ignoredUrls
function isWrapped
isWrapped: (func: unknown) => func is ShimWrapped;
Checks if certain function has been already wrapped
Parameter func
function loggingErrorHandler
loggingErrorHandler: () => ErrorHandler;
Returns a function that logs an error using the provided logger, or a console logger if one was not provided.
function merge
merge: (...args: any[]) => any;
Merges objects together
Parameter args
objects / values to be merged
function millisToHrTime
millisToHrTime: (epochMillis: number) => api.HrTime;
Converts a number of milliseconds from epoch to HrTime([seconds, remainder in nanoseconds]).
Parameter epochMillis
function parseEnvironment
parseEnvironment: (values: RAW_ENVIRONMENT) => ENVIRONMENT;
Parses environment values
Parameter values
function parseTraceParent
parseTraceParent: (traceParent: string) => SpanContext | null;
Parses information from the [traceparent] span tag and converts it into SpanContext
Parameter traceParent
A meta property that comes from server. It should be dynamically generated server side to have the server's request trace Id, a parent span Id that was set on the server's request span, and the trace flags to indicate the server's sampling decision (01 = sampled, 00 = not sampled). for example: '{version}-{traceId}-{spanId}-{sampleDecision}' For more information see https://www.w3.org/TR/trace-context/
function sanitizeAttributes
sanitizeAttributes: (attributes: unknown) => SpanAttributes;
function setGlobalErrorHandler
setGlobalErrorHandler: (handler: ErrorHandler) => void;
Set the global error handler
Parameter handler
function setRPCMetadata
setRPCMetadata: (context: Context, meta: RPCMetadata) => Context;
function suppressTracing
suppressTracing: (context: Context) => Context;
function timeInputToHrTime
timeInputToHrTime: (time: api.TimeInput) => api.HrTime;
Converts a TimeInput to an HrTime, defaults to _hrtime().
Parameter time
function unrefTimer
unrefTimer: (timer: NodeJS.Timer) => void;
function unsuppressTracing
unsuppressTracing: (context: Context) => Context;
function urlMatches
urlMatches: (url: string, urlToMatch: string | RegExp) => boolean;
Classes
class AlwaysOffSampler
class AlwaysOffSampler implements Sampler {}
Deprecated
Use the one defined in @opentelemetry/sdk-trace-base instead. Sampler that samples no traces.
method shouldSample
shouldSample: () => SamplingResult;
method toString
toString: () => string;
class AlwaysOnSampler
class AlwaysOnSampler implements Sampler {}
Deprecated
Use the one defined in @opentelemetry/sdk-trace-base instead. Sampler that samples all traces.
method shouldSample
shouldSample: () => SamplingResult;
method toString
toString: () => string;
class AnchoredClock
class AnchoredClock implements Clock {}
A utility for returning wall times anchored to a given point in time. Wall time measurements will not be taken from the system, but instead are computed by adding a monotonic clock time to the anchor point.
This is needed because the system time can change and result in unexpected situations like spans ending before they are started. Creating an anchored clock for each local root span ensures that span timings and durations are accurate while preventing span times from drifting too far from the system clock.
Only creating an anchored clock once per local trace ensures span times are correct relative to each other. For example, a child span will never have a start time before its parent even if the system clock is corrected during the local trace.
Heavily inspired by the OTel Java anchored clock https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/AnchoredClock.java
constructor
constructor(systemClock: Clock, monotonicClock: Clock);
Create a new AnchoredClock anchored to the current time returned by systemClock.
Parameter systemClock
should be a clock that returns the number of milliseconds since January 1 1970 such as Date
Parameter monotonicClock
should be a clock that counts milliseconds monotonically such as window.performance or perf_hooks.performance
method now
now: () => number;
Returns the current time by adding the number of milliseconds since the AnchoredClock was created to the creation epoch time
class BindOnceFuture
class BindOnceFuture< R, This = unknown, T extends (this: This, ...args: unknown[]) => R = () => R> {}
Bind the callback and only invoke the callback once regardless how many times
BindOnceFuture.call
is invoked.
constructor
constructor(_callback: (this: This, ...args: unknown[]) => R, _that: {});
property isCalled
readonly isCalled: boolean;
property promise
readonly promise: Promise<R>;
method call
call: (...args: Parameters<T>) => Promise<R>;
class CompositePropagator
class CompositePropagator implements TextMapPropagator {}
Combines multiple propagators into a single propagator.
constructor
constructor(config?: CompositePropagatorConfig);
Construct a composite propagator from a list of propagators.
Parameter config
Configuration object for composite propagator
method extract
extract: (context: Context, carrier: unknown, getter: TextMapGetter) => Context;
Run each of the configured propagators with the given context and carrier. Propagators are run in the order they are configured, so if multiple propagators write the same context key, the propagator later in the list will "win".
Parameter context
Context to add values to
Parameter carrier
Carrier from which to extract context
method fields
fields: () => string[];
method inject
inject: (context: Context, carrier: unknown, setter: TextMapSetter) => void;
Run each of the configured propagators with the given context and carrier. Propagators are run in the order they are configured, so if multiple propagators write the same carrier key, the propagator later in the list will "win".
Parameter context
Context to inject
Parameter carrier
Carrier into which context will be injected
class ParentBasedSampler
class ParentBasedSampler implements Sampler {}
Deprecated
Use the one defined in @opentelemetry/sdk-trace-base instead. A composite sampler that either respects the parent span's sampling decision or delegates to
delegateSampler
for root spans.
constructor
constructor(config: ParentBasedSamplerConfig);
method shouldSample
shouldSample: ( context: Context, traceId: string, spanName: string, spanKind: SpanKind, attributes: SpanAttributes, links: Link[]) => SamplingResult;
method toString
toString: () => string;
class RandomIdGenerator
class RandomIdGenerator implements IdGenerator {}
Deprecated
Use the one defined in @opentelemetry/sdk-trace-base instead.
property generateSpanId
generateSpanId: () => string;
Returns a random 8-byte span ID formatted/encoded as a 16 lowercase hex characters corresponding to 64 bits.
property generateTraceId
generateTraceId: () => string;
Returns a random 16-byte trace ID formatted/encoded as a 32 lowercase hex characters corresponding to 128 bits.
class TimeoutError
class TimeoutError extends Error {}
Error that is thrown on timeouts.
constructor
constructor(message?: string);
class TraceIdRatioBasedSampler
class TraceIdRatioBasedSampler implements Sampler {}
Deprecated
Use the one defined in @opentelemetry/sdk-trace-base instead. Sampler that samples a given fraction of traces based of trace id deterministically.
constructor
constructor(_ratio?: number);
method shouldSample
shouldSample: (context: unknown, traceId: string) => SamplingResult;
method toString
toString: () => string;
class TraceState
class TraceState implements api.TraceState {}
TraceState must be a class and not a simple object type because of the spec requirement (https://www.w3.org/TR/trace-context/#tracestate-field).
Here is the list of allowed mutations: - New key-value pair should be added into the beginning of the list - The value of any key can be updated. Modified keys MUST be moved to the beginning of the list.
constructor
constructor(rawTraceState?: string);
method get
get: (key: string) => string | undefined;
method serialize
serialize: () => string;
method set
set: (key: string, value: string) => TraceState;
method unset
unset: (key: string) => TraceState;
class W3CBaggagePropagator
class W3CBaggagePropagator implements TextMapPropagator {}
Propagates Baggage through Context format propagation.
Based on the Baggage specification: https://w3c.github.io/baggage/
class W3CTraceContextPropagator
class W3CTraceContextPropagator implements TextMapPropagator {}
Propagates SpanContext through Trace Context format propagation.
Based on the Trace Context specification: https://www.w3.org/TR/trace-context/
Interfaces
interface Clock
interface Clock {}
method now
now: () => number;
Return the current time in milliseconds from some epoch such as the Unix epoch or process start
interface CompositePropagatorConfig
interface CompositePropagatorConfig {}
Configuration object for composite propagator
property propagators
propagators?: TextMapPropagator[];
List of propagators to run. Propagators run in the list order. If a propagator later in the list writes the same context key as a propagator earlier in the list, the later on will "win".
interface ExportResult
interface ExportResult {}
interface IdGenerator
interface IdGenerator {}
Deprecated
Use the one defined in @opentelemetry/sdk-trace-base instead. IdGenerator provides an interface for generating Trace Id and Span Id.
method generateSpanId
generateSpanId: () => string;
Returns a span ID composed of 16 lowercase hex characters.
method generateTraceId
generateTraceId: () => string;
Returns a trace ID composed of 32 lowercase hex characters.
interface InstrumentationLibrary
interface InstrumentationLibrary {}
An instrumentation library consists of the name and optional version used to obtain a tracer or meter from a provider. This metadata is made available on ReadableSpan and MetricRecord for use by the export pipeline.
Deprecated
Use InstrumentationScope instead.
interface InstrumentationScope
interface InstrumentationScope {}
An instrumentation scope consists of the name and optional version used to obtain a tracer or meter from a provider. This metadata is made available on ReadableSpan and MetricRecord for use by the export pipeline.
interface ShimWrapped
interface ShimWrapped extends Function {}
This interface defines the params that are be added to the wrapped function using the "shimmer.wrap"
interface TimeOriginLegacy
interface TimeOriginLegacy {}
This interface defines a fallback to read a timeOrigin when it is not available on performance.timeOrigin, this happens for example on Safari Mac then the timeOrigin is taken from fetchStart - which is the closest to timeOrigin
property timing
timing: { fetchStart: number;};
Enums
enum ExportResultCode
enum ExportResultCode { SUCCESS = 0, FAILED = 1,}
enum TracesSamplerValues
enum TracesSamplerValues { AlwaysOff = 'always_off', AlwaysOn = 'always_on', ParentBasedAlwaysOff = 'parentbased_always_off', ParentBasedAlwaysOn = 'parentbased_always_on', ParentBasedTraceIdRatio = 'parentbased_traceidratio', TraceIdRatio = 'traceidratio',}
member AlwaysOff
AlwaysOff = 'always_off'
member AlwaysOn
AlwaysOn = 'always_on'
member ParentBasedAlwaysOff
ParentBasedAlwaysOff = 'parentbased_always_off'
member ParentBasedAlwaysOn
ParentBasedAlwaysOn = 'parentbased_always_on'
member ParentBasedTraceIdRatio
ParentBasedTraceIdRatio = 'parentbased_traceidratio'
member TraceIdRatio
TraceIdRatio = 'traceidratio'
Type Aliases
type ENVIRONMENT
type ENVIRONMENT = { CONTAINER_NAME?: string; ECS_CONTAINER_METADATA_URI_V4?: string; ECS_CONTAINER_METADATA_URI?: string; HOSTNAME?: string; KUBERNETES_SERVICE_HOST?: string; NAMESPACE?: string; OTEL_EXPORTER_JAEGER_AGENT_HOST?: string; OTEL_EXPORTER_JAEGER_ENDPOINT?: string; OTEL_EXPORTER_JAEGER_PASSWORD?: string; OTEL_EXPORTER_JAEGER_USER?: string; OTEL_EXPORTER_OTLP_ENDPOINT?: string; OTEL_EXPORTER_OTLP_TRACES_ENDPOINT?: string; OTEL_EXPORTER_OTLP_METRICS_ENDPOINT?: string; OTEL_EXPORTER_OTLP_LOGS_ENDPOINT?: string; OTEL_EXPORTER_OTLP_HEADERS?: string; OTEL_EXPORTER_OTLP_TRACES_HEADERS?: string; OTEL_EXPORTER_OTLP_METRICS_HEADERS?: string; OTEL_EXPORTER_OTLP_LOGS_HEADERS?: string; OTEL_EXPORTER_ZIPKIN_ENDPOINT?: string; OTEL_LOG_LEVEL?: DiagLogLevel; OTEL_RESOURCE_ATTRIBUTES?: string; OTEL_SERVICE_NAME?: string; OTEL_TRACES_EXPORTER?: string; OTEL_TRACES_SAMPLER_ARG?: string; OTEL_TRACES_SAMPLER?: string; OTEL_LOGS_EXPORTER?: string; OTEL_EXPORTER_OTLP_INSECURE?: string; OTEL_EXPORTER_OTLP_TRACES_INSECURE?: string; OTEL_EXPORTER_OTLP_METRICS_INSECURE?: string; OTEL_EXPORTER_OTLP_LOGS_INSECURE?: string; OTEL_EXPORTER_OTLP_CERTIFICATE?: string; OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE?: string; OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE?: string; OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE?: string; OTEL_EXPORTER_OTLP_COMPRESSION?: string; OTEL_EXPORTER_OTLP_TRACES_COMPRESSION?: string; OTEL_EXPORTER_OTLP_METRICS_COMPRESSION?: string; OTEL_EXPORTER_OTLP_LOGS_COMPRESSION?: string; OTEL_EXPORTER_OTLP_CLIENT_KEY?: string; OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY?: string; OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEY?: string; OTEL_EXPORTER_OTLP_LOGS_CLIENT_KEY?: string; OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE?: string; OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE?: string; OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE?: string; OTEL_EXPORTER_OTLP_LOGS_CLIENT_CERTIFICATE?: string; OTEL_EXPORTER_OTLP_PROTOCOL?: string; OTEL_EXPORTER_OTLP_TRACES_PROTOCOL?: string; OTEL_EXPORTER_OTLP_METRICS_PROTOCOL?: string; OTEL_EXPORTER_OTLP_LOGS_PROTOCOL?: string; OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE?: string;} & ENVIRONMENT_BOOLEANS & ENVIRONMENT_NUMBERS & ENVIRONMENT_LISTS;
type ErrorHandler
type ErrorHandler = (ex: Exception) => void;
Defines an error handler function
type RAW_ENVIRONMENT
type RAW_ENVIRONMENT = { [key: string]: string | number | undefined | string[];};
type RPCMetadata
type RPCMetadata = HTTPMetadata;
Allows for future rpc metadata to be used with this mechanism
Package Files (34)
- build/src/ExportResult.d.ts
- build/src/baggage/propagation/W3CBaggagePropagator.d.ts
- build/src/common/anchored-clock.d.ts
- build/src/common/attributes.d.ts
- build/src/common/global-error-handler.d.ts
- build/src/common/hex-to-binary.d.ts
- build/src/common/logging-error-handler.d.ts
- build/src/common/time.d.ts
- build/src/common/types.d.ts
- build/src/index.d.ts
- build/src/platform/node/RandomIdGenerator.d.ts
- build/src/platform/node/environment.d.ts
- build/src/platform/node/hex-to-base64.d.ts
- build/src/platform/node/performance.d.ts
- build/src/platform/node/sdk-info.d.ts
- build/src/platform/node/timer-util.d.ts
- build/src/propagation/composite.d.ts
- build/src/trace/IdGenerator.d.ts
- build/src/trace/TraceState.d.ts
- build/src/trace/W3CTraceContextPropagator.d.ts
- build/src/trace/rpc-metadata.d.ts
- build/src/trace/sampler/AlwaysOffSampler.d.ts
- build/src/trace/sampler/AlwaysOnSampler.d.ts
- build/src/trace/sampler/ParentBasedSampler.d.ts
- build/src/trace/sampler/TraceIdRatioBasedSampler.d.ts
- build/src/trace/suppress-tracing.d.ts
- build/src/utils/callback.d.ts
- build/src/utils/environment.d.ts
- build/src/utils/merge.d.ts
- build/src/utils/sampling.d.ts
- build/src/utils/timeout.d.ts
- build/src/utils/url.d.ts
- build/src/utils/wrap.d.ts
- build/src/version.d.ts
Dependencies (1)
Dev Dependencies (21)
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/core
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@opentelemetry/core)
- HTML<a href="https://www.jsdocs.io/package/@opentelemetry/core"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 4251 ms. - Missing or incorrect documentation? Open an issue for this package.