UNPKG

@temporalio/interceptors-opentelemetry

Version:
45 lines (44 loc) 2.54 kB
import * as otel from '@opentelemetry/api'; import type { Resource } from '@opentelemetry/resources'; import type { SpanExporter, SpanProcessor } from '@opentelemetry/sdk-trace-base'; import type { Context as ActivityContext } from '@temporalio/activity'; import type { Next, ActivityInboundCallsInterceptor, ActivityOutboundCallsInterceptor, InjectedSink, GetLogAttributesInput, GetMetricTagsInput, ActivityExecuteInput } from '@temporalio/worker'; import { type OpenTelemetryWorkflowExporter } from '../workflow/definitions'; export interface InterceptorOptions { readonly tracer?: otel.Tracer; } /** * Intercepts calls to start an Activity. * * Wraps the operation in an opentelemetry Span and links it to a parent Span context if one is * provided in the Activity input headers. */ export declare class OpenTelemetryActivityInboundInterceptor implements ActivityInboundCallsInterceptor { protected readonly ctx: ActivityContext; protected readonly tracer: otel.Tracer; constructor(ctx: ActivityContext, options?: InterceptorOptions); execute(input: ActivityExecuteInput, next: Next<ActivityInboundCallsInterceptor, 'execute'>): Promise<unknown>; } /** * Intercepts calls to emit logs and metrics from an Activity. * * Attach OpenTelemetry context tracing attributes to emitted log messages and metrics, if appropriate. */ export declare class OpenTelemetryActivityOutboundInterceptor implements ActivityOutboundCallsInterceptor { protected readonly ctx: ActivityContext; constructor(ctx: ActivityContext); getLogAttributes(input: GetLogAttributesInput, next: Next<ActivityOutboundCallsInterceptor, 'getLogAttributes'>): Record<string, unknown>; getMetricTags(input: GetMetricTagsInput, next: Next<ActivityOutboundCallsInterceptor, 'getMetricTags'>): GetMetricTagsInput; } /** * Takes an opentelemetry SpanExporter and turns it into an injected Workflow span exporter sink * * @deprecated Do not directly pass a `SpanExporter`. Pass a `SpanProcessor` instead to ensure proper handling of async attributes. */ export declare function makeWorkflowExporter(spanExporter: SpanExporter, resource: Resource): InjectedSink<OpenTelemetryWorkflowExporter>; /** * Takes an opentelemetry SpanProcessor and turns it into an injected Workflow span exporter sink. * * For backward compatibility, passing a `SpanExporter` directly is still supported. */ export declare function makeWorkflowExporter(spanProcessor: SpanProcessor, resource: Resource): InjectedSink<OpenTelemetryWorkflowExporter>;