@@ -7,6 +7,7 @@ class Transport
77 USER_AGENT = "sentry-ruby/#{ Sentry ::VERSION } "
88
99 attr_accessor :configuration
10+ attr_reader :rate_limits
1011
1112 def initialize ( configuration )
1213 @configuration = configuration
@@ -20,12 +21,24 @@ def send_data(data, options = {})
2021 end
2122
2223 def send_event ( event )
24+ event_hash = event . to_hash
25+ item_type = get_item_type ( event_hash )
26+
2327 unless configuration . sending_allowed?
24- configuration . logger . debug ( LOGGER_PROGNAME ) { "Event not sent: #{ configuration . error_messages } " }
28+ configuration . logger . debug ( LOGGER_PROGNAME ) do
29+ "Envelope [#{ item_type } ] not sent: #{ configuration . error_messages } "
30+ end
31+
2532 return
2633 end
2734
28- return if is_rate_limited? ( event )
35+ if is_rate_limited? ( item_type )
36+ configuration . logger . info ( LOGGER_PROGNAME ) do
37+ "Envelope [#{ item_type } ] not sent: rate limiting"
38+ end
39+
40+ return
41+ end
2942
3043 encoded_data = encode ( event )
3144
@@ -36,18 +49,14 @@ def send_event(event)
3649 event
3750 end
3851
39- def is_rate_limited? ( event )
40- event_hash = event . to_hash
41- event_type = event_hash [ :type ] || event_hash [ 'type' ]
42-
52+ def is_rate_limited? ( item_type )
4353 # check category-specific limit
4454 delay =
45- case event_type
46- when "event"
47- # confusing mapping, but it's decided by Sentry
48- @rate_limits [ "error" ]
55+ case item_type
4956 when "transaction"
5057 @rate_limits [ "transaction" ]
58+ else
59+ @rate_limits [ "error" ]
5160 end
5261
5362 # check universal limit if not category limit
@@ -73,7 +82,7 @@ def encode(event)
7382 event_hash = event . to_hash
7483
7584 event_id = event_hash [ :event_id ] || event_hash [ "event_id" ]
76- item_type = event_hash [ :type ] || event_hash [ "type" ] || "event"
85+ item_type = get_item_type ( event_hash )
7786
7887 envelope = <<~ENVELOPE
7988 {"event_id":"#{ event_id } ","dsn":"#{ configuration . dsn . to_s } ","sdk":#{ Sentry . sdk_meta . to_json } ,"sent_at":"#{ Sentry . utc_now . iso8601 } "}
@@ -85,6 +94,12 @@ def encode(event)
8594
8695 envelope
8796 end
97+
98+ private
99+
100+ def get_item_type ( event_hash )
101+ event_hash [ :type ] || event_hash [ "type" ] || "event"
102+ end
88103 end
89104end
90105
0 commit comments