Skip to content

Commit fc392b1

Browse files
authored
feat: source worker.id telemetry from the deployment friendlyId (#78)
* feat(supervisor,cli): source worker.id telemetry from the deployment friendlyId The runner stamps the OTel worker.id from TRIGGER_DEPLOYMENT_ID, which the supervisor may set to an opaque token. Have the supervisor also pass the plain friendlyId in TRIGGER_DEPLOYMENT_FRIENDLY_ID, and have the runner prefer it for the telemetry worker.id (falling back to TRIGGER_DEPLOYMENT_ID for older supervisors). The auth header keeps using TRIGGER_DEPLOYMENT_ID unchanged. New deploys then report a stable deployment id in telemetry with no decode - including to customers' own external exporters. Refs TRI-11974 * fix(cli): redact TRIGGER_DEPLOYMENT_ID from managed run debug logs
1 parent dcc4b40 commit fc392b1

8 files changed

Lines changed: 31 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Deployed task telemetry now reports the deployment identifier (e.g. `deployment_abc123`) in the `worker.id` attribute, instead of an opaque internal value. Upgrade to get the readable identifier in your own OpenTelemetry exporters.

apps/supervisor/src/workloadManager/compute.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ export class ComputeWorkloadManager implements WorkloadManager {
152152
TRIGGER_POD_SCHEDULED_AT_MS: String(Date.now()),
153153
TRIGGER_ENV_ID: opts.envId,
154154
TRIGGER_DEPLOYMENT_ID: opts.deploymentToken ?? opts.deploymentFriendlyId,
155+
// Plain friendlyId for telemetry (worker.id), so it isn't the opaque token in DEPLOYMENT_ID.
156+
TRIGGER_DEPLOYMENT_FRIENDLY_ID: opts.deploymentFriendlyId,
155157
TRIGGER_DEPLOYMENT_VERSION: opts.deploymentVersion,
156158
TRIGGER_RUN_ID: opts.runFriendlyId,
157159
TRIGGER_SNAPSHOT_ID: opts.snapshotFriendlyId,

apps/supervisor/src/workloadManager/docker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ export class DockerWorkloadManager implements WorkloadManager {
7373
`TRIGGER_POD_SCHEDULED_AT_MS=${Date.now()}`,
7474
`TRIGGER_ENV_ID=${opts.envId}`,
7575
`TRIGGER_DEPLOYMENT_ID=${opts.deploymentToken ?? opts.deploymentFriendlyId}`,
76+
// Plain friendlyId for telemetry (worker.id), so it isn't the opaque token in DEPLOYMENT_ID.
77+
`TRIGGER_DEPLOYMENT_FRIENDLY_ID=${opts.deploymentFriendlyId}`,
7678
`TRIGGER_DEPLOYMENT_VERSION=${opts.deploymentVersion}`,
7779
`TRIGGER_RUN_ID=${opts.runFriendlyId}`,
7880
`TRIGGER_SNAPSHOT_ID=${opts.snapshotFriendlyId}`,

apps/supervisor/src/workloadManager/kubernetes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ export class KubernetesWorkloadManager implements WorkloadManager {
160160
name: "TRIGGER_DEPLOYMENT_ID",
161161
value: opts.deploymentToken ?? opts.deploymentFriendlyId,
162162
},
163+
{
164+
// Plain friendlyId for telemetry (worker.id), not the opaque token in DEPLOYMENT_ID.
165+
name: "TRIGGER_DEPLOYMENT_FRIENDLY_ID",
166+
value: opts.deploymentFriendlyId,
167+
},
163168
{
164169
name: "TRIGGER_DEPLOYMENT_VERSION",
165170
value: opts.deploymentVersion,

packages/cli-v3/src/entryPoints/managed/controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class ManagedRunController {
7676
});
7777

7878
const properties = {
79-
...env.raw,
79+
...env.rawForLogging,
8080
TRIGGER_POD_SCHEDULED_AT_MS: env.TRIGGER_POD_SCHEDULED_AT_MS.toISOString(),
8181
TRIGGER_DEQUEUED_AT_MS: env.TRIGGER_DEQUEUED_AT_MS.toISOString(),
8282
};

packages/cli-v3/src/entryPoints/managed/env.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ const Env = z.object({
2727

2828
// Set at runtime
2929
TRIGGER_DEPLOYMENT_ID: z.string(),
30+
// Plain deployment friendlyId for telemetry. Optional: older supervisors don't set it, in which
31+
// case we fall back to TRIGGER_DEPLOYMENT_ID.
32+
TRIGGER_DEPLOYMENT_FRIENDLY_ID: z.string().optional(),
3033
TRIGGER_DEPLOYMENT_VERSION: z.string(),
3134
TRIGGER_WORKLOAD_CONTROLLER_ID: z.string().default(`controller_${randomUUID()}`),
3235
TRIGGER_ENV_ID: z.string(),
@@ -74,6 +77,11 @@ export class RunnerEnv {
7477
return this.env;
7578
}
7679

80+
// TRIGGER_DEPLOYMENT_ID carries the deployment token; redact it before logging.
81+
get rawForLogging() {
82+
return { ...this.env, TRIGGER_DEPLOYMENT_ID: "[redacted]" };
83+
}
84+
7785
// Base environment variables
7886
get NODE_ENV() {
7987
return this.env.NODE_ENV;
@@ -93,6 +101,9 @@ export class RunnerEnv {
93101
get TRIGGER_DEPLOYMENT_ID() {
94102
return this.env.TRIGGER_DEPLOYMENT_ID;
95103
}
104+
get TRIGGER_DEPLOYMENT_FRIENDLY_ID() {
105+
return this.env.TRIGGER_DEPLOYMENT_FRIENDLY_ID;
106+
}
96107
get TRIGGER_DEPLOYMENT_VERSION() {
97108
return this.env.TRIGGER_DEPLOYMENT_VERSION;
98109
}

packages/cli-v3/src/entryPoints/managed/execution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ export class RunExecution {
951951

952952
this.sendDebugLog(`[override] processing: ${reason}`, {
953953
overrides,
954-
currentEnv: this.env.raw,
954+
currentEnv: this.env.rawForLogging,
955955
});
956956

957957
// Override the env with the new values

packages/cli-v3/src/entryPoints/managed/taskRunProcessProvider.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,14 @@ export class TaskRunProcessProvider {
252252
workerManifest: this.workerManifest,
253253
env: processEnv,
254254
serverWorker: {
255-
id: this.env.TRIGGER_DEPLOYMENT_ID,
255+
// Telemetry-only (becomes OTel worker.id). Prefer the plain friendlyId; fall back to
256+
// DEPLOYMENT_ID (which may be an opaque token) only when an older supervisor didn't set it.
257+
id: this.env.TRIGGER_DEPLOYMENT_FRIENDLY_ID ?? this.env.TRIGGER_DEPLOYMENT_ID,
256258
contentHash: this.env.TRIGGER_CONTENT_HASH,
257259
version: this.env.TRIGGER_DEPLOYMENT_VERSION,
258260
engine: "V2",
259261
},
262+
260263
machineResources: {
261264
cpu: Number(this.env.TRIGGER_MACHINE_CPU),
262265
memory: Number(this.env.TRIGGER_MACHINE_MEMORY),

0 commit comments

Comments
 (0)