Class: Brut::FrontEnd::Components::Traceparent

Inherits:
Brut::FrontEnd::Component show all
Defined in:
lib/brut/front_end/components/traceparent.rb

Overview

Renders the traceparent value for the current trace so that the front-end can add additional spans.

Instance Method Summary collapse

Methods inherited from Brut::FrontEnd::Component

component_name, #component_name

Methods included from Brut::FrontEnd::Component::Helpers

#global_component, #inline_svg

Methods included from I18n::ForHTML

#html_escape, #t

Methods included from I18n::BaseMethods

#l, #t, #t_direct, #this_field_value

Methods included from Brut::Framework::Errors

#abstract_method!, #bug!

Constructor Details

#initializeTraceparent

Returns a new instance of Traceparent.



3
4
5
6
7
8
9
# File 'lib/brut/front_end/components/traceparent.rb', line 3

def initialize
  propagator = OpenTelemetry::Trace::Propagation::TraceContext::TextMapPropagator.new
  carrier = {}
  current_context = OpenTelemetry::Context.current
  propagator.inject(carrier, context: current_context)
  @traceparent = carrier["traceparent"]
end

Instance Method Details

#view_templateObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/brut/front_end/components/traceparent.rb', line 11

def view_template
  attributes = {
    name: "traceparent",
    content: @traceparent,
  }
  if !@traceparent
    attributes["data-no-traceparent"] = "no traceparent was available - this component may have been rendered outside of an existing OpenTelemetry context"
  end
  meta(**attributes)
end