Class: OpenTelemetry::Trace::Tracer

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/trace/tracer.rb

Overview

No-op implementation of Tracer.

Direct Known Subclasses

Internal::ProxyTracer

Instance Method Summary collapse

Instance Method Details

#in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil) {|span, context| ... } ⇒ Object

This is a helper for the default use-case of extending the current trace with a span.

With this helper:

OpenTelemetry.tracer.in_span('do-the-thing') do ... end

Equivalent without helper:

OpenTelemetry::Trace.with_span(tracer.start_span('do-the-thing')) do ... end

On exit, the Span that was active before calling this method will be reactivated. If an exception occurs during the execution of the provided block, it will be recorded on the span and reraised.

Numeric, Boolean, Array}

Parameters:

  • name (String)

    the name of the span

  • attributes (optional Hash) (defaults to: nil)

    attributes to attach to the span {String => String,

  • links (optional Array) (defaults to: nil)

    an array of OpenTelemetry::Trace::Link instances

  • start_timestamp (optional Integer) (defaults to: nil)

    nanoseconds since Epoch

  • kind (optional Symbol) (defaults to: nil)

    One of :internal, :server, :client, :producer, :consumer

Yields:

  • (span, context)

    yields the newly created span and a context containing the span to the block.



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/opentelemetry/trace/tracer.rb', line 34

def in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
  span = nil
  span = start_span(name, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind)
  Trace.with_span(span) { |s, c| yield s, c }
rescue Exception => e # rubocop:disable Lint/RescueException
  span&.record_exception(e)
  span&.status = Status.error("Unhandled exception of type: #{e.class}")
  raise e
ensure
  span&.finish
end

#start_root_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil) ⇒ Object



46
47
48
# File 'lib/opentelemetry/trace/tracer.rb', line 46

def start_root_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
  Span::INVALID
end

#start_span(name, with_parent: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil) ⇒ Span

Used when a caller wants to manage the activation/deactivation and lifecycle of the Span and its parent manually.

Parent context can be either passed explicitly, or inferred from currently activated span.

Parameters:

  • with_parent (optional Context) (defaults to: nil)

    Explicitly managed parent context

Returns:



58
59
60
61
62
63
64
65
66
# File 'lib/opentelemetry/trace/tracer.rb', line 58

def start_span(name, with_parent: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
  span = OpenTelemetry::Trace.current_span(with_parent)

  if span.context.valid?
    span
  else
    Span::INVALID
  end
end