Class: OpenTelemetry::Instrumentation::ActionPack::Handlers::ActionController

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/instrumentation/action_pack/handlers/action_controller.rb

Overview

Action Controller handler to handle the notification from Active Support

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ActionController

Returns a new instance of ActionController.

Parameters:

  • config (Hash)

    of instrumentation options



14
15
16
17
# File 'lib/opentelemetry/instrumentation/action_pack/handlers/action_controller.rb', line 14

def initialize(config)
  @config = config
  @span_naming = config.fetch(:span_naming)
end

Instance Method Details

#finish(_name, _id, payload) ⇒ Hash

Invoked by ActiveSupport::Notifications at the end of the instrumentation block

Parameters:

  • _name (String)

    of the event (unused)

  • _id (String)

    of the event (unused)

  • payload (Hash)

    the payload passed as a method argument

Returns:

  • (Hash)

    the payload passed as a method argument



41
42
43
44
45
46
# File 'lib/opentelemetry/instrumentation/action_pack/handlers/action_controller.rb', line 41

def finish(_name, _id, payload)
  span = OpenTelemetry::Instrumentation::Rack.current_span
  span.record_exception(payload[:exception_object]) if payload[:exception_object]
rescue StandardError => e
  OpenTelemetry.handle_error(exception: e)
end

#start(_name, _id, payload) ⇒ Hash

Invoked by ActiveSupport::Notifications at the start of the instrumentation block

Parameters:

  • _name (String)

    of the event (unused)

  • _id (String)

    of the event (unused)

  • payload (Hash)

    the payload passed as a method argument

Returns:

  • (Hash)

    the payload passed as a method argument



25
26
27
28
29
30
31
32
33
# File 'lib/opentelemetry/instrumentation/action_pack/handlers/action_controller.rb', line 25

def start(_name, _id, payload)
  span_name, attributes = to_span_name_and_attributes(payload)

  span = OpenTelemetry::Instrumentation::Rack.current_span
  span.name = span_name
  span.add_attributes(attributes)
rescue StandardError => e
  OpenTelemetry.handle_error(exception: e)
end