@opentelemetry/core

  • Version 1.2.0
  • Published
  • 772 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

Classes

Interfaces

Enums

Type Aliases

Namespaces

Variables

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 otperformance

      const otperformance: any;

        variable SDK_INFO

        const SDK_INFO: { [x: string]: 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 deleteRPCMetadata

              deleteRPCMetadata: (context: Context) => Context;

                function getEnv

                getEnv: () => Required<ENVIRONMENT>;
                • Gets the environment variables

                function getRPCMetadata

                getRPCMetadata: (context: Context) => RPCMetadata | undefined;

                  function globalErrorHandler

                  globalErrorHandler: (ex: Exception) => void;
                  • Return the global error handler

                    Parameter ex

                  function hexToBase64

                  hexToBase64: (hexStr: string) => string;

                    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 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 {}
                                      • Sampler that samples no traces.

                                      method shouldSample

                                      shouldSample: () => SamplingResult;

                                        method toString

                                        toString: () => string;

                                          class AlwaysOnSampler

                                          class AlwaysOnSampler implements Sampler {}
                                          • Sampler that samples all traces.

                                          method shouldSample

                                          shouldSample: () => SamplingResult;

                                            method toString

                                            toString: () => string;

                                              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 {}
                                                        • 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 {}

                                                                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 TraceIdRatioBasedSampler

                                                                class TraceIdRatioBasedSampler implements Sampler {}
                                                                • 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/

                                                                                method extract

                                                                                extract: (context: Context, carrier: unknown, getter: TextMapGetter) => Context;

                                                                                  method fields

                                                                                  fields: () => string[];

                                                                                    method inject

                                                                                    inject: (context: Context, carrier: unknown, setter: TextMapSetter) => void;

                                                                                      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/

                                                                                      method extract

                                                                                      extract: (context: Context, carrier: unknown, getter: TextMapGetter) => Context;

                                                                                        method fields

                                                                                        fields: () => string[];

                                                                                          method inject

                                                                                          inject: (context: Context, carrier: unknown, setter: TextMapSetter) => void;

                                                                                            Interfaces

                                                                                            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 {}

                                                                                              property code

                                                                                              code: ExportResultCode;

                                                                                                property error

                                                                                                error?: Error;

                                                                                                  interface IdGenerator

                                                                                                  interface IdGenerator {}
                                                                                                  • 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 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.

                                                                                                  property name

                                                                                                  readonly name: string;

                                                                                                    property schemaUrl

                                                                                                    readonly schemaUrl?: string;

                                                                                                      property version

                                                                                                      readonly version?: string;

                                                                                                        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,
                                                                                                          }

                                                                                                            member FAILED

                                                                                                            FAILED = 1

                                                                                                              member SUCCESS

                                                                                                              SUCCESS = 0

                                                                                                                enum RPCType

                                                                                                                enum RPCType {
                                                                                                                HTTP = 'http',
                                                                                                                }

                                                                                                                  member HTTP

                                                                                                                  HTTP = 'http'

                                                                                                                    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_HEADERS?: string;
                                                                                                                                  OTEL_EXPORTER_OTLP_TRACES_HEADERS?: string;
                                                                                                                                  OTEL_EXPORTER_OTLP_METRICS_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_EXPORTER_OTLP_COMPRESSION?: string;
                                                                                                                                  OTEL_EXPORTER_OTLP_TRACES_COMPRESSION?: string;
                                                                                                                                  OTEL_EXPORTER_OTLP_METRICS_COMPRESSION?: string;
                                                                                                                                  } & 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

                                                                                                                                      Namespaces

                                                                                                                                      namespace baggageUtils

                                                                                                                                      module 'build/src/baggage/utils.d.ts' {}
                                                                                                                                      • Parse a string serialized in the baggage HTTP Format (without metadata): https://github.com/w3c/baggage/blob/master/baggage/HTTP_HEADER_FORMAT.md

                                                                                                                                      function getKeyPairs

                                                                                                                                      getKeyPairs: (baggage: Baggage) => string[];

                                                                                                                                        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 parsePairKeyValue

                                                                                                                                        parsePairKeyValue: (entry: string) => ParsedBaggageKeyValue | undefined;

                                                                                                                                          function serializeKeyPairs

                                                                                                                                          serializeKeyPairs: (keyPairs: string[]) => string;

                                                                                                                                            Package Files (32)

                                                                                                                                            Dependencies (1)

                                                                                                                                            Dev Dependencies (22)

                                                                                                                                            Peer Dependencies (1)

                                                                                                                                            Badge

                                                                                                                                            To add a badge like this onejsDocs.io badgeto 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>