/** * opentelemetry instrumentation helper functions * @module */ import * as otel from '@opentelemetry/api'; import { type Headers } from '@temporalio/common'; /** Default trace header for opentelemetry interceptors */ export declare const TRACE_HEADER = "_tracer-data"; /** As in workflow run id */ export declare const RUN_ID_ATTR_KEY = "run_id"; /** As in workflow id */ export declare const WORKFLOW_ID_ATTR_KEY = "temporalWorkflowId"; /** As in activity id */ export declare const ACTIVITY_ID_ATTR_KEY = "temporalActivityId"; /** As in update id */ export declare const UPDATE_ID_ATTR_KEY = "temporalUpdateId"; /** As in termination reason */ export declare const TERMINATE_REASON_ATTR_KEY = "temporalTerminateReason"; /** As in Nexus service */ export declare const NEXUS_SERVICE_ATTR_KEY = "temporalNexusService"; /** As in Nexus operation */ export declare const NEXUS_OPERATION_ATTR_KEY = "temporalNexusOperation"; /** As in Nexus endpoint */ export declare const NEXUS_ENDPOINT_ATTR_KEY = "temporalNexusEndpoint"; /** * If found, return an otel Context deserialized from the provided headers */ export declare function extractContextFromHeaders(headers: Headers): otel.Context | undefined; /** * If found, return an otel Context deserialized from the provided Nexus headers. * * Nexus headers are plain `Record`, so we extract the context * directly from the string map. */ export declare function extractContextFromNexusHeaders(headers: Record): otel.Context | undefined; /** * Given headers, return new headers with the current otel context inserted */ export declare function headersWithContext(headers: Headers): Headers; /** * Given headers represented as application values, return new headers with the * current OpenTelemetry context inserted. The caller's payload converter is * responsible for serializing these values later. */ export declare function rawHeadersWithContext(headers: Record | undefined): Record; /** * Given Nexus headers, return new headers with the current otel context injected directly */ export declare function nexusHeadersWithContext(headers: Record): Record; export interface InstrumentOptions { tracer: otel.Tracer; spanName: string; fn: (span: otel.Span) => Promise; context?: otel.Context; acceptableErrors?: (err: unknown) => boolean; } export type InstrumentOptionsSync = Omit, 'fn'> & { fn: (span: otel.Span) => T; }; export type InstrumentOptionsAsyncIterable = Omit, 'fn'> & { fn: (span: otel.Span) => AsyncIterable; }; /** * Wraps `fn` in a span which ends when function returns or throws */ export declare function instrument({ tracer, spanName, fn, context, acceptableErrors, }: InstrumentOptions): Promise; export declare function instrumentSync({ tracer, spanName, fn, context, acceptableErrors }: InstrumentOptionsSync): T; /** * Wraps an async iterable in a span whose lifetime matches iteration. * * The returned iterable is lazy: creating it does not open a span. The span starts on the first * `next()` call, remains open while the iterator is in use, and ends on completion, early * termination (`return`), or error. */ export declare function instrumentAsyncIterable({ tracer, spanName, fn, context, acceptableErrors, }: InstrumentOptionsAsyncIterable): AsyncIterable;