feat!: add scope merging mechanism - #1373
Conversation
8f6a8b4 to
e509cb6
Compare
e509cb6 to
5ea0d02
Compare
5ea0d02 to
2905cce
Compare
8b46a73 to
b3bd79f
Compare
b3bd79f to
5ab473f
Compare
5ab473f to
a27e5e5
Compare
a32be8d to
af060b8
Compare
5146682 to
80b661b
Compare
80b661b to
f1ba13c
Compare
bf26935 to
ec3c9a6
Compare
ec3c9a6 to
503b67b
Compare
503b67b to
24d5a46
Compare
szokeasaurusrex
left a comment
There was a problem hiding this comment.
Admittedly only skimmed this, as the PR is quite huge, but I left a few questions
24d5a46 to
ff67282
Compare
ff67282 to
c7f455b
Compare
| // FillMap copies keys from src that are absent in dst. It allocates dst when | ||
| // needed and never aliases src. |
There was a problem hiding this comment.
m: Please document the precedence between dst and src if both contain the same key with different corresponding values.
| type signalCaptureContext struct { | ||
| scope *Scope | ||
| ctx context.Context | ||
| fallback context.Context | ||
| defaultAttributes map[string]attribute.Value |
There was a problem hiding this comment.
l: Please document what this is, including documentation for the individual fields, because it is a bit unclear why we need this.
c7f455b to
a7e13ce
Compare
a7e13ce to
f1cf3a9
Compare
f1cf3a9 to
ffd5441
Compare
Apply the single scope selected by the capture context directly to events, preserve event precedence, enforce breadcrumb limits, and run request processing and event processors after releasing the scope lock. BREAKING CHANGE: Event values take precedence over scope values during capture, context scopes replace the global scope, and scope breadcrumbs and attachments are applied before event-specific values.
ffd5441 to
5d18fe6
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5d18fe6. Configure here.
| traceIDContextKey: traceID.String(), | ||
| spanIDContextKey: spanID.String(), | ||
| }) | ||
| return |
There was a problem hiding this comment.
External traces drop sampling context
Medium Severity
When an external trace resolver succeeds, applyTraceToEvent replaces the event trace context with only trace_id and span_id and returns. That drops Dynamic Sampling Context and other trace fields that were previously kept from the span or propagation context after only the IDs were overwritten.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 5d18fe6. Configure here.


Description
This adds the scope merging mechanism by allocating a
captureStateobject and copying all needed event attributes in place. This removes taking multiple scope clones on every capture.The PR also includes breaking changes around
EventModifier. TheEventModifierwas an agnostic modifier that was passed onApplyToEvent. This duplicated the EventProcessor behavior and also complicated the scope merging mechanism, since we need to have a concrete*Scopetype to merge the scopes. Furthermore, there is no documented behavior or signature for anyEventModifierand this seems to be just the first archaic way to modify events beforeEventProcessorandBeforeSendhooks where a thing. Thus decided to remove this and have a concrete*Scopepassed onApplyToEvent. This behavior aligns with other sdks that pass a concrete scope.This affects the public API with all the
CaptureXmethods now requiring a concrete scope to be passed, but further scope changes in the stack also change theCaptureXAPIs to work withcontext.Context, so this change seems acceptable. Functionality isn't really removed but just shifted toBeforeSendhooks as intended.Issues
Changelog Entry Instructions
To add a custom changelog entry, uncomment the section above. Supports:
For more details: custom changelog entries
Reminders
feat:,fix:,ref:,meta:)