Skip to content

Commit

Permalink
Missing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ericallam committed Jan 13, 2025
1 parent c8678f7 commit e0c6a33
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 6 deletions.
6 changes: 4 additions & 2 deletions packages/cli-v3/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,10 @@ function adaptResolveEnvVarsToSyncEnvVarsExtension(
function getInstrumentedPackageNames(config: ResolvedConfig): Array<string> {
const packageNames = [];

if (config.instrumentations) {
for (const instrumentation of config.instrumentations) {
if (config.instrumentations ?? config.telemetry?.instrumentations) {
for (const instrumentation of config.telemetry?.instrumentations ??
config.instrumentations ??
[]) {
const moduleDefinitions = (
instrumentation as any
).getModuleDefinitions?.() as Array<InstrumentationModuleDefinition>;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/v3/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Instrumentation } from "@opentelemetry/instrumentation";
import type { SpanExporter } from "@opentelemetry/sdk-trace-base";
import type { BuildExtension } from "./build/extensions.js";
import type { MachinePresetName } from "./schemas/common.js";
import type { LogLevel } from "./logger/taskLogger.js";
Expand Down
49 changes: 49 additions & 0 deletions packages/core/src/v3/otel/tracingSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import {
BatchSpanProcessor,
NodeTracerProvider,
ReadableSpan,
SimpleSpanProcessor,
SpanExporter,
} from "@opentelemetry/sdk-trace-node";
Expand Down Expand Up @@ -112,6 +113,8 @@ export class TracingSDK {
.merge(
new Resource({
[SemanticResourceAttributes.CLOUD_PROVIDER]: "trigger.dev",
[SemanticResourceAttributes.SERVICE_NAME]:
getEnvVar("OTEL_SERVICE_NAME") ?? "trigger.dev",
[SemanticInternalAttributes.TRIGGER]: true,
[SemanticInternalAttributes.CLI_VERSION]: VERSION,
})
Expand Down Expand Up @@ -256,3 +259,49 @@ function setLogLevel(level: TracingDiagnosticLogLevel) {

diag.setLogger(new DiagConsoleLogger(), diagLogLevel);
}

class ExternalSpanExporterWrapper {
constructor(
private underlyingExporter: SpanExporter,
private externalTraceId: string
) {}

private transformSpan(span: ReadableSpan): ReadableSpan | undefined {
if (span.attributes[SemanticInternalAttributes.SPAN_PARTIAL]) {
// Skip partial spans
return;
}

const spanContext = span.spanContext();

return {
...span,
spanContext: () => ({ ...spanContext, traceId: this.externalTraceId }),
parentSpanId: span.attributes[SemanticInternalAttributes.SPAN_ATTEMPT]
? undefined
: span.parentSpanId,
};
}

export(spans: any[], resultCallback: (result: any) => void): void {
try {
const modifiedSpans = spans.map(this.transformSpan.bind(this));
this.underlyingExporter.export(
modifiedSpans.filter(Boolean) as ReadableSpan[],
resultCallback
);
} catch (e) {
console.error(e);
}
}

shutdown(): Promise<void> {
return this.underlyingExporter.shutdown();
}

forceFlush?(): Promise<void> {
return this.underlyingExporter.forceFlush
? this.underlyingExporter.forceFlush()
: Promise.resolve();
}
}
1 change: 1 addition & 0 deletions packages/core/src/v3/semanticInternalAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ export const SemanticInternalAttributes = {
RATE_LIMIT_LIMIT: "response.rateLimit.limit",
RATE_LIMIT_REMAINING: "response.rateLimit.remaining",
RATE_LIMIT_RESET: "response.rateLimit.reset",
SPAN_ATTEMPT: "$span.attempt",
};
1 change: 1 addition & 0 deletions packages/core/src/v3/workers/taskExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export class TaskExecutor {
kind: SpanKind.CONSUMER,
attributes: {
[SemanticInternalAttributes.STYLE_ICON]: "attempt",
[SemanticInternalAttributes.SPAN_ATTEMPT]: true,
},
},
this._tracer.extractContext(traceContext),
Expand Down
121 changes: 117 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions references/nextjs-realtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@ai-sdk/openai": "^1.0.1",
"@fal-ai/serverless-client": "^0.15.0",
"@fast-csv/parse": "^5.0.2",
"@opentelemetry/exporter-trace-otlp-http": "^0.57.0",
"@radix-ui/react-dialog": "^1.0.3",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-progress": "^1.1.1",
Expand Down

0 comments on commit e0c6a33

Please sign in to comment.