@opentelemetry/core
- Version 2.0.0
- Published
- 679 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()
- diagLogLevelFromString()
- getBooleanFromEnv()
- getNumberFromEnv()
- getRPCMetadata()
- getStringFromEnv()
- getStringListFromEnv()
- getTimeOrigin()
- globalErrorHandler()
- hrTime()
- hrTimeDuration()
- hrTimeToMicroseconds()
- hrTimeToMilliseconds()
- hrTimeToNanoseconds()
- hrTimeToTimeStamp()
- isAttributeValue()
- isTimeInput()
- isTimeInputHrTime()
- isTracingSuppressed()
- isUrlIgnored()
- loggingErrorHandler()
- merge()
- millisToHrTime()
- parseKeyPairsIntoRecord()
- parseTraceParent()
- sanitizeAttributes()
- setGlobalErrorHandler()
- setRPCMetadata()
- suppressTracing()
- timeInputToHrTime()
- unrefTimer()
- unsuppressTracing()
- urlMatches()
Classes
Interfaces
Enums
Type Aliases
Variables
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;
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 diagLogLevelFromString
diagLogLevelFromString: (value: string | undefined) => DiagLogLevel | undefined;
Convert a string to a DiagLogLevel, defaults to DiagLogLevel if the log level does not exist or undefined if the input is undefined.
Parameter value
function getBooleanFromEnv
getBooleanFromEnv: (key: string) => boolean;
Retrieves a boolean value from an environment variable. - Trims leading and trailing whitespace and ignores casing. - Returns
false
if the environment variable is empty, unset, or contains only whitespace. - Returnsfalse
for strings that cannot be mapped to a boolean.Parameter key
The name of the environment variable to retrieve.
Returns
{boolean} - The boolean value or
false
if the environment variable is unset empty, unset, or contains only whitespace.
function getNumberFromEnv
getNumberFromEnv: (key: string) => number | undefined;
Retrieves a number from an environment variable. - Returns
undefined
if the environment variable is empty, unset, contains only whitespace, or is not a number. - Returns a number in all other cases.Parameter key
The name of the environment variable to retrieve.
Returns
{number | undefined} - The number value or
undefined
.
function getRPCMetadata
getRPCMetadata: (context: Context) => RPCMetadata | undefined;
function getStringFromEnv
getStringFromEnv: (key: string) => string | undefined;
Retrieves a string from an environment variable. - Returns
undefined
if the environment variable is empty, unset, or contains only whitespace.Parameter key
The name of the environment variable to retrieve.
Returns
{string | undefined} - The string value or
undefined
.
function getStringListFromEnv
getStringListFromEnv: (key: string) => string[] | undefined;
Retrieves a list of strings from an environment variable. - Uses ',' as the delimiter. - Trims leading and trailing whitespace from each entry. - Excludes empty entries. - Returns
undefined
if the environment variable is empty or contains only whitespace. - Returns an empty array if all entries are empty or whitespace.Parameter key
The name of the environment variable to retrieve.
Returns
{string[] | undefined} - The list of strings or
undefined
.
function getTimeOrigin
getTimeOrigin: () => number;
function globalErrorHandler
globalErrorHandler: (ex: Exception) => void;
Return the global error handler
Parameter ex
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 isAttributeValue
isAttributeValue: (val: unknown) => val is AttributeValue;
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 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 parseKeyPairsIntoRecord
parseKeyPairsIntoRecord: (value?: string) => Record<string, string>;
Parse a string serialized in the baggage HTTP Format (without metadata): https://github.com/w3c/baggage/blob/master/baggage/HTTP_HEADER_FORMAT.md
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) => Attributes;
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 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 TimeoutError
class TimeoutError extends Error {}
Error that is thrown on timeouts.
constructor
constructor(message?: 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 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.
Enums
enum ExportResultCode
enum ExportResultCode { SUCCESS = 0, FAILED = 1,}
Type Aliases
type ErrorHandler
type ErrorHandler = (ex: Exception) => void;
Defines an error handler function
type RPCMetadata
type RPCMetadata = HTTPMetadata;
Allows for future rpc metadata to be used with this mechanism
Package Files (24)
- build/src/ExportResult.d.ts
- build/src/baggage/propagation/W3CBaggagePropagator.d.ts
- build/src/baggage/utils.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/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/environment.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/TraceState.d.ts
- build/src/trace/W3CTraceContextPropagator.d.ts
- build/src/trace/rpc-metadata.d.ts
- build/src/trace/suppress-tracing.d.ts
- build/src/utils/callback.d.ts
- build/src/utils/configuration.d.ts
- build/src/utils/merge.d.ts
- build/src/utils/timeout.d.ts
- build/src/utils/url.d.ts
Dependencies (1)
Dev Dependencies (20)
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[](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 5551 ms. - Missing or incorrect documentation? Open an issue for this package.