Class: OpenTelemetry::Instrumentation::Grape::EventHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/instrumentation/grape/event_handler.rb

Overview

Handles the events instrumented with ActiveSupport notifications. These handlers contain all the logic needed to create and connect spans.

Class Method Summary collapse

Class Method Details

.endpoint_render(_name, start, _finish, _id, payload) ⇒ Object

Handles the endpoint_render event, recording it as a span event



29
30
31
32
33
34
# File 'lib/opentelemetry/instrumentation/grape/event_handler.rb', line 29

def endpoint_render(_name, start, _finish, _id, payload)
  span = OpenTelemetry::Instrumentation::Rack.current_span
  return unless span.recording?

  span.add_event('grape.endpoint_render', timestamp: start)
end

.endpoint_run(_name, start, _finish, _id, payload) ⇒ Object

Handles the start of the endpoint_run event, modifying the parent Rack span and recording it as a span event



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/opentelemetry/instrumentation/grape/event_handler.rb', line 16

def endpoint_run(_name, start, _finish, _id, payload)
  span = OpenTelemetry::Instrumentation::Rack.current_span
  return unless span.recording?

  endpoint = payload[:endpoint]
  span.name = span_name(endpoint)
  span.add_attributes(attributes_from_grape_endpoint(endpoint))

  span.add_event('grape.endpoint_run', timestamp: start)
  handle_payload_exception(span, payload[:exception_object]) if payload[:exception_object]
end

.endpoint_run_filters(_name, start, finish, _id, payload) ⇒ Object

Handles the endpoint_run_filters events, recording them as a span event



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/opentelemetry/instrumentation/grape/event_handler.rb', line 37

def endpoint_run_filters(_name, start, finish, _id, payload)
  span = OpenTelemetry::Instrumentation::Rack.current_span
  return unless span.recording?

  filters = payload[:filters]
  type = payload[:type]

  # Prevent submitting empty filters
  return if (!filters || filters.empty?) || !type || (finish - start).zero?

  attributes = { 'grape.filter.type' => type.to_s }
  span.add_event('grape.endpoint_run_filters', attributes: attributes, timestamp: start)
end

.format_response(_name, start, _finish, _id, payload) ⇒ Object

Handles the format_response event, recording it as a span event



52
53
54
55
56
57
58
59
60
61
# File 'lib/opentelemetry/instrumentation/grape/event_handler.rb', line 52

def format_response(_name, start, _finish, _id, payload)
  span = OpenTelemetry::Instrumentation::Rack.current_span
  return unless span.recording?

  attributes = {
    'grape.formatter.type' => formatter_type(payload[:formatter])
  }
  span.add_event('grape.format_response', attributes: attributes, timestamp: start)
  handle_payload_exception(span, payload[:exception_object]) if payload[:exception_object]
end