Skip to content

Commit 51af5a6

Browse files
committed
Remove hash based event logic
1 parent 9696cf4 commit 51af5a6

File tree

7 files changed

+12
-63
lines changed

7 files changed

+12
-63
lines changed

sentry-ruby/lib/sentry/client.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ def capture_event(event, scope, hint = {})
5353
return
5454
end
5555

56-
event_type = event.is_a?(Event) ? event.type : event["type"]
57-
data_category = Envelope::Item.data_category(event_type)
56+
data_category = Envelope::Item.data_category(event.type)
5857
event = scope.apply_to_event(event, hint)
5958

6059
if event.nil?
@@ -164,10 +163,9 @@ def event_from_transaction(transaction)
164163

165164
# @!macro send_event
166165
def send_event(event, hint = nil)
167-
event_type = event.is_a?(Event) ? event.type : event["type"]
168-
data_category = Envelope::Item.data_category(event_type)
166+
data_category = Envelope::Item.data_category(event.type)
169167

170-
if event_type != TransactionEvent::TYPE && configuration.before_send
168+
if event.type != TransactionEvent::TYPE && configuration.before_send
171169
event = configuration.before_send.call(event, hint)
172170

173171
if event.nil?
@@ -177,7 +175,7 @@ def send_event(event, hint = nil)
177175
end
178176
end
179177

180-
if event_type == TransactionEvent::TYPE && configuration.before_send_transaction
178+
if event.type == TransactionEvent::TYPE && configuration.before_send_transaction
181179
event = configuration.before_send_transaction.call(event, hint)
182180

183181
if event.nil?

sentry-ruby/lib/sentry/transport.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,7 @@ def envelope_from_event(event)
127127
sent_at: Sentry.utc_now.iso8601
128128
}
129129

130-
if event.is_a?(Event) && event.dynamic_sampling_context
131-
envelope_headers[:trace] = event.dynamic_sampling_context
132-
end
133-
130+
envelope_headers[:trace] = event.dynamic_sampling_context if event.dynamic_sampling_context
134131
envelope = Envelope.new(envelope_headers)
135132

136133
envelope.add_item(

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

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,12 @@
129129

130130
it "applies before_send callback before sending the event" do
131131
configuration.before_send = lambda do |event, _hint|
132-
if event.is_a?(Sentry::Event)
133-
event.tags[:called] = true
134-
else
135-
event["tags"]["called"] = true
136-
end
137-
132+
event.tags[:called] = true
138133
event
139134
end
140135

141136
subject.send_event(event)
142-
143-
if event.is_a?(Sentry::Event)
144-
expect(event.tags[:called]).to eq(true)
145-
else
146-
expect(event["tags"]["called"]).to eq(true)
147-
end
137+
expect(event.tags[:called]).to eq(true)
148138
end
149139

150140
it "doesn't apply before_send_transaction to Event" do
@@ -161,10 +151,6 @@
161151
let(:event) { event_object }
162152
end
163153

164-
it_behaves_like "Event in send_event" do
165-
let(:event) { event_object.to_json_compatible }
166-
end
167-
168154
shared_examples "TransactionEvent in send_event" do
169155
it "sends data through the transport" do
170156
subject.send_event(event)
@@ -180,32 +166,18 @@
180166

181167
it "applies before_send_transaction callback before sending the event" do
182168
configuration.before_send_transaction = lambda do |event, _hint|
183-
if event.is_a?(Sentry::TransactionEvent)
184-
event.tags[:called] = true
185-
else
186-
event["tags"]["called"] = true
187-
end
188-
169+
event.tags[:called] = true
189170
event
190171
end
191172

192173
subject.send_event(event)
193-
194-
if event.is_a?(Sentry::Event)
195-
expect(event.tags[:called]).to eq(true)
196-
else
197-
expect(event["tags"]["called"]).to eq(true)
198-
end
174+
expect(event.tags[:called]).to eq(true)
199175
end
200176
end
201177

202178
it_behaves_like "TransactionEvent in send_event" do
203179
let(:event) { transaction_event_object }
204180
end
205-
206-
it_behaves_like "TransactionEvent in send_event" do
207-
let(:event) { transaction_event_object.to_json_compatible }
208-
end
209181
end
210182

211183
describe "integrated error handling testing with HTTPTransport" do

sentry-ruby/spec/sentry/transport/http_transport_rate_limiting_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
let(:configuration) { Sentry.configuration }
1515
let(:client) { Sentry.get_current_client }
1616
let(:data) do
17-
subject.envelope_from_event(client.event_from_message("foobarbaz").to_hash).to_s
17+
subject.envelope_from_event(client.event_from_message("foobarbaz")).to_s
1818
end
1919

2020
subject { Sentry::HTTPTransport.new(configuration) }

sentry-ruby/spec/sentry/transport/http_transport_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
let(:event) { client.event_from_message("foobarbaz") }
1515
let(:fake_time) { Time.now }
1616
let(:data) do
17-
subject.serialize_envelope(subject.envelope_from_event(event.to_hash)).first
17+
subject.serialize_envelope(subject.envelope_from_event(event)).first
1818
end
1919

2020
subject { client.transport }

sentry-ruby/spec/sentry/transport/spotlight_transport_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
let(:client) { Sentry::Client.new(configuration) }
1919
let(:event) { client.event_from_message("foobarbaz") }
2020
let(:data) do
21-
subject.serialize_envelope(subject.envelope_from_event(event.to_hash)).first
21+
subject.serialize_envelope(subject.envelope_from_event(event)).first
2222
end
2323

2424
subject { described_class.new(configuration) }

sentry-ruby/spec/sentry/transport_spec.rb

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -387,18 +387,6 @@
387387
expect(io.string).to match(/Sending envelope with items \[event\]/)
388388
end
389389

390-
context "when the event hash has string keys" do
391-
let(:envelope) { subject.envelope_from_event(event.to_json_compatible) }
392-
393-
it "deletes the event's breadcrumbs and sends it" do
394-
expect(subject).to receive(:send_data)
395-
396-
subject.send_envelope(envelope)
397-
398-
expect(io.string).to match(/Sending envelope with items \[event\]/)
399-
end
400-
end
401-
402390
context "if it's still oversized" do
403391
before do
404392
1000.times do |i|
@@ -450,12 +438,6 @@
450438
expect(subject.send_event(event)).to eq(event)
451439
end
452440

453-
it "sends Event hash" do
454-
expect(subject).not_to receive(:failed_send)
455-
456-
expect(subject.send_event(event.to_json_compatible)).to eq(event.to_json_compatible)
457-
end
458-
459441
it "logs correct message" do
460442
expect(subject.send_event(event)).to eq(event)
461443

0 commit comments

Comments
 (0)