Class: Aws::Telemetry::OTelTracer

Inherits:
TracerBase show all
Defined in:
gems/aws-sdk-core/lib/aws-sdk-core/telemetry/otel.rb

Overview

OpenTelemetry-based TracerBase, responsible for creating spans.

Instance Method Summary collapse

Constructor Details

#initialize(tracer) ⇒ OTelTracer

Returns a new instance of OTelTracer.



81
82
83
84
# File 'gems/aws-sdk-core/lib/aws-sdk-core/telemetry/otel.rb', line 81

def initialize(tracer)
  super()
  @tracer = tracer
end

Instance Method Details

#current_spanAws::Telemetry::OTelSpan

Returns the current active span.



123
124
125
# File 'gems/aws-sdk-core/lib/aws-sdk-core/telemetry/otel.rb', line 123

def current_span
  OTelSpan.new(OpenTelemetry::Trace.current_span)
end

#in_span(name, attributes: nil, kind: nil, &block) ⇒ Aws::Telemetry::OTelSpan

A helper for the default use-case of extending the current trace with a span. 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 re-raised.

Parameters:

  • name (String)

    Span name

  • attributes (Hash) (defaults to: nil)

    Attributes to attach to the span

  • kind (Aws::Telemetry::SpanKind) (defaults to: nil)

    Type of Span

Returns:



114
115
116
117
118
# File 'gems/aws-sdk-core/lib/aws-sdk-core/telemetry/otel.rb', line 114

def in_span(name, attributes: nil, kind: nil, &block)
  @tracer.in_span(name, attributes: attributes, kind: kind) do |span|
    block.call(OTelSpan.new(span))
  end
end

#start_span(name, with_parent: nil, attributes: nil, kind: nil) ⇒ Aws::Telemetry::OTelSpan

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

Parameters:

  • name (String)

    Span name

  • with_parent (Object) (defaults to: nil)

    Parent Context

  • attributes (Hash) (defaults to: nil)

    Attributes to attach to the span

  • kind (Aws::Telemetry::SpanKind) (defaults to: nil)

    Type of Span

Returns:



94
95
96
97
98
99
100
101
102
# File 'gems/aws-sdk-core/lib/aws-sdk-core/telemetry/otel.rb', line 94

def start_span(name, with_parent: nil, attributes: nil, kind: nil)
  span = @tracer.start_span(
    name,
    with_parent: with_parent,
    attributes: attributes,
    kind: kind
  )
  OTelSpan.new(span)
end