Class: Brut::FrontEnd::Handlers::InstrumentationHandler

Inherits:
Brut::FrontEnd::Handler show all
Defined in:
lib/brut/front_end/handlers/instrumentation_handler.rb

Defined Under Namespace

Classes: Event, Span, TraceParent

Instance Method Summary collapse

Methods inherited from Brut::FrontEnd::Handler

#before_handle, #handle!

Methods included from Brut::Framework::Errors

#abstract_method!, #bug!

Methods included from Brut::FrontEnd::HandlingResults

#http_status, #redirect_to

Constructor Details

#initialize(http_tracestate:, http_traceparent:) ⇒ InstrumentationHandler

Returns a new instance of InstrumentationHandler.



68
69
70
71
# File 'lib/brut/front_end/handlers/instrumentation_handler.rb', line 68

def initialize(http_tracestate:, http_traceparent:)
  @http_tracestate  = http_tracestate
  @http_traceparent = http_traceparent
end

Instance Method Details

#handleObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/brut/front_end/handlers/instrumentation_handler.rb', line 72

def handle
  traceparent = TraceParent.from_header(@http_traceparent)
  span        = Span.from_header(@http_tracestate)

  if span.nil? || traceparent.nil?
    SemanticLogger[self.class].info "Missing traceparent or span: #{@http_tracestate}, #{@http_traceparent}"
    return http_status(400)
  end

  carrier = traceparent.as_carrier
  propagator = OpenTelemetry::Trace::Propagation::TraceContext::TextMapPropagator.new
  extracted_context = propagator.extract(carrier)
  OpenTelemetry::Context.with_current(extracted_context) do
    record_span(span)
  end
  http_status(200)
end