Class: OpenTelemetry::Instrumentation::Rage::Handlers::Request

Inherits:
Rage::Telemetry::Handler
  • Object
show all
Defined in:
lib/opentelemetry/instrumentation/rage/handlers/request.rb

Overview

The class updates the name of the Rack span, adds relevant attributes, and records exceptions if any occur during the processing of a controller action.

Class Method Summary collapse

Class Method Details

.enrich_request_span(controller:, request:) ⇒ Object

Parameters:

  • controller (RageController::API)

    the controller processing the request

  • request (Rage::Request)

    the request being processed



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/opentelemetry/instrumentation/rage/handlers/request.rb', line 21

def self.enrich_request_span(controller:, request:)
  span = OpenTelemetry::Instrumentation::Rack.current_span
  return yield unless span.recording?

  http_route = request.route_uri_pattern
  span.name = "#{request.method} #{http_route}"
  span.set_attribute(SemConv::HTTP::HTTP_ROUTE, http_route)

  result = yield
  return unless result.error?

  span.record_exception(result.exception)
  span.status = OpenTelemetry::Trace::Status.error
end