@temporalio/interceptors-opentelemetry
Version:
Temporal.io SDK interceptors bundle for tracing with opentelemetry
70 lines (69 loc) • 4.13 kB
TypeScript
import * as otel from '@opentelemetry/api';
import type { Resource } from '@opentelemetry/resources';
import type { SpanExporter, SpanProcessor } from '@opentelemetry/sdk-trace-base';
import type * as nexus from 'nexus-rpc';
import type { Context as ActivityContext } from '@temporalio/activity';
import type { Next, ActivityInboundCallsInterceptor, ActivityOutboundCallsInterceptor, NexusInboundCallsInterceptor, NexusOutboundCallsInterceptor, NexusStartOperationInput, NexusStartOperationOutput, NexusCancelOperationInput, 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;
}
/**
* Intercepts inbound Nexus Operation calls on the worker.
*
* Wraps `startOperation` and `cancelOperation` in opentelemetry Spans, linking to a parent Span context
* if one is provided in the Nexus request headers.
*/
export declare class OpenTelemetryNexusInboundInterceptor implements NexusInboundCallsInterceptor {
protected readonly ctx: nexus.OperationContext;
protected readonly tracer: otel.Tracer;
constructor(ctx: nexus.OperationContext, options?: InterceptorOptions);
startOperation(input: NexusStartOperationInput, next: Next<NexusInboundCallsInterceptor, 'startOperation'>): Promise<NexusStartOperationOutput>;
cancelOperation(input: NexusCancelOperationInput, next: Next<NexusInboundCallsInterceptor, 'cancelOperation'>): Promise<void>;
}
/**
* Intercepts outbound calls from a Nexus Operation handler.
*
* Attaches OpenTelemetry context tracing attributes to emitted log messages and metrics.
*/
export declare class OpenTelemetryNexusOutboundInterceptor implements NexusOutboundCallsInterceptor {
protected readonly ctx: nexus.OperationContext;
constructor(ctx: nexus.OperationContext);
getLogAttributes(input: GetLogAttributesInput, next: Next<NexusOutboundCallsInterceptor, 'getLogAttributes'>): Record<string, unknown>;
getMetricTags(input: GetMetricTagsInput, next: Next<NexusOutboundCallsInterceptor, '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>;