Module: Rails::Instrumentation::Utils
- Defined in:
- lib/rails/instrumentation/utils.rb
Class Method Summary collapse
-
.register_subscriber(full_name: '', event_name: '', handler_module: nil) ⇒ Object
calls a handler function with name ‘event’ on the handler module.
-
.tag_error(span, payload) ⇒ Object
according to the ActiveSupport::Notifications documentation, exceptions will be indicated with the presence of the :exception and :exception_object keys.
-
.trace_notification(event:, tags: []) ⇒ Object
takes and event and some set of tags from a handler, and creates a span with the event’s name and the start and finish times.
Class Method Details
.register_subscriber(full_name: '', event_name: '', handler_module: nil) ⇒ Object
calls a handler function with name ‘event’ on the handler module. For example, if the handler module is ActionViewSubscriber and the event hook is ‘render_template.action_controller’, full_name is ‘render_template.action_controller’ and event_name is ‘render_template’
11 12 13 14 15 16 |
# File 'lib/rails/instrumentation/utils.rb', line 11 def register_subscriber(full_name: '', event_name: '', handler_module: nil) ::ActiveSupport::Notifications.subscribe(full_name) do |*args| event = ::ActiveSupport::Notifications::Event.new(*args) handler_module.send(event_name, event) end end |
.tag_error(span, payload) ⇒ Object
according to the ActiveSupport::Notifications documentation, exceptions will be indicated with the presence of the :exception and :exception_object keys. These will be tagged and logged according to the OpenTracing specification.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rails/instrumentation/utils.rb', line 38 def tag_error(span, payload) if payload.key? :exception_object span.record_exception(payload[:exception_object]) else exception = payload[:exception] span.set_tag(:error, true) span.set_tag(:'sfx.error.kind', exception[0]) span.set_tag(:'sfx.error.message', exception[1]) end end |
.trace_notification(event:, tags: []) ⇒ Object
takes and event and some set of tags from a handler, and creates a span with the event’s name and the start and finish times.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rails/instrumentation/utils.rb', line 20 def trace_notification(event:, tags: []) = ::Rails::Instrumentation::TAGS.clone.merge() span = ::Rails::Instrumentation.tracer.start_span(event.name, tags: , start_time: event.time) # tag transaction_id span.set_tag('transaction.id', event.transaction_id) tag_error(span, event.payload) if event.payload.key? :exception span.finish(end_time: event.end) end |