Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## Unreleased

### Bug Fixes

- Accept Hash in `before_send*` callbacks again ([#2529](https://github.com/getsentry/sentry-ruby/pull/2529))
- Fixes [#2526](https://github.com/getsentry/sentry-ruby/issues/2526)

## 5.22.2

### Features
Expand All @@ -6,7 +13,7 @@
- Use attempt_threshold to skip reporting on first N attempts ([#2503](https://github.com/getsentry/sentry-ruby/pull/2503))
- Support `code.namespace` for Ruby 3.4+ stacktraces ([#2506](https://github.com/getsentry/sentry-ruby/pull/2506))

### Bug fixes
### Bug Fixes

- Default to `internal_error` error type for OpenTelemetry spans [#2473](https://github.com/getsentry/sentry-ruby/pull/2473)
- Improve `before_send` and `before_send_transaction`'s return value handling ([#2504](https://github.com/getsentry/sentry-ruby/pull/2504))
Expand Down
19 changes: 17 additions & 2 deletions sentry-ruby/lib/sentry/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,15 @@
if event_type != TransactionEvent::TYPE && configuration.before_send
event = configuration.before_send.call(event, hint)

unless event.is_a?(ErrorEvent)
case event

Check warning on line 186 in sentry-ruby/lib/sentry/client.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/client.rb#L186

Added line #L186 was not covered by tests
when ErrorEvent
# do nothing
when Hash
log_debug(<<~MSG)

Check warning on line 190 in sentry-ruby/lib/sentry/client.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/client.rb#L190

Added line #L190 was not covered by tests
Returning a Hash from before_send is deprecated and will be removed in the next major version.
Please return a Sentry::ErrorEvent object instead.
MSG
else
# Avoid serializing the event object in this case because we aren't sure what it is and what it contains
log_debug(<<~MSG)
Discarded event because before_send didn't return a Sentry::ErrorEvent object but an instance of #{event.class}
Expand All @@ -196,10 +204,17 @@
if event_type == TransactionEvent::TYPE && configuration.before_send_transaction
event = configuration.before_send_transaction.call(event, hint)

if event.is_a?(TransactionEvent)
if event.is_a?(TransactionEvent) || event.is_a?(Hash)

Check warning on line 207 in sentry-ruby/lib/sentry/client.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/client.rb#L207

Added line #L207 was not covered by tests
spans_after = event.is_a?(TransactionEvent) ? event.spans.size : 0
spans_delta = spans_before - spans_after
transport.record_lost_event(:before_send, "span", num: spans_delta) if spans_delta > 0

if event.is_a?(Hash)
log_debug(<<~MSG)

Check warning on line 213 in sentry-ruby/lib/sentry/client.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/client.rb#L212-L213

Added lines #L212 - L213 were not covered by tests
Returning a Hash from before_send_transaction is deprecated and will be removed in the next major version.
Please return a Sentry::TransactionEvent object instead.
MSG
end
else
# Avoid serializing the event object in this case because we aren't sure what it is and what it contains
log_debug(<<~MSG)
Expand Down
32 changes: 30 additions & 2 deletions sentry-ruby/spec/sentry/client/event_sending_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,22 @@
123
end

client.send_event(event)
return_value = client.send_event(event)
expect(string_io.string).to include("Discarded event because before_send didn't return a Sentry::ErrorEvent object but an instance of Integer")
expect(return_value).to eq(nil)
end

it "warns about Hash value's deprecation" do
string_io = StringIO.new
logger = Logger.new(string_io, level: :debug)
configuration.logger = logger
configuration.before_send = lambda do |_event, _hint|
{ foo: "bar" }
end

return_value = client.send_event(event)
expect(string_io.string).to include("Returning a Hash from before_send is deprecated and will be removed in the next major version.")
expect(return_value).to eq({ foo: "bar" })
end
end

Expand Down Expand Up @@ -323,8 +337,22 @@
nil
end

client.send_event(event)
return_value = client.send_event(event)
expect(string_io.string).to include("Discarded event because before_send_transaction didn't return a Sentry::TransactionEvent object but an instance of NilClass")
expect(return_value).to be_nil
end

it "warns about Hash value's deprecation" do
string_io = StringIO.new
logger = Logger.new(string_io, level: :debug)
configuration.logger = logger
configuration.before_send_transaction = lambda do |_event, _hint|
{ foo: "bar" }
end

return_value = client.send_event(event)
expect(string_io.string).to include("Returning a Hash from before_send_transaction is deprecated and will be removed in the next major version.")
expect(return_value).to eq({ foo: "bar" })
end
end

Expand Down
Loading