Skip to content

Commit 791e359

Browse files
committed
feat(supervisor): forward traceparent + request_id to compute
1 parent 4a53cab commit 791e359

4 files changed

Lines changed: 44 additions & 0 deletions

File tree

.server-changes/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ Speed up batch queue processing by removing stalls and fixing retry race
3838

3939
The body text (below the frontmatter) is a one-line description of the change. Keep it concise — it will appear in release notes.
4040

41+
### Writing guidance
42+
43+
These entries are public-facing - they ship verbatim in user-visible release notes. A few rules to keep them clean:
44+
45+
- **One sentence is usually enough.** The body is the bullet in the changelog. If you need a paragraph, you're probably describing the implementation rather than the change.
46+
- **Describe behavior, not implementation.** Skip internal scopes, middleware names, library specifics, framework internals. Users care about what's different for them, not how it's wired.
47+
- **Never name internal tools or infra.** Observability stacks, internal services, infra components, monitoring backends, CI surfaces, AWS specifics - none of these belong in user-facing notes.
48+
4149
## Lifecycle
4250

4351
1. Engineer adds a `.server-changes/` file in their PR
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: supervisor
3+
type: improvement
4+
---
5+
6+
Forward `traceparent` headers on outbound calls to the compute provider so distributed traces stay continuous across services.

apps/supervisor/src/workloadManager/compute.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ComputeClient, stripImageDigest } from "@internal/compute";
1010
import { extractTraceparent, getRunnerId } from "../util.js";
1111
import type { OtlpTraceService } from "../services/otlpTraceService.js";
1212
import { tryCatch } from "@trigger.dev/core";
13+
import { fromContext } from "../wideEvents/index.js";
1314

1415
type ComputeWorkloadManagerOptions = WorkloadManagerOptions & {
1516
gateway: {
@@ -46,6 +47,20 @@ export class ComputeWorkloadManager implements WorkloadManager {
4647
gatewayUrl: opts.gateway.url,
4748
authToken: opts.gateway.authToken,
4849
timeoutMs: opts.gateway.timeoutMs,
50+
// Forward the current wide-event scope's traceparent + request_id so the
51+
// downstream service continues the same trace and joins its own wide
52+
// events to ours. When called outside a wide-event scope (or when wide
53+
// events are disabled), `fromContext` returns undefined and propagation
54+
// is skipped.
55+
getPropagationHeaders: () => {
56+
const state = fromContext();
57+
if (!state) return {};
58+
const headers: Record<string, string> = { "x-request-id": state.requestId };
59+
if (state.traceparent) {
60+
headers.traceparent = state.traceparent;
61+
}
62+
return headers;
63+
},
4964
});
5065
}
5166

internal-packages/compute/src/client.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ export type ComputeClientOptions = {
1111
gatewayUrl: string;
1212
authToken?: string;
1313
timeoutMs: number;
14+
/**
15+
* Called once per outbound request to collect cross-service correlation
16+
* headers (e.g. `traceparent`, `x-request-id`) from the caller's current
17+
* scope. The returned record is merged onto the outbound headers. Return
18+
* `{}` (or omit the option) to skip propagation.
19+
*/
20+
getPropagationHeaders?: () => Record<string, string>;
1421
};
1522

1623
export class ComputeClient {
@@ -40,6 +47,14 @@ class HttpTransport {
4047
if (this.opts.authToken) {
4148
h["Authorization"] = `Bearer ${this.opts.authToken}`;
4249
}
50+
const propagation = this.opts.getPropagationHeaders?.();
51+
if (propagation) {
52+
for (const [key, value] of Object.entries(propagation)) {
53+
if (value) {
54+
h[key] = value;
55+
}
56+
}
57+
}
4358
return h;
4459
}
4560

0 commit comments

Comments
 (0)