fix: restore metrics after waitpoint resume#3840
Conversation
🦋 Changeset detectedLatest commit: 1477ad3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 25 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Hi @RitwijParmar, thanks for your interest in contributing! This project requires that pull request authors are vouched, and you are not in the list of vouched users. This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
WalkthroughThis PR restores run metric attribution after waitpoint resume by implementing task context re-enablement. A new ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What changed
Closes #3672.
This restores run-level metric attribution after a task resumes from a waitpoint:
taskContext.enable()as the explicit inverse oftaskContext.disable()RESOLVE_WAITPOINThandlers before resolving runtime waitpointsRUN_ID,TASK_SLUG,ATTEMPT_NUMBER, run tags, and worker attrs@trigger.dev/coreandtrigger.devWhy
FLUSH { disableContext: true }is used at waitpoints to mark the process as between active run execution. In a warm process,setGlobalTaskContext()is not called again when the same run resumes, so_runDisabledcan stay true for the rest of the run. The periodic metric exporter then keeps stripping run-specific attributes, making post-waitpoint CPU/memory/heap metrics hard to query by run.Re-enabling the task context at waitpoint resolution keeps the existing between-run stripping behavior while restoring attribution when user code resumes.
Validation
bun test packages/core/src/v3/taskContext/index.test.ts packages/core/src/v3/taskContext/otelProcessors.test.ts— 8 passedbunx prettier --check .changeset/waitpoint-metric-attribution.md packages/core/src/v3/taskContext/index.ts packages/core/src/v3/taskContext/index.test.ts packages/core/src/v3/taskContext/otelProcessors.test.ts packages/cli-v3/src/entryPoints/managed-run-worker.ts packages/cli-v3/src/entryPoints/dev-run-worker.tsgit diff --checkI also ran package typechecks, but this local checkout reports existing unrelated workspace/setup errors, including missing generated workspace package types for
@trigger.dev/database/@trigger.dev/schema-to-jsonand pre-existingassertExhaustive(...string)errors. The new test file type errors found on the first run were fixed, and the focused tests pass.