Skip to content

feat!: add scope merging mechanism - #1373

Open
giortzisg wants to merge 1 commit into
scopes/scope-storagefrom
scopes/scope-merge
Open

feat!: add scope merging mechanism#1373
giortzisg wants to merge 1 commit into
scopes/scope-storagefrom
scopes/scope-merge

Conversation

@giortzisg

@giortzisg giortzisg commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Description

This adds the scope merging mechanism by allocating a captureState object 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. The EventModifier was an agnostic modifier that was passed on ApplyToEvent. This duplicated the EventProcessor behavior and also complicated the scope merging mechanism, since we need to have a concrete *Scope type to merge the scopes. Furthermore, there is no documented behavior or signature for any EventModifier and this seems to be just the first archaic way to modify events before EventProcessor and BeforeSend hooks where a thing. Thus decided to remove this and have a concrete *Scope passed on ApplyToEvent. This behavior aligns with other sdks that pass a concrete scope.

This affects the public API with all the CaptureX methods now requiring a concrete scope to be passed, but further scope changes in the stack also change the CaptureX APIs to work with context.Context, so this change seems acceptable. Functionality isn't really removed but just shifted to BeforeSend hooks as intended.

Issues

Changelog Entry Instructions

To add a custom changelog entry, uncomment the section above. Supports:

  • Single entry: just write text
  • Multiple entries: use bullet points
  • Nested bullets: indent 4+ spaces

For more details: custom changelog entries

Reminders

@linear-code

linear-code Bot commented Jul 23, 2026

Copy link
Copy Markdown

GO-155

@giortzisg
giortzisg force-pushed the scopes/scope-merge branch from 8f6a8b4 to e509cb6 Compare July 23, 2026 08:45
@giortzisg
giortzisg marked this pull request as ready for review July 23, 2026 08:51
Comment thread scope.go Outdated
@giortzisg
giortzisg force-pushed the scopes/scope-merge branch from e509cb6 to 5ea0d02 Compare July 30, 2026 20:45
@giortzisg
giortzisg force-pushed the scopes/scope-merge branch from 5ea0d02 to 2905cce Compare August 4, 2026 15:25
Comment thread scope.go Outdated
@giortzisg
giortzisg force-pushed the scopes/scope-merge branch 2 times, most recently from 8b46a73 to b3bd79f Compare August 5, 2026 09:59
Comment thread scope.go Outdated
@giortzisg
giortzisg force-pushed the scopes/scope-merge branch 2 times, most recently from a32be8d to af060b8 Compare August 12, 2026 12:11
Comment thread scope.go
Comment thread scope.go Outdated
Comment thread scope.go Outdated
Comment thread scope.go Outdated
Comment thread scope.go Outdated
Comment thread metrics.go Outdated
Comment thread client.go Outdated
Comment thread scope.go Outdated
Comment thread scope.go Outdated
@giortzisg giortzisg changed the title feat: add scope merging mechanism feat!: add scope merging mechanism Sep 1, 2026
Comment thread client.go

@szokeasaurusrex szokeasaurusrex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Admittedly only skimmed this, as the PR is quite huge, but I left a few questions

Comment thread internal/sentrytest/fixture.go
Comment thread client.go Outdated
Comment thread client.go
Comment thread log.go
Comment thread internal/util/map.go Outdated
Comment on lines +5 to +6
// FillMap copies keys from src that are absent in dst. It allocates dst when
// needed and never aliases src.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: Please document the precedence between dst and src if both contain the same key with different corresponding values.

Comment thread scope.go Outdated
Comment on lines +618 to +622
type signalCaptureContext struct {
scope *Scope
ctx context.Context
fallback context.Context
defaultAttributes map[string]attribute.Value

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: Please document what this is, including documentation for the individual fields, because it is a bit unclear why we need this.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread scope_merge.go Outdated
Comment thread scope.go

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread scope.go
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.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread scope.go
traceIDContextKey: traceID.String(),
spanIDContextKey: spanID.String(),
})
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 5d18fe6. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add scope merging for global and isolation scopes

2 participants