Method: Sentry::Client#send_event

Defined in:
lib/sentry/client.rb

#send_event(event, hint = nil) ⇒ Event

Sends the event to Sentry.

Parameters:

  • event (Event)

    the event to be sent.

  • hint (Hash) (defaults to: nil)

    the hint data that’ll be passed to before_send callback.

Returns:



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/sentry/client.rb', line 239

def send_event(event, hint = nil)
  data_category = Envelope::Item.data_category(event.type)
  spans_before = event.is_a?(TransactionEvent) ? event.spans.size : 0

  if event.is_a?(ErrorEvent) && configuration.before_send
    event = configuration.before_send.call(event, hint)

    if !event.is_a?(ErrorEvent)
      # Avoid serializing the event object in this case because we aren't sure what it is and what it contains
      log_debug(<<~MSG)
        Discarded event because before_send didn't return a Sentry::ErrorEvent object but an instance of #{event.class}
      MSG
      transport.record_lost_event(:before_send, data_category)
      return
    end
  end

  if event.is_a?(TransactionEvent) && configuration.before_send_transaction
    event = configuration.before_send_transaction.call(event, hint)

    if !event.is_a?(TransactionEvent)
      # Avoid serializing the event object in this case because we aren't sure what it is and what it contains
      log_debug(<<~MSG)
        Discarded event because before_send_transaction didn't return a Sentry::TransactionEvent object but an instance of #{event.class}
      MSG
      transport.record_lost_event(:before_send, "transaction")
      transport.record_lost_event(:before_send, "span", num: spans_before + 1)
      return
    end

    spans_after = event.is_a?(TransactionEvent) ? event.spans.size : 0
    spans_delta = spans_before - spans_after
    transport.record_lost_event(:before_send, "span", num: spans_delta) if spans_delta > 0
  end

  if event.is_a?(CheckInEvent) && configuration.before_send_check_in
    event = configuration.before_send_check_in.call(event, hint)

    if !event.is_a?(CheckInEvent)
      # Avoid serializing the event object in this case because we aren't sure what it is and what it contains
      log_debug(<<~MSG)
        Discarded event because before_send_check_in didn't return a Sentry::CheckInEvent object but an instance of #{event.class}
      MSG
      transport.record_lost_event(:before_send, data_category)
      return
    end
  end

  transport.send_event(event) if configuration.sending_to_dsn_allowed?
  spotlight_transport.send_event(event) if spotlight_transport

  event
rescue => e
  log_error("Event sending failed", e, debug: configuration.debug)
  transport.record_lost_event(:network_error, data_category)
  transport.record_lost_event(:network_error, "span", num: spans_before + 1) if event.is_a?(TransactionEvent)
  raise
end