Skip to content

Commit e0c6a33

Browse files
committed
Missing changes
1 parent c8678f7 commit e0c6a33

File tree

7 files changed

+174
-6
lines changed

7 files changed

+174
-6
lines changed

packages/cli-v3/src/config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,10 @@ function adaptResolveEnvVarsToSyncEnvVarsExtension(
317317
function getInstrumentedPackageNames(config: ResolvedConfig): Array<string> {
318318
const packageNames = [];
319319

320-
if (config.instrumentations) {
321-
for (const instrumentation of config.instrumentations) {
320+
if (config.instrumentations ?? config.telemetry?.instrumentations) {
321+
for (const instrumentation of config.telemetry?.instrumentations ??
322+
config.instrumentations ??
323+
[]) {
322324
const moduleDefinitions = (
323325
instrumentation as any
324326
).getModuleDefinitions?.() as Array<InstrumentationModuleDefinition>;

packages/core/src/v3/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Instrumentation } from "@opentelemetry/instrumentation";
2+
import type { SpanExporter } from "@opentelemetry/sdk-trace-base";
23
import type { BuildExtension } from "./build/extensions.js";
34
import type { MachinePresetName } from "./schemas/common.js";
45
import type { LogLevel } from "./logger/taskLogger.js";

packages/core/src/v3/otel/tracingSDK.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import {
2121
BatchSpanProcessor,
2222
NodeTracerProvider,
23+
ReadableSpan,
2324
SimpleSpanProcessor,
2425
SpanExporter,
2526
} from "@opentelemetry/sdk-trace-node";
@@ -112,6 +113,8 @@ export class TracingSDK {
112113
.merge(
113114
new Resource({
114115
[SemanticResourceAttributes.CLOUD_PROVIDER]: "trigger.dev",
116+
[SemanticResourceAttributes.SERVICE_NAME]:
117+
getEnvVar("OTEL_SERVICE_NAME") ?? "trigger.dev",
115118
[SemanticInternalAttributes.TRIGGER]: true,
116119
[SemanticInternalAttributes.CLI_VERSION]: VERSION,
117120
})
@@ -256,3 +259,49 @@ function setLogLevel(level: TracingDiagnosticLogLevel) {
256259

257260
diag.setLogger(new DiagConsoleLogger(), diagLogLevel);
258261
}
262+
263+
class ExternalSpanExporterWrapper {
264+
constructor(
265+
private underlyingExporter: SpanExporter,
266+
private externalTraceId: string
267+
) {}
268+
269+
private transformSpan(span: ReadableSpan): ReadableSpan | undefined {
270+
if (span.attributes[SemanticInternalAttributes.SPAN_PARTIAL]) {
271+
// Skip partial spans
272+
return;
273+
}
274+
275+
const spanContext = span.spanContext();
276+
277+
return {
278+
...span,
279+
spanContext: () => ({ ...spanContext, traceId: this.externalTraceId }),
280+
parentSpanId: span.attributes[SemanticInternalAttributes.SPAN_ATTEMPT]
281+
? undefined
282+
: span.parentSpanId,
283+
};
284+
}
285+
286+
export(spans: any[], resultCallback: (result: any) => void): void {
287+
try {
288+
const modifiedSpans = spans.map(this.transformSpan.bind(this));
289+
this.underlyingExporter.export(
290+
modifiedSpans.filter(Boolean) as ReadableSpan[],
291+
resultCallback
292+
);
293+
} catch (e) {
294+
console.error(e);
295+
}
296+
}
297+
298+
shutdown(): Promise<void> {
299+
return this.underlyingExporter.shutdown();
300+
}
301+
302+
forceFlush?(): Promise<void> {
303+
return this.underlyingExporter.forceFlush
304+
? this.underlyingExporter.forceFlush()
305+
: Promise.resolve();
306+
}
307+
}

packages/core/src/v3/semanticInternalAttributes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ export const SemanticInternalAttributes = {
5151
RATE_LIMIT_LIMIT: "response.rateLimit.limit",
5252
RATE_LIMIT_REMAINING: "response.rateLimit.remaining",
5353
RATE_LIMIT_RESET: "response.rateLimit.reset",
54+
SPAN_ATTEMPT: "$span.attempt",
5455
};

packages/core/src/v3/workers/taskExecutor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ export class TaskExecutor {
231231
kind: SpanKind.CONSUMER,
232232
attributes: {
233233
[SemanticInternalAttributes.STYLE_ICON]: "attempt",
234+
[SemanticInternalAttributes.SPAN_ATTEMPT]: true,
234235
},
235236
},
236237
this._tracer.extractContext(traceContext),

pnpm-lock.yaml

Lines changed: 117 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

references/nextjs-realtime/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@ai-sdk/openai": "^1.0.1",
1515
"@fal-ai/serverless-client": "^0.15.0",
1616
"@fast-csv/parse": "^5.0.2",
17+
"@opentelemetry/exporter-trace-otlp-http": "^0.57.0",
1718
"@radix-ui/react-dialog": "^1.0.3",
1819
"@radix-ui/react-icons": "^1.3.0",
1920
"@radix-ui/react-progress": "^1.1.1",

0 commit comments

Comments
 (0)