|
| 1 | +--- |
| 2 | +"@trigger.dev/sdk": patch |
| 3 | +--- |
| 4 | + |
| 5 | +External Trace Correlation & OpenTelemetry Package Updates. |
| 6 | + |
| 7 | +| Package | Previous Version | New Version | Change Type | |
| 8 | +|---------|------------------|-------------|-------------| |
| 9 | +| `@opentelemetry/api` | 1.9.0 | 1.9.0 | No change (stable API) | |
| 10 | +| `@opentelemetry/api-logs` | 0.52.1 | 0.203.0 | Major update | |
| 11 | +| `@opentelemetry/core` | - | 2.0.1 | New dependency | |
| 12 | +| `@opentelemetry/exporter-logs-otlp-http` | 0.52.1 | 0.203.0 | Major update | |
| 13 | +| `@opentelemetry/exporter-trace-otlp-http` | 0.52.1 | 0.203.0 | Major update | |
| 14 | +| `@opentelemetry/instrumentation` | 0.52.1 | 0.203.0 | Major update | |
| 15 | +| `@opentelemetry/instrumentation-fetch` | 0.52.1 | 0.203.0 | Major update | |
| 16 | +| `@opentelemetry/resources` | 1.25.1 | 2.0.1 | Major update | |
| 17 | +| `@opentelemetry/sdk-logs` | 0.52.1 | 0.203.0 | Major update | |
| 18 | +| `@opentelemetry/sdk-node` | 0.52.1 | - | Removed (functionality consolidated) | |
| 19 | +| `@opentelemetry/sdk-trace-base` | 1.25.1 | 2.0.1 | Major update | |
| 20 | +| `@opentelemetry/sdk-trace-node` | 1.25.1 | 2.0.1 | Major update | |
| 21 | +| `@opentelemetry/semantic-conventions` | 1.25.1 | 1.36.0 | Minor update | |
| 22 | + |
| 23 | +### External trace correlation and propagation |
| 24 | + |
| 25 | +We will now correlate your external traces with trigger.dev traces and logs when using our external exporters: |
| 26 | + |
| 27 | +```ts |
| 28 | +import { defineConfig } from "@trigger.dev/sdk"; |
| 29 | +import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http"; |
| 30 | +import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http"; |
| 31 | + |
| 32 | +export default defineConfig({ |
| 33 | + project: process.env.TRIGGER_PROJECT_REF, |
| 34 | + dirs: ["./src/trigger"], |
| 35 | + telemetry: { |
| 36 | + logExporters: [ |
| 37 | + new OTLPLogExporter({ |
| 38 | + url: "https://api.axiom.co/v1/logs", |
| 39 | + headers: { |
| 40 | + Authorization: `Bearer ${process.env.AXIOM_TOKEN}`, |
| 41 | + "X-Axiom-Dataset": "test", |
| 42 | + }, |
| 43 | + }), |
| 44 | + ], |
| 45 | + exporters: [ |
| 46 | + new OTLPTraceExporter({ |
| 47 | + url: "https://api.axiom.co/v1/traces", |
| 48 | + headers: { |
| 49 | + Authorization: `Bearer ${process.env.AXIOM_TOKEN}`, |
| 50 | + "X-Axiom-Dataset": "test", |
| 51 | + }, |
| 52 | + }), |
| 53 | + ], |
| 54 | + }, |
| 55 | + maxDuration: 3600, |
| 56 | +}); |
| 57 | +``` |
| 58 | + |
| 59 | +You can also now propagate your external trace context when calling back into your own backend infra from inside a trigger.dev task: |
| 60 | + |
| 61 | +```ts |
| 62 | +import { otel, task } from "@trigger.dev/sdk"; |
| 63 | +import { context, propagation } from "@opentelemetry/api"; |
| 64 | + |
| 65 | +async function callNextjsApp() { |
| 66 | + return await otel.withExternalTrace(async () => { |
| 67 | + const headersObject = {}; |
| 68 | + |
| 69 | + // Now context.active() refers to your external trace context |
| 70 | + propagation.inject(context.active(), headersObject); |
| 71 | + |
| 72 | + const result = await fetch("http://localhost:3000/api/demo-call-from-trigger", { |
| 73 | + headers: new Headers(headersObject), |
| 74 | + method: "POST", |
| 75 | + body: JSON.stringify({ |
| 76 | + message: "Hello from Trigger.dev", |
| 77 | + }), |
| 78 | + }); |
| 79 | + |
| 80 | + return result.json(); |
| 81 | + }); |
| 82 | +} |
| 83 | + |
| 84 | +export const myTask = task({ |
| 85 | + id: "my-task", |
| 86 | + run: async (payload: any) => { |
| 87 | + await callNextjsApp() |
| 88 | + } |
| 89 | +}) |
| 90 | +``` |
| 91 | + |
| 92 | + |
0 commit comments