-
Notifications
You must be signed in to change notification settings - Fork 262
Auto-inject workflow run/step ID VQS headers from queue payload #1098
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@workflow/world-vercel': patch | ||
| '@workflow/core': patch | ||
| --- | ||
|
|
||
| Auto-inject `x-workflow-run-id` and `x-workflow-step-id` VQS headers from queue payload in `world-vercel` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,28 @@ const MAX_DELAY_SECONDS = Number( | |
| process.env.VERCEL_QUEUE_MAX_DELAY_SECONDS || 82800 // 23 hours - leave 1h buffer before 24h retention limit | ||
| ); | ||
|
|
||
| /** | ||
| * Extract known identifiers from a queue payload and return them as VQS headers. | ||
| * This ensures observability headers are always set without relying on callers. | ||
| */ | ||
| function getHeadersFromPayload( | ||
| payload: QueuePayload | ||
| ): Record<string, string> | undefined { | ||
| const headers: Record<string, string> = {}; | ||
|
|
||
| if ('runId' in payload && typeof payload.runId === 'string') { | ||
| headers['x-workflow-run-id'] = payload.runId; | ||
| } | ||
| if ('workflowRunId' in payload && typeof payload.workflowRunId === 'string') { | ||
| headers['x-workflow-run-id'] = payload.workflowRunId; | ||
| } | ||
| if ('stepId' in payload && typeof payload.stepId === 'string') { | ||
| headers['x-workflow-step-id'] = payload.stepId; | ||
| } | ||
|
|
||
| return Object.keys(headers).length > 0 ? headers : undefined; | ||
| } | ||
|
|
||
| type QueueFunction = ( | ||
| queueName: ValidQueueName, | ||
| payload: QueuePayload, | ||
|
|
@@ -114,7 +136,10 @@ export function createQueue(config?: APIConfig): Queue { | |
| { | ||
| idempotencyKey: opts?.idempotencyKey, | ||
| delaySeconds: opts?.delaySeconds, | ||
| headers: opts?.headers, | ||
| headers: { | ||
| ...getHeadersFromPayload(payload), | ||
| ...opts?.headers, | ||
| }, | ||
|
Comment on lines
136
to
+142
|
||
| } | ||
| ); | ||
| return { messageId: MessageId.parse(messageId) }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getHeadersFromPayloadcan setx-workflow-run-idtwice (fromrunIdandworkflowRunId), with the latter overwriting the former. BecauseQueuePayloadSchemais a union of non-strict objects (unknown keys are stripped), a payload object containing both keys can be encoded/parsed as a workflow payload with onlyrunId, while the header ends up reflectingworkflowRunId, creating an observability mismatch. Consider deriving headers from the same sanitized/encoded payload you actually send (or explicitly choosing precedence withif/else if, and potentially warning when both are present).