Skip to content

Global event processors do not clear on Sentry.init #2051

@andrewharrisatcheckr

Description

@andrewharrisatcheckr

Issue Description

Hello! In working recently with sentry-ruby, a colleague and I found that the recently added global event processors from #1974 don't seem to clear on invocation of Sentry.init. This is a bit unexpected, considering the overall action of Sentry.init to reset other options.

If this is the intended behavior and simply could use a documentation note, then please feel free to close this issue report.

Reproduction Steps

  1. Sentry.init to get started
  2. Sentry.add_global_event_processor
  3. Sentry.init to reset state
  4. Sentry.add_global_event_processor
  5. Examine Sentry::Scope.global_event_processors.length or similar

For example:

Gemfile

# frozen_string_literal: true

source 'https://rubygems.org'

gem 'rspec'
gem 'rubocop'
gem 'sentry-ruby', '~> 5.9'

spec/sentry_ruby_spec.rb

# frozen_string_literal: true

require 'rspec'
require 'sentry-ruby'

describe Sentry do
  it 'flushes global event processors on .init' do
    # Setup - init and set one global event processor
    Sentry.init
    Sentry.add_global_event_processor do |event, _hint|
      event.tags = { foo: 42 }
      event
    end
    expect(Sentry::Scope.global_event_processors.length).to eq(1)

    # When - init and set another global event processor
    Sentry.init
    Sentry.add_global_event_processor do |event, _hint|
      event.tags = { foo: 42 }
      event
    end

    # Then there should be one global event processor.
    expect(Sentry::Scope.global_event_processors.length).to eq(1)
    # However, this fails: length is 2, because Sentry.init retains global event processors.
  end
end

Expected Behavior

Sentry::Scope.global_event_processors.length shows one configured global event processor.

Actual Behavior

Sentry::Scope.global_event_processors.length shows two configured global event processors.

Ruby Version

3.2.2

SDK Version

5.9.0

Integration and Its Version

Non-specific

Sentry Config

None needed. Works with sentry-ruby defaults.

Metadata

Metadata

Assignees

Labels

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions