Skip to content

Commit eebf084

Browse files
committed
Cleanup before_send to only apply to ErrorEvent
* also remove the Hash deprecation message
1 parent 3a07852 commit eebf084

File tree

2 files changed

+7
-48
lines changed

2 files changed

+7
-48
lines changed

sentry-ruby/lib/sentry/client.rb

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,10 @@ def send_event(event, hint = nil)
209209
data_category = Envelope::Item.data_category(event.type)
210210
spans_before = event.is_a?(TransactionEvent) ? event.spans.size : 0
211211

212-
if event.type != TransactionEvent::TYPE && configuration.before_send
212+
if event.is_a?(ErrorEvent) && configuration.before_send
213213
event = configuration.before_send.call(event, hint)
214214

215-
case event
216-
when ErrorEvent, CheckInEvent
217-
# do nothing
218-
when Hash
219-
log_debug(<<~MSG)
220-
Returning a Hash from before_send is deprecated and will be removed in the next major version.
221-
Please return a Sentry::ErrorEvent object instead.
222-
MSG
223-
else
215+
if !event.is_a?(ErrorEvent)
224216
# Avoid serializing the event object in this case because we aren't sure what it is and what it contains
225217
log_debug(<<~MSG)
226218
Discarded event because before_send didn't return a Sentry::ErrorEvent object but an instance of #{event.class}
@@ -233,18 +225,7 @@ def send_event(event, hint = nil)
233225
if event.type == TransactionEvent::TYPE && configuration.before_send_transaction
234226
event = configuration.before_send_transaction.call(event, hint)
235227

236-
if event.is_a?(TransactionEvent) || event.is_a?(Hash)
237-
spans_after = event.is_a?(TransactionEvent) ? event.spans.size : 0
238-
spans_delta = spans_before - spans_after
239-
transport.record_lost_event(:before_send, "span", num: spans_delta) if spans_delta > 0
240-
241-
if event.is_a?(Hash)
242-
log_debug(<<~MSG)
243-
Returning a Hash from before_send_transaction is deprecated and will be removed in the next major version.
244-
Please return a Sentry::TransactionEvent object instead.
245-
MSG
246-
end
247-
else
228+
if !event.is_a?(TransactionEvent)
248229
# Avoid serializing the event object in this case because we aren't sure what it is and what it contains
249230
log_debug(<<~MSG)
250231
Discarded event because before_send_transaction didn't return a Sentry::TransactionEvent object but an instance of #{event.class}
@@ -253,6 +234,10 @@ def send_event(event, hint = nil)
253234
transport.record_lost_event(:before_send, "span", num: spans_before + 1)
254235
return
255236
end
237+
238+
spans_after = event.is_a?(TransactionEvent) ? event.spans.size : 0
239+
spans_delta = spans_before - spans_after
240+
transport.record_lost_event(:before_send, "span", num: spans_delta) if spans_delta > 0
256241
end
257242

258243
transport.send_event(event) if configuration.sending_to_dsn_allowed?

sentry-ruby/spec/sentry/client/event_sending_spec.rb

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,6 @@
200200
expect(string_io.string).to include("Discarded event because before_send didn't return a Sentry::ErrorEvent object but an instance of Integer")
201201
expect(return_value).to eq(nil)
202202
end
203-
204-
it "warns about Hash value's deprecation" do
205-
string_io = StringIO.new
206-
logger = Logger.new(string_io, level: :debug)
207-
configuration.sdk_logger = logger
208-
configuration.before_send = lambda do |_event, _hint|
209-
{ foo: "bar" }
210-
end
211-
212-
return_value = client.send_event(event)
213-
expect(string_io.string).to include("Returning a Hash from before_send is deprecated and will be removed in the next major version.")
214-
expect(return_value).to eq({ foo: "bar" })
215-
end
216203
end
217204

218205
it_behaves_like "Event in send_event" do
@@ -254,19 +241,6 @@
254241
expect(string_io.string).to include("Discarded event because before_send_transaction didn't return a Sentry::TransactionEvent object but an instance of NilClass")
255242
expect(return_value).to be_nil
256243
end
257-
258-
it "warns about Hash value's deprecation" do
259-
string_io = StringIO.new
260-
logger = Logger.new(string_io, level: :debug)
261-
configuration.sdk_logger = logger
262-
configuration.before_send_transaction = lambda do |_event, _hint|
263-
{ foo: "bar" }
264-
end
265-
266-
return_value = client.send_event(event)
267-
expect(string_io.string).to include("Returning a Hash from before_send_transaction is deprecated and will be removed in the next major version.")
268-
expect(return_value).to eq({ foo: "bar" })
269-
end
270244
end
271245

272246
it_behaves_like "TransactionEvent in send_event" do

0 commit comments

Comments
 (0)