Skip to content

Commit 5e4be7c

Browse files
committed
Correct Transport's encoding logging
1 parent 351c64e commit 5e4be7c

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

sentry-ruby/lib/sentry/transport.rb

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def send_event(event)
2424
return
2525
end
2626

27-
encoded_data = prepare_encoded_event(event)
27+
encoded_data = encode(event)
2828

2929
return nil unless encoded_data
3030

@@ -45,29 +45,22 @@ def generate_auth_header
4545
'Sentry ' + fields.map { |key, value| "#{key}=#{value}" }.join(', ')
4646
end
4747

48-
def encode(event_hash)
49-
event_id = event_hash[:event_id] || event_hash['event_id']
50-
event_type = event_hash[:type] || event_hash['type']
48+
def encode(event)
49+
# Convert to hash
50+
event_hash = event.to_hash
51+
52+
event_id = event_hash[:event_id] || event_hash["event_id"]
53+
envelope_type = event_hash[:type] || event_hash["type"] || "event"
5154

5255
envelope = <<~ENVELOPE
5356
{"event_id":"#{event_id}","dsn":"#{configuration.dsn.to_s}","sdk":#{Sentry.sdk_meta.to_json},"sent_at":"#{Sentry.utc_now.iso8601}"}
54-
{"type":"#{event_type}","content_type":"application/json"}
57+
{"type":"#{envelope_type}","content_type":"application/json"}
5558
#{JSON.generate(event_hash)}
5659
ENVELOPE
5760

58-
envelope
59-
end
60-
61-
private
62-
63-
def prepare_encoded_event(event)
64-
# Convert to hash
65-
event_hash = event.to_hash
61+
configuration.logger.info(LOGGER_PROGNAME) { "Sending envelope [#{envelope_type}] #{event_id} to Sentry" }
6662

67-
event_id = event_hash[:event_id] || event_hash["event_id"]
68-
event_type = event_hash[:type] || event_hash["type"]
69-
configuration.logger.info(LOGGER_PROGNAME) { "Sending #{event_type} #{event_id} to Sentry" }
70-
encode(event_hash)
63+
envelope
7164
end
7265
end
7366
end

sentry-ruby/spec/sentry/rake_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
message = `cd spec/support && bundle exec rake raise_exception 2>&1`
1111
end.join
1212

13-
expect(message).to match(/Sending event [abcdef0-9]+ to Sentry/)
13+
expect(message).to match(/Sending envelope \[event\] [abcdef0-9]+ to Sentry/)
1414
end
1515
end

sentry-ruby/spec/sentry/transport_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
expect(subject.send_event(event)).to eq(event)
116116

117117
expect(io.string).to match(
118-
/INFO -- sentry: Sending event #{event.event_id} to Sentry/
118+
/INFO -- sentry: Sending envelope \[event\] #{event.event_id} to Sentry/
119119
)
120120
end
121121
end

0 commit comments

Comments
 (0)