import * as pb from "../proto/orchestrator_service_pb"; import type { Span, Tracer } from "@opentelemetry/api"; /** * Gets the Durable Task tracer from the OpenTelemetry API. * Returns undefined if OpenTelemetry is not installed. */ export declare function getTracer(): Tracer | undefined; /** * Information about an orchestration span for replay continuity. * * `spanId` is a DurableTask-specific replay correlation identifier. On the first * execution it equals the actual OTEL span ID. On replays, it is carried forward * from the first execution so all replay iterations share a stable identifier, * even though each replay creates a new OTEL span with its own spanId. */ export interface OrchestrationSpanInfo { spanId: string; /** * The start time from the first execution, persisted across replays in * OrchestrationTraceContext. On replay invocations this is the original * first-execution time, which may differ from the OTEL span's actual * startTime (which is always the current wall-clock time). */ startTime: Date; } /** * Creates a Producer span for scheduling a new orchestration (client-side). * Injects the W3C trace context into the CreateInstanceRequest. * * @param req - The CreateInstanceRequest to inject trace context into. * @returns The span (or undefined if OTEL is not available). Caller must end it. */ export declare function startSpanForNewOrchestration(req: pb.CreateInstanceRequest): Span | undefined; /** * Creates a Server span for orchestration execution. * Handles replay by reusing the same span identity across multiple invocations. * * @param executionStartedEvent - The proto ExecutionStartedEvent. * @param orchestrationTraceContext - The OrchestrationTraceContext from the request (for replay). * @param instanceId - The orchestration instance ID. * @returns An object with the span and span info for the response, or undefined if OTEL is not available. */ export declare function startSpanForOrchestrationExecution(executionStartedEvent: pb.ExecutionStartedEvent, orchestrationTraceContext: pb.OrchestrationTraceContext | undefined, instanceId: string): { span: Span; spanInfo: OrchestrationSpanInfo; } | undefined; /** * Creates a Client span for scheduling an activity task (worker-side, within orchestration execution). * Injects trace context into the ScheduleTaskAction. * * @param orchestrationSpan - The parent orchestration span. * @param action - The ScheduleTaskAction to inject trace context into. * @param taskId - The sequential task ID. */ /** * Injects trace context into a ScheduleTaskAction for activity scheduling. * Generates a random client span ID (matching .NET's CreateTraceContext pattern) * without creating an actual Client span — the retroactive Client span is emitted * later from processNewEventsForTracing when the activity completes. * * @param orchestrationSpan - The parent orchestration span. * @param action - The ScheduleTaskAction to inject trace context into. */ export declare function injectTraceContextForSchedulingTask(orchestrationSpan: Span, action: pb.ScheduleTaskAction): void; /** * Creates a Server span for activity task execution (worker-side). * * @param req - The ActivityRequest containing the parent trace context. * @returns The span (or undefined if OTEL is not available). Caller must end it. */ export declare function startSpanForTaskExecution(req: pb.ActivityRequest): Span | undefined; /** * Creates a Client span for scheduling a sub-orchestration (worker-side, within orchestration execution). * Injects trace context into the CreateSubOrchestrationAction. * * @param orchestrationSpan - The parent orchestration span. * @param action - The CreateSubOrchestrationAction to inject trace context into. * @param taskId - The sequential task ID. */ /** * Injects trace context into a CreateSubOrchestrationAction for sub-orchestration scheduling. * Generates a random client span ID (matching .NET's CreateTraceContext pattern) * without creating an actual Client span — the retroactive Client span is emitted * later from processNewEventsForTracing when the sub-orchestration completes. * * @param orchestrationSpan - The parent orchestration span. * @param action - The CreateSubOrchestrationAction to inject trace context into. */ export declare function injectTraceContextForSchedulingSubOrchestration(orchestrationSpan: Span, action: pb.CreateSubOrchestrationAction): void; /** * Emits a span for a timer being created within an orchestration. * * @param orchestrationSpan - The parent orchestration span. * @param orchestrationName - The name of the parent orchestration. * @param fireAt - When the timer fires. * @param timerId - The timer's sequential ID. * @param instanceId - The orchestration instance ID. */ export declare function emitSpanForTimer(orchestrationSpan: Span, orchestrationName: string, fireAt: Date, timerId: number, instanceId?: string, startTime?: Date): void; /** * Emits a retroactive Client-kind span for a completed/failed activity task. * This matches the .NET SDK pattern (EmitTraceActivityForTaskCompleted/Failed) where * client spans are emitted at completion time with startTime from the original * TaskScheduled event timestamp, providing accurate scheduling-to-completion duration. * * @param orchestrationSpan - The parent orchestration span. * @param taskName - The activity name. * @param version - The activity version (optional). * @param instanceId - The orchestration instance ID. * @param taskId - The task's sequential ID. * @param startTime - The scheduling timestamp from the TaskScheduled history event. * @param failureMessage - If the task failed, the error message. */ export declare function emitRetroactiveActivityClientSpan(orchestrationSpan: Span, taskName: string, version: string | undefined, instanceId: string, taskId: number, startTime?: Date, failureMessage?: string): void; /** * Emits a retroactive Client-kind span for a completed/failed sub-orchestration. * Matches .NET SDK's EmitTraceActivityForSubOrchestrationCompleted/Failed pattern. * * @param orchestrationSpan - The parent orchestration span. * @param subOrchName - The sub-orchestration name. * @param version - The sub-orchestration version (optional). * @param instanceId - The parent orchestration instance ID. * @param startTime - The scheduling timestamp from the SubOrchestrationInstanceCreated event. * @param failureMessage - If the sub-orchestration failed, the error message. */ export declare function emitRetroactiveSubOrchClientSpan(orchestrationSpan: Span, subOrchName: string, version: string | undefined, instanceId: string, startTime?: Date, failureMessage?: string): void; /** * Processes new history events to emit retroactive spans for completed/failed tasks, * sub-orchestrations, and fired timers. This follows the .NET SDK pattern where the * worker emits these spans before the orchestrator executor runs. * * @param orchestrationSpan - The orchestration span (parent for retroactive spans). * @param pastEvents - The past (replay) history events to look up scheduling events. * @param newEvents - The new history events to process for completions/failures. * @param instanceId - The orchestration instance ID. * @param orchestrationName - The orchestration name (for timer spans). */ export declare function processNewEventsForTracing(orchestrationSpan: Span | undefined | null, pastEvents: pb.HistoryEvent[], newEvents: pb.HistoryEvent[], instanceId: string, orchestrationName: string): void; /** * Emits a span for sending an event to another orchestration. * * @param orchestrationSpan - The parent orchestration span. * @param eventName - The name of the event. * @param targetInstanceId - The target orchestration instance ID. * @param instanceId - The source orchestration instance ID. * @param executionId - The source orchestration execution ID. */ export declare function emitSpanForEventSent(orchestrationSpan: Span, eventName: string, targetInstanceId?: string, instanceId?: string, executionId?: string): void; /** * Creates a Producer span for raising an event from the client. * * @param eventName - The name of the event. * @param instanceId - The target orchestration instance ID. * @returns The span (or undefined if OTEL is not available). Caller must end it. */ export declare function startSpanForEventRaisedFromClient(eventName: string, instanceId: string): Span | undefined; /** * Sets span status to error and records the error. * * @param span - The span to set error status on. * @param error - The error to record. */ export declare function setSpanError(span: Span | undefined | null, error: unknown): void; /** * Sets span status to OK. * * @param span - The span to set OK status on. */ export declare function setSpanOk(span: Span | undefined | null): void; /** * Safely ends a span, ignoring errors. * * @param span - The span to end. */ export declare function endSpan(span: Span | undefined | null): void; /** * Sets the orchestration completion status attribute and span status based on the * completion action. Matches .NET behavior: sets ERROR status with result message * when orchestration fails, OK otherwise. * * @param span - The orchestration span. * @param actions - The orchestrator actions to inspect for completion status. */ export declare function setOrchestrationStatusFromActions(span: Span | undefined | null, actions: pb.OrchestratorAction[]): void; /** * Creates an OrchestrationTraceContext protobuf message for the orchestrator response. * * @param spanInfo - The span info to encode. * @returns The OrchestrationTraceContext protobuf message. */ export declare function createOrchestrationTraceContextPb(spanInfo: OrchestrationSpanInfo): pb.OrchestrationTraceContext; /** * Processes orchestrator actions to inject trace context for distributed tracing. * This is called after the orchestration executor returns its actions. * * @param orchestrationSpan - The orchestration span (parent for action spans). * @param actions - The OrchestratorAction list to process. * @param orchestrationName - The name of the orchestration (for timer spans). * @param instanceId - The orchestration instance ID (for enriching span attributes). * @param executionId - The orchestration execution ID (for event spans). */ export declare function processActionsForTracing(orchestrationSpan: Span | undefined | null, actions: pb.OrchestratorAction[], orchestrationName: string, instanceId?: string, executionId?: string): void; /** * Emits a span for calling an entity from an orchestration (request/response). * * @param orchestrationSpan - The parent orchestration span. * @param operationName - The entity operation name. * @param targetInstanceId - The target entity instance ID. * @param taskId - The sequential task ID. */ export declare function emitSpanForEntityCall(orchestrationSpan: Span, operationName: string, targetInstanceId?: string, taskId?: number): void; /** * Emits a span for signaling an entity from an orchestration (fire-and-forget). * * @param orchestrationSpan - The parent orchestration span. * @param operationName - The entity operation name. * @param targetInstanceId - The target entity instance ID. * @param taskId - The sequential task ID. */ export declare function emitSpanForEntitySignal(orchestrationSpan: Span, operationName: string, targetInstanceId?: string, taskId?: number): void; /** * Emits a span for requesting entity locks from an orchestration. * * @param orchestrationSpan - The parent orchestration span. * @param taskId - The sequential task ID. */ export declare function emitSpanForEntityLockRequest(orchestrationSpan: Span, taskId: number): void; /** * Creates a Producer span for signaling an entity from the client. * * @param entityId - The target entity instance ID string. * @param operationName - The entity operation name. * @returns The span (or undefined if OTEL is not available). Caller must end it. */ export declare function startSpanForSignalEntityFromClient(entityId: string, operationName: string): Span | undefined;