Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions packages/cli-v3/src/entryPoints/dev-run-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ async function doBootstrap() {
instrumentations: config.telemetry?.instrumentations ?? config.instrumentations ?? [],
exporters: config.telemetry?.exporters ?? [],
logExporters: config.telemetry?.logExporters ?? [],
spanProcessors : config.telemetry?.spanProcessors ?? [],
diagLogLevel: (env.TRIGGER_OTEL_LOG_LEVEL as TracingDiagnosticLogLevel) ?? "none",
forceFlushTimeoutMillis: 30_000,
resource: config.telemetry?.resource,
Expand Down
1 change: 1 addition & 0 deletions packages/cli-v3/src/entryPoints/managed-run-worker.ts

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 managed-run-worker doesn't check telemetry.instrumentations (pre-existing inconsistency)

In dev-run-worker.ts:207, instrumentations are resolved with config.telemetry?.instrumentations ?? config.instrumentations ?? [], properly supporting both the new telemetry.instrumentations path and the deprecated top-level instrumentations field.

However, managed-run-worker.ts:186 only uses config.instrumentations ?? [], ignoring config.telemetry?.instrumentations entirely. This means users who configure instrumentations under the telemetry key (as the deprecation notice on config.ts:86-87 suggests) will have them silently ignored in managed/production runs while working fine in dev. This is a pre-existing issue not introduced by this PR, but the PR author may want to fix it alongside this change for consistency.

(Refers to line 186)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ async function doBootstrap() {
forceFlushTimeoutMillis: 30_000,
exporters: config.telemetry?.exporters ?? [],
logExporters: config.telemetry?.logExporters ?? [],
spanProcessors: config.telemetry?.spanProcessors ?? [],
resource: config.telemetry?.resource,
});

Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/v3/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Instrumentation } from "@opentelemetry/instrumentation";
import type { SpanExporter } from "@opentelemetry/sdk-trace-base";
import type { SpanExporter, SpanProcessor } from "@opentelemetry/sdk-trace-base";
import type { BuildExtension } from "./build/extensions.js";
import type {
AnyOnFailureHookFunction,
Expand Down Expand Up @@ -95,6 +95,12 @@ export type TriggerConfig = {
*/
instrumentations?: Array<Instrumentation>;

/**
* Span processors to use for OpenTelemetry. This is useful if you want to add custom span processors to your tasks.
* There are executed in the order passed before running exporters
*/
spanProcessors?: Array<SpanProcessor>;

/**
* Exporters to use for OpenTelemetry. This is useful if you want to add custom exporters to your tasks.
*
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/v3/otel/tracingSDK.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Context,
DiagConsoleLogger,
DiagLogLevel,
TraceFlags,
Expand Down Expand Up @@ -66,6 +67,7 @@ export type TracingSDKConfig = {
url: string;
forceFlushTimeoutMillis?: number;
instrumentations?: Instrumentation[];
spanProcessors?: SpanProcessor[];
exporters?: SpanExporter[];
logExporters?: LogRecordExporter[];
diagLogLevel?: TracingDiagnosticLogLevel;
Expand Down Expand Up @@ -120,6 +122,11 @@ export class TracingSDK {

const spanProcessors: Array<SpanProcessor> = [];

//add span processor passed via config before adding exporters
for (const spanProcessor of config.spanProcessors ?? []) {
spanProcessors.push(spanProcessor);
}
Comment on lines +125 to +128

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 Custom span processors' onStart won't see task context attributes

Custom span processors are pushed into the array before TaskContextSpanProcessor at packages/core/src/v3/otel/tracingSDK.ts:130-148. The NodeTracerProvider calls each processor's onStart in order, so custom processors' onStart will execute before TaskContextSpanProcessor.onStart adds task context metadata attributes (see packages/core/src/v3/taskContext/otelProcessors.ts:18-31 where span.setAttributes(...) is called).

However, since attributes are mutated on the shared span object, custom processors' onEnd will see the task context attributes (they were already set during the onStart phase). This is likely acceptable for most use cases (the PR's example LogSpanProcessor only logs in onStart and doesn't read attributes), but users writing processors that need task context in onStart would be surprised. The comment on line 125 says this ordering is intentional.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.


spanProcessors.push(
new TaskContextSpanProcessor(
VERSION,
Expand Down