Class: Sentry::Client
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
Instance Method Summary collapse
- #capture_event(event, scope, hint = {}) ⇒ Object
- #event_from_exception(exception, hint = {}) ⇒ Object
- #event_from_message(message, hint = {}) ⇒ Object
- #event_from_transaction(transaction) ⇒ Object
-
#initialize(configuration) ⇒ Client
constructor
A new instance of Client.
- #send_event(event, hint = nil) ⇒ Object
Constructor Details
#initialize(configuration) ⇒ Client
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/sentry/client.rb', line 7 def initialize(configuration) @configuration = configuration @logger = configuration.logger if transport_class = configuration.transport.transport_class @transport = transport_class.new(configuration) else @transport = case configuration.dsn&.scheme when 'http', 'https' HTTPTransport.new(configuration) else DummyTransport.new(configuration) end end end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
5 6 7 |
# File 'lib/sentry/client.rb', line 5 def configuration @configuration end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
5 6 7 |
# File 'lib/sentry/client.rb', line 5 def logger @logger end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
5 6 7 |
# File 'lib/sentry/client.rb', line 5 def transport @transport end |
Instance Method Details
#capture_event(event, scope, hint = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sentry/client.rb', line 24 def capture_event(event, scope, hint = {}) return unless configuration.sending_allowed? scope.apply_to_event(event, hint) if async_block = configuration.async dispatch_async_event(async_block, event, hint) elsif hint.fetch(:background, true) dispatch_background_event(event, hint) else send_event(event, hint) end event rescue => e logger.error(LOGGER_PROGNAME) { "Event capturing failed: #{e.message}" } nil end |
#event_from_exception(exception, hint = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/sentry/client.rb', line 43 def event_from_exception(exception, hint = {}) = Sentry.integrations[hint[:integration]] return unless @configuration.exception_class_allowed?(exception) Event.new(configuration: configuration, integration_meta: ).tap do |event| event.add_exception_interface(exception) event.add_threads_interface(crashed: true) end end |
#event_from_message(message, hint = {}) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/sentry/client.rb', line 53 def (, hint = {}) = Sentry.integrations[hint[:integration]] event = Event.new(configuration: configuration, integration_meta: , message: ) event.add_threads_interface(backtrace: caller) event end |
#event_from_transaction(transaction) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sentry/client.rb', line 60 def event_from_transaction(transaction) TransactionEvent.new(configuration: configuration).tap do |event| event.transaction = transaction.name event.contexts.merge!(trace: transaction.get_trace_context) event. = transaction. event. = transaction. finished_spans = transaction.span_recorder.spans.select { |span| span. && span != transaction } event.spans = finished_spans.map(&:to_hash) end end |
#send_event(event, hint = nil) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/sentry/client.rb', line 72 def send_event(event, hint = nil) event_type = event.is_a?(Event) ? event.type : event["type"] if event_type == "event" && configuration.before_send event = configuration.before_send.call(event, hint) if event.nil? logger.info(LOGGER_PROGNAME) { "Discarded event because before_send returned nil" } return end end transport.send_event(event) event rescue => e logger.error(LOGGER_PROGNAME) { "#{event_type.capitalize} sending failed: #{e.message}" } logger.error(LOGGER_PROGNAME) { "Unreported #{event_type.capitalize}: #{Event.get_log_message(event.to_hash)}" } raise end |