Skip to content

Commit 7c5ac9b

Browse files
committed
add support to prod v4 and v3 runs
1 parent 1616bf4 commit 7c5ac9b

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

apps/webapp/app/v3/marqs/sharedQueueConsumer.server.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
TaskRunSuccessfulExecutionResult,
2323
parsePacket,
2424
serverWebsocketMessages,
25+
SemanticInternalAttributes,
2526
} from "@trigger.dev/core/v3";
2627
import { ZodMessageSender } from "@trigger.dev/core/v3/zodMessageHandler";
2728
import {
@@ -1648,6 +1649,7 @@ export const AttemptForExecutionGetPayload = {
16481649
baseCostInCents: true,
16491650
maxDurationInSeconds: true,
16501651
tags: true,
1652+
taskEventStore: true,
16511653
},
16521654
},
16531655
queue: {
@@ -1880,7 +1882,8 @@ class SharedQueueTasks {
18801882
const variables = await this.#buildEnvironmentVariables(
18811883
attempt.runtimeEnvironment,
18821884
taskRun.id,
1883-
machinePreset
1885+
machinePreset,
1886+
taskRun.taskEventStore ?? undefined
18841887
);
18851888

18861889
const payload: V3ProdTaskRunExecutionPayload = {
@@ -2049,6 +2052,7 @@ class SharedQueueTasks {
20492052
},
20502053
},
20512054
machinePreset: true,
2055+
taskEventStore: true,
20522056
},
20532057
});
20542058

@@ -2071,7 +2075,12 @@ class SharedQueueTasks {
20712075
const machinePreset =
20722076
machinePresetFromRun(run) ?? machinePresetFromConfig(run.lockedBy?.machineConfig ?? {});
20732077

2074-
const variables = await this.#buildEnvironmentVariables(environment, run.id, machinePreset);
2078+
const variables = await this.#buildEnvironmentVariables(
2079+
environment,
2080+
run.id,
2081+
machinePreset,
2082+
run.taskEventStore ?? undefined
2083+
);
20752084

20762085
return {
20772086
traceContext: run.traceContext as Record<string, unknown>,
@@ -2178,7 +2187,8 @@ class SharedQueueTasks {
21782187
async #buildEnvironmentVariables(
21792188
environment: RuntimeEnvironmentForEnvRepo,
21802189
runId: string,
2181-
machinePreset: MachinePreset
2190+
machinePreset: MachinePreset,
2191+
taskEventStore?: string
21822192
): Promise<Array<EnvironmentVariable>> {
21832193
const variables = await resolveVariablesForEnvironment(environment);
21842194

@@ -2187,6 +2197,14 @@ class SharedQueueTasks {
21872197
machine_preset: machinePreset.name,
21882198
});
21892199

2200+
if (taskEventStore) {
2201+
const resourceAttributes = JSON.stringify({
2202+
[SemanticInternalAttributes.TASK_EVENT_STORE]: taskEventStore,
2203+
});
2204+
2205+
variables.push(...[{ key: "OTEL_RESOURCE_ATTRIBUTES", value: resourceAttributes }]);
2206+
}
2207+
21902208
return [
21912209
...variables,
21922210
...[

apps/webapp/app/v3/services/worker/workerGroupTokenService.server.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
DequeuedMessage,
66
ExecutionResult,
77
MachinePreset,
8+
SemanticInternalAttributes,
89
StartRunAttemptResult,
910
TaskRunExecutionResult,
1011
} from "@trigger.dev/core/v3";
@@ -444,7 +445,8 @@ export class AuthenticatedWorkerInstance extends WithRunEngine {
444445
environment,
445446
engineResult.run.id,
446447
engineResult.execution.machine ?? defaultMachinePreset,
447-
environment.parentEnvironment ?? undefined
448+
environment.parentEnvironment ?? undefined,
449+
engineResult.run.taskEventStore ?? undefined
448450
)
449451
: {};
450452

@@ -544,7 +546,8 @@ export class AuthenticatedWorkerInstance extends WithRunEngine {
544546
environment: RuntimeEnvironment,
545547
runId: string,
546548
machinePreset: MachinePreset,
547-
parentEnvironment?: RuntimeEnvironment
549+
parentEnvironment?: RuntimeEnvironment,
550+
taskEventStore?: string
548551
): Promise<Record<string, string>> {
549552
const variables = await resolveVariablesForEnvironment(environment, parentEnvironment);
550553

@@ -561,6 +564,19 @@ export class AuthenticatedWorkerInstance extends WithRunEngine {
561564
]
562565
);
563566

567+
if (taskEventStore) {
568+
const resourceAttributes = JSON.stringify({
569+
[SemanticInternalAttributes.TASK_EVENT_STORE]: taskEventStore,
570+
});
571+
572+
variables.push(
573+
...[
574+
{ key: "OTEL_RESOURCE_ATTRIBUTES", value: resourceAttributes },
575+
{ key: "TRIGGER_OTEL_RESOURCE_ATTRIBUTES", value: resourceAttributes },
576+
]
577+
);
578+
}
579+
564580
return variables.reduce((acc: Record<string, string>, curr) => {
565581
acc[curr.key] = curr.value;
566582
return acc;

0 commit comments

Comments
 (0)