Class: Brut::Instrumentation::OpenTelemetry::Span

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/brut/instrumentation/open_telemetry.rb

Instance Method Summary collapse

Instance Method Details

#add_attributes(attributes) ⇒ Object

Adds attributes to the span, converting the hash or keyword arguments to strings. This will use the app's Otel prefix for all attributes, so you do not have to prefix them. If you need to set standard attributes, you should use #add_prefixed_attributes instead.

Values will be converted via NormalizedAttributes, which preserves strings, numbers, and booleans, and converts the rest to strings via to_s.

Parameters:

  • attributes (Hash)

    a hash of the attributes to add. Keys will be converted to strings via to_s.



141
142
143
# File 'lib/brut/instrumentation/open_telemetry.rb', line 141

def add_attributes(attributes)
  add_prefixed_attributes(:detect,attributes)
end

#add_prefixed_attributes(prefix, attributes) ⇒ Object

Adds attributes to the span, prefixing each key with the given prefix, then converting the hash or keyword arguments to strings. For example, if the prefix is 'my_app' and you add the attributes 'type' and 'reason', the actual attribute names will be 'my_app.type' and 'my_app.reason'.

See Also:



148
149
150
151
152
# File 'lib/brut/instrumentation/open_telemetry.rb', line 148

def add_prefixed_attributes(prefix,attributes)
  __getobj__.add_attributes(
    NormalizedAttributes.new(prefix,attributes).to_h
  )
end