Skip to content

Commit a7427aa

Browse files
committed
Correct type declaration for events
Normal events shouldn't have the `type` field. Only transactions should have `type: "transaction"`. But in the logs, we should still print normal events' type as `"event"`. For more information about the rules, please see https://github.com/getsentry/sentry-ruby/pull/1336/files#r596851969
1 parent 5e4be7c commit a7427aa

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

sentry-rails/spec/sentry/send_event_job_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
expect(transport.events.count).to eq(1)
5858
event = transport.events.first
59-
expect(event.type).to eq("event")
59+
expect(event.type).to eq(nil)
6060
end
6161

6262
context "when ApplicationJob is not defined" do

sentry-ruby/lib/sentry/client.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def event_from_transaction(transaction)
7272
def send_event(event, hint = nil)
7373
event_type = event.is_a?(Event) ? event.type : event["type"]
7474

75-
if event_type == "event" && configuration.before_send
75+
if event_type != TransactionEvent::TYPE && configuration.before_send
7676
event = configuration.before_send.call(event, hint)
7777

7878
if event.nil?
@@ -85,8 +85,9 @@ def send_event(event, hint = nil)
8585

8686
event
8787
rescue => e
88-
logger.error(LOGGER_PROGNAME) { "#{event_type.capitalize} sending failed: #{e.message}" }
89-
logger.error(LOGGER_PROGNAME) { "Unreported #{event_type.capitalize}: #{Event.get_log_message(event.to_hash)}" }
88+
loggable_event_type = (event_type || "event").capitalize
89+
logger.error(LOGGER_PROGNAME) { "#{loggable_event_type} sending failed: #{e.message}" }
90+
logger.error(LOGGER_PROGNAME) { "Unreported #{loggable_event_type}: #{Event.get_log_message(event.to_hash)}" }
9091
raise
9192
end
9293

@@ -110,8 +111,8 @@ def dispatch_async_event(async_block, event, hint)
110111
async_block.call(event_hash)
111112
end
112113
rescue => e
113-
event_type = event_hash["type"]
114-
logger.error(LOGGER_PROGNAME) { "Async #{event_type} sending failed: #{e.message}" }
114+
loggable_event_type = event_hash["type"] || "event"
115+
logger.error(LOGGER_PROGNAME) { "Async #{loggable_event_type} sending failed: #{e.message}" }
115116
send_event(event, hint)
116117
end
117118

sentry-ruby/lib/sentry/event.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ def rack_env=(env)
100100
end
101101

102102
def type
103-
"event"
104103
end
105104

106105
def to_hash

sentry-ruby/lib/sentry/transaction_event.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
module Sentry
44
class TransactionEvent < Event
5+
TYPE = "transaction"
6+
57
ATTRIBUTES = %i(
68
event_id level timestamp start_timestamp
79
release environment server_name modules
@@ -17,7 +19,7 @@ def start_timestamp=(time)
1719
end
1820

1921
def type
20-
"transaction"
22+
TYPE
2123
end
2224

2325
def to_hash

0 commit comments

Comments
 (0)