[Heartbeat] Pass synthetics monitor context for APM cross-linking#51083
[Heartbeat] Pass synthetics monitor context for APM cross-linking#51083shahzad31 wants to merge 3 commits into
Conversation
Inject the monitor id, type, location and per-execution trace id as ELASTIC_SYNTHETICS_* environment variables when spawning the @elastic/synthetics runner, so its APM plugin can cross-link synthetics journey executions with the traced application's APM data. Relates to elastic/synthetics#595 Co-authored-by: Cursor <cursoragent@cursor.com>
|
This pull request doesn't have a |
🤖 GitHub commentsJust comment with:
|
|
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
Set monitor.check_group in the state plugins' BeforeEachEvent (before the synthetics process is spawned) and read it back in synthexec so the injected ELASTIC_SYNTHETICS_TRACE_ID equals the published monitor.check_group (including the attempt suffix). Falls back to the stream enricher's check group when run outside the summarizer. Co-authored-by: Cursor <cursoragent@cursor.com>
Beats lints with --whole-files, so touching a file surfaces all of its pre-existing issues. Address the ones dragged in by this PR: - synthexec.go: route the package's global-logger access through a single synthexecLog() helper so logp.L() (forbidigo) isn't referenced throughout; threading a *logp.Logger through the synthetics job factory is out of scope. - plugstatestat.go: suppress the two pre-existing logp.L() usages. - Move the new BeforeEachEvent check_group test into plugstatestat_test.go so summarizer_test.go is no longer modified and doesn't inherit its lint debt. - synthexec_test.go: use require.Empty, fix expected/actual order, and suppress gosec/noctx on the existing go-toolchain test helper. Co-authored-by: Cursor <cursoragent@cursor.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthrough
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 does this PR do?
When Heartbeat spawns the
@elastic/syntheticsrunner forbrowser/apimonitors, it now injects the monitor execution context as environment variables so the synthetics runner's APM plugin can cross-link a journey execution with the APM data of the application it traces:ELASTIC_SYNTHETICS_TRACE_ID— themonitor.check_groupof the current attemptELASTIC_SYNTHETICS_MONITOR_ID—stdfields.IDELASTIC_SYNTHETICS_MONITOR_TYPE—stdfields.Type(browser/api)ELASTIC_SYNTHETICS_MONITOR_LOCATION—stdfields.RunFrom.IDOnly non-empty values are emitted so the synthetics agent can fall back to its own defaults.
Trace id == check_group
The trace id must equal the
monitor.check_grouppublished on the heartbeat documents so APM data can be joined back to the exact journey execution.monitor.check_groupis owned by the summarizer (formatted as<uuid>-<attempt>) and was previously only written after the job ran. This PR sets it in the state plugins'BeforeEachEvent(before the synthetics process is spawned), andsynthexecreads it off the event to use as the trace id. This keeps the two identical, including across retries (the root job re-runs with the bumped attempt). When run outside the summarizer (e.g. unit tests), it falls back to the synthexec stream enricher's own check group.This is the Heartbeat side of the Synthetics ⇄ APM cross-linking effort and the counterpart to elastic/synthetics#595.
Why is it important?
It lets the Synthetics waterfall be correlated with APM traces of the monitored application, enabling end-to-end performance analysis across Elastic Observability. See elastic/apm#823.
Scope / follow-ups (intentionally out of this PR)
apm.traceUrlsis configured (see feat: support cross-linking synthetics & apm synthetics#595); enabling it from Heartbeat is a follow-up.Checklist
TestSyntheticsCrosslinkEnv)TestCheckGroupFromEvent)monitor.check_groupearly (TestStateStatusPluginBeforeEachEventSetsCheckGroup)How to test this PR locally
Related issues