Skip to content

add_event_processor inside with_scope accumulates processors across events #2891

@seriousdev-gh

Description

@seriousdev-gh

Issue Description

When using Sentry.with_scope, adding an event processor via scope.add_event_processor appears to affect subsequent events as well. As a result, processors accumulate over time and are executed multiple times for each event.

This is unexpected because with_scope suggests that modifications to the scope should only apply within the block.

In practice, when add_event_processor is used inside with_scope (for example inside an exception handler), each invocation adds another processor that remains active for future events.

Reproduction Steps

2.times do
  Sentry.with_scope do |scope|
    scope.add_event_processor do |event, hint|
      puts "processor called"
      event
    end

    Sentry.capture_message("test")
  end
end

Expected output

processor called
processor called

Actual output

processor called
processor called
processor called

Expected Behavior

An event processor added inside Sentry.with_scope should apply only to the event captured within that block.

Actual Behavior

Each call to scope.add_event_processor adds a processor that persists and runs for future events, causing the number of processor executions to grow over time.

Ruby Version

3.3.2

SDK Version

5.21.0

Integration and Its Version

No response

Sentry Config

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions