Class: Utrace::Otel

Inherits:
Object
  • Object
show all
Defined in:
lib/utrace/otel.rb

Instance Method Summary collapse

Constructor Details

#initialize(name: self.class.name) ⇒ Otel

Returns a new instance of Otel.



3
4
5
# File 'lib/utrace/otel.rb', line 3

def initialize(name: self.class.name)
  @tracer = OpenTelemetry.tracer_provider.tracer(name)
end

Instance Method Details

#attrs(attrs) ⇒ Object



19
20
21
22
# File 'lib/utrace/otel.rb', line 19

def attrs(attrs)
  attrs = validate_attrs(attrs)
  ::OpenTelemetry::Trace.current_span.add_attributes(attrs)
end

#error(err) ⇒ Object



15
16
17
# File 'lib/utrace/otel.rb', line 15

def error(err)
  ::OpenTelemetry::Trace.current_span.record_exception(err)
end

#event(name, attrs: nil) ⇒ Object



11
12
13
# File 'lib/utrace/otel.rb', line 11

def event(name, attrs: nil)
  ::OpenTelemetry::Trace.current_span.add_event(name, attributes: validate_attrs(attrs))
end

#new_span(name, &block) ⇒ Object



7
8
9
# File 'lib/utrace/otel.rb', line 7

def new_span(name, &block)
  @tracer.in_span(name.to_s) { |_span| block.call }
end

#trace_idObject



24
25
26
# File 'lib/utrace/otel.rb', line 24

def trace_id
  ::OpenTelemetry::Trace.current_span.context.trace_id.unpack1('H*')
end