Skip to content

Commit

Permalink
Add client reports for span drop counts
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Jul 19, 2024
1 parent 36866c5 commit a7e0c34
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
16 changes: 15 additions & 1 deletion sentry-ruby/lib/sentry/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,20 @@ def capture_event(event, scope, hint = {})

event_type = event.is_a?(Event) ? event.type : event["type"]
data_category = Envelope::Item.data_category(event_type)

is_transaction = event.is_a?(TransactionEvent)
spans_before = is_transaction ? event.spans.size : 0

event = scope.apply_to_event(event, hint)

if event.nil?
log_debug("Discarded event because one of the event processors returned nil")
transport.record_lost_event(:event_processor, data_category)
transport.record_lost_event(:event_processor, 'span', num: spans_before + 1) if is_transaction
return
elsif is_transaction
spans_delta = spans_before - event.spans.size
transport.record_lost_event(:before_send, data_category, num: spans_delta) if spans_delta > 0
end

if async_block = configuration.async
Expand Down Expand Up @@ -180,12 +188,18 @@ def send_event(event, hint = nil)
end

if event_type == TransactionEvent::TYPE && configuration.before_send_transaction
spans_before = event.is_a?(TransactionEvent) ? event.spans.size : 0
event = configuration.before_send_transaction.call(event, hint)

if event.nil?
log_debug("Discarded event because before_send_transaction returned nil")
transport.record_lost_event(:before_send, data_category)
transport.record_lost_event(:before_send, 'transaction')
transport.record_lost_event(:before_send, 'span', num: spans_before + 1)
return
else
spans_after = event.is_a?(TransactionEvent) ? event.spans.size : 0
spans_delta = spans_before - spans_after
transport.record_lost_event(:before_send, data_category, num: spans_delta) if spans_delta > 0
end
end

Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/envelope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def type
# rate limits and client reports use the data_category rather than envelope item type
def self.data_category(type)
case type
when 'session', 'attachment', 'transaction', 'profile' then type
when 'session', 'attachment', 'transaction', 'profile', 'span' then type
when 'sessions' then 'session'
when 'check_in' then 'monitor'
when 'statsd', 'metric_meta' then 'metric_bucket'
Expand Down
1 change: 1 addition & 0 deletions sentry-ruby/lib/sentry/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def finish(hub: nil, end_timestamp: nil)
is_backpressure = Sentry.backpressure_monitor&.downsample_factor&.positive?
reason = is_backpressure ? :backpressure : :sample_rate
hub.current_client.transport.record_lost_event(reason, 'transaction')
hub.current_client.transport.record_lost_event(reason, 'span')
end
end

Expand Down
4 changes: 2 additions & 2 deletions sentry-ruby/lib/sentry/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ def envelope_from_event(event)
envelope
end

def record_lost_event(reason, data_category)
def record_lost_event(reason, data_category, num: 1)
return unless @send_client_reports
return unless CLIENT_REPORT_REASONS.include?(reason)

@discarded_events[[reason, data_category]] += 1
@discarded_events[[reason, data_category]] += num
end

def flush
Expand Down

0 comments on commit a7e0c34

Please sign in to comment.