Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### New

- Align tracing attributes with .NET SDK conventions: add `execution_id` on creation spans, `version` on activity execution spans, `name`/`instance_id` on timer spans, and `durabletask.task.status` on orchestration completion
Comment thread
torosent marked this conversation as resolved.
Outdated

### Fixes


Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/tracing/jaeger-span-attributes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/tracing/jaeger-trace-detail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/tracing/jaeger-trace-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions examples/azure-managed/distributed-tracing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import { NodeSDK } from "@opentelemetry/sdk-node";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base";
import { resourceFromAttributes } from "@opentelemetry/resources";
import { Resource } from "@opentelemetry/resources";
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";

// Load environment variables from .env file
Expand All @@ -30,10 +30,10 @@ const traceExporter = new OTLPTraceExporter({
});

const sdk = new NodeSDK({
resource: resourceFromAttributes({
resource: new Resource({
[ATTR_SERVICE_NAME]: "durabletask-js-tracing-example",
}),
spanProcessors: [new SimpleSpanProcessor(traceExporter)],
spanProcessors: [new SimpleSpanProcessor(traceExporter) as any],
});
Comment thread
torosent marked this conversation as resolved.

sdk.start();
Expand Down
1 change: 1 addition & 0 deletions packages/durabletask-js/src/tracing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export {
setSpanError,
setSpanOk,
endSpan,
setOrchestrationStatusFromActions,
createOrchestrationTraceContextPb,
processActionsForTracing,
} from "./trace-helper";
66 changes: 64 additions & 2 deletions packages/durabletask-js/src/tracing/trace-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ export function startSpanForNewOrchestration(req: pb.CreateInstanceRequest): Spa
[DurableTaskAttributes.TASK_NAME]: name,
[DurableTaskAttributes.TASK_INSTANCE_ID]: instanceId,
...(version ? { [DurableTaskAttributes.TASK_VERSION]: version } : {}),
...(req.getExecutionid()?.getValue()
? { [DurableTaskAttributes.TASK_EXECUTION_ID]: req.getExecutionid()!.getValue() }
: {}),
Comment thread
torosent marked this conversation as resolved.
Outdated
},
});

Expand Down Expand Up @@ -229,7 +232,8 @@ export function startSpanForTaskExecution(req: pb.ActivityRequest): Span | undef
if (!ctx) return undefined;

const name = req.getName();
const spanName = createSpanName(TaskType.ACTIVITY, name);
const version = req.getVersion()?.getValue();
const spanName = createSpanName(TaskType.ACTIVITY, name, version);

const parentPbCtx = req.getParenttracecontext();
const parentContext = createParentContextFromPb(parentPbCtx);
Expand All @@ -245,6 +249,7 @@ export function startSpanForTaskExecution(req: pb.ActivityRequest): Span | undef
[DurableTaskAttributes.TASK_NAME]: name,
[DurableTaskAttributes.TASK_INSTANCE_ID]: instanceId,
[DurableTaskAttributes.TASK_TASK_ID]: req.getTaskid(),
...(version ? { [DurableTaskAttributes.TASK_VERSION]: version } : {}),
},
},
parentContext,
Expand Down Expand Up @@ -308,12 +313,14 @@ export function startSpanForSchedulingSubOrchestration(
* @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 function emitSpanForTimer(
orchestrationSpan: Span,
orchestrationName: string,
fireAt: Date,
timerId: number,
instanceId?: string,
): void {
const ctx = getTracingContext();
if (!ctx) return;
Expand All @@ -327,8 +334,10 @@ export function emitSpanForTimer(
kind: ctx.otel.SpanKind.INTERNAL,
attributes: {
[DurableTaskAttributes.TYPE]: TaskType.TIMER,
[DurableTaskAttributes.TASK_NAME]: orchestrationName,
[DurableTaskAttributes.TASK_TASK_ID]: timerId,
[DurableTaskAttributes.FIRE_AT]: fireAt.toISOString(),
...(instanceId ? { [DurableTaskAttributes.TASK_INSTANCE_ID]: instanceId } : {}),
},
},
parentContext,
Expand Down Expand Up @@ -440,6 +449,57 @@ export function endSpan(span: Span | undefined | null): void {
}
}

/**
* Sets the orchestration completion status attribute on the span.
* This records the final status (e.g. "Completed", "Failed") as a span attribute,
* matching the .NET SDK behavior.
*
* @param span - The orchestration span.
* @param actions - The orchestrator actions to inspect for completion status.
*/
export function setOrchestrationStatusFromActions(
span: Span | undefined | null,
actions: pb.OrchestratorAction[],
): void {
if (!span) return;

for (const action of actions) {
if (action.hasCompleteorchestration()) {
const completeAction = action.getCompleteorchestration()!;
const status = completeAction.getOrchestrationstatus();
const statusName = orchestrationStatusToString(status);
if (statusName) {
span.setAttribute(DurableTaskAttributes.TASK_STATUS, statusName);
}
break;
}
}
}

/** Maps protobuf OrchestrationStatus enum to a human-readable string. */
function orchestrationStatusToString(status: pb.OrchestrationStatus): string | undefined {
switch (status) {
case pb.OrchestrationStatus.ORCHESTRATION_STATUS_RUNNING:
return "Running";
case pb.OrchestrationStatus.ORCHESTRATION_STATUS_COMPLETED:
return "Completed";
case pb.OrchestrationStatus.ORCHESTRATION_STATUS_CONTINUED_AS_NEW:
return "ContinuedAsNew";
case pb.OrchestrationStatus.ORCHESTRATION_STATUS_FAILED:
return "Failed";
case pb.OrchestrationStatus.ORCHESTRATION_STATUS_CANCELED:
return "Canceled";
case pb.OrchestrationStatus.ORCHESTRATION_STATUS_TERMINATED:
return "Terminated";
case pb.OrchestrationStatus.ORCHESTRATION_STATUS_PENDING:
return "Pending";
case pb.OrchestrationStatus.ORCHESTRATION_STATUS_SUSPENDED:
return "Suspended";
default:
return undefined;
}
}

/**
* Creates an OrchestrationTraceContext protobuf message for the orchestrator response.
*
Expand Down Expand Up @@ -467,11 +527,13 @@ export function createOrchestrationTraceContextPb(spanInfo: OrchestrationSpanInf
* @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).
*/
export function processActionsForTracing(
orchestrationSpan: Span | undefined | null,
actions: pb.OrchestratorAction[],
orchestrationName: string,
instanceId?: string,
): void {
if (!orchestrationSpan) return;

Expand All @@ -485,7 +547,7 @@ export function processActionsForTracing(
} else if (action.hasCreatetimer()) {
const createTimer = action.getCreatetimer()!;
const fireAt = createTimer.getFireat()?.toDate() ?? new Date();
emitSpanForTimer(orchestrationSpan, orchestrationName, fireAt, action.getId());
emitSpanForTimer(orchestrationSpan, orchestrationName, fireAt, action.getId(), instanceId);
} else if (action.hasSendevent()) {
const sendEvent = action.getSendevent()!;
emitSpanForEventSent(orchestrationSpan, sendEvent.getName(), sendEvent.getInstance()?.getInstanceid());
Expand Down
5 changes: 4 additions & 1 deletion packages/durabletask-js/src/worker/task-hub-grpc-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
startSpanForTaskExecution,
processActionsForTracing,
createOrchestrationTraceContextPb,
setOrchestrationStatusFromActions,
setSpanError,
setSpanOk,
endSpan,
Expand Down Expand Up @@ -662,7 +663,7 @@ export class TaskHubGrpcWorker {
// Process actions to inject trace context into scheduled tasks, sub-orchestrations, etc.
if (tracingResult) {
const orchName = executionStartedProtoEvent?.getName() ?? "";
processActionsForTracing(tracingResult.span, result.actions, orchName);
processActionsForTracing(tracingResult.span, result.actions, orchName, instanceId);
}

res = new pb.OrchestratorResponse();
Expand All @@ -678,6 +679,8 @@ export class TaskHubGrpcWorker {
const orchTraceCtxPb = createOrchestrationTraceContextPb(tracingResult.spanInfo);
res.setOrchestrationtracecontext(orchTraceCtxPb);

// Set orchestration completion status attribute (e.g. "Completed", "Failed")
setOrchestrationStatusFromActions(tracingResult.span, result.actions);
setSpanOk(tracingResult.span);
Comment thread
torosent marked this conversation as resolved.
Outdated
}
} catch (e: unknown) {
Expand Down
Loading
Loading