@@ -11,9 +11,10 @@ const ParamsSchema = z.object({
11
11
} ) ;
12
12
13
13
export const HeadersSchema = z . object ( {
14
- "idempotency-key" : z . string ( ) . optional ( ) . nullable ( ) ,
15
- "trigger-version" : z . string ( ) . optional ( ) . nullable ( ) ,
16
- "x-trigger-span-parent-as-link" : z . coerce . number ( ) . optional ( ) . nullable ( ) ,
14
+ "idempotency-key" : z . string ( ) . nullish ( ) ,
15
+ "trigger-version" : z . string ( ) . nullish ( ) ,
16
+ "x-trigger-span-parent-as-link" : z . coerce . number ( ) . nullish ( ) ,
17
+ "x-trigger-worker" : z . string ( ) . nullish ( ) ,
17
18
traceparent : z . string ( ) . optional ( ) ,
18
19
tracestate : z . string ( ) . optional ( ) ,
19
20
} ) ;
@@ -45,6 +46,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
45
46
"x-trigger-span-parent-as-link" : spanParentAsLink ,
46
47
traceparent,
47
48
tracestate,
49
+ "x-trigger-worker" : isFromWorker ,
48
50
} = headers . data ;
49
51
50
52
const { taskId } = ParamsSchema . parse ( params ) ;
@@ -58,20 +60,31 @@ export async function action({ request, params }: ActionFunctionArgs) {
58
60
return json ( { error : "Invalid request body" } , { status : 400 } ) ;
59
61
}
60
62
61
- logger . debug ( "Triggering task" , {
62
- taskId,
63
- idempotencyKey,
64
- triggerVersion,
65
- body : body . data ,
66
- } ) ;
67
-
68
63
const service = new TriggerTaskService ( ) ;
69
64
70
65
try {
66
+ const traceContext = traceparent
67
+ ? ! triggerVersion // If the trigger version is NOT set, we are in an older version of the SDK
68
+ ? { traceparent, tracestate }
69
+ : isFromWorker // If the trigger version is set, and the request is from a worker, we should pass the trace context
70
+ ? { traceparent, tracestate }
71
+ : undefined
72
+ : undefined ;
73
+
74
+ logger . debug ( "Triggering task" , {
75
+ taskId,
76
+ idempotencyKey,
77
+ triggerVersion,
78
+ headers : Object . fromEntries ( request . headers ) ,
79
+ body : body . data ,
80
+ isFromWorker,
81
+ traceContext,
82
+ } ) ;
83
+
71
84
const run = await service . call ( taskId , authenticationResult . environment , body . data , {
72
85
idempotencyKey : idempotencyKey ?? undefined ,
73
86
triggerVersion : triggerVersion ?? undefined ,
74
- traceContext : traceparent ? { traceparent , tracestate } : undefined ,
87
+ traceContext,
75
88
spanParentAsLink : spanParentAsLink === 1 ,
76
89
} ) ;
77
90
0 commit comments