Class: OpenTelemetry::SDK::Trace::Tracer

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

Overview

Tracer is the SDK implementation of Trace::Tracer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version) ⇒ Tracer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new OpenTelemetry::SDK::Trace::Tracer instance.

Parameters:

  • name (String)

    Instrumentation package name

  • version (String)

    Instrumentation package version



23
24
25
26
27
# File 'lib/opentelemetry/sdk/trace/tracer.rb', line 23

def initialize(name, version)
  @name = name
  @version = version
  @resource = Resources::Resource.create('name' => name, 'version' => version)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/opentelemetry/sdk/trace/tracer.rb', line 12

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



13
14
15
# File 'lib/opentelemetry/sdk/trace/tracer.rb', line 13

def version
  @version
end

Instance Method Details

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



29
30
31
32
# File 'lib/opentelemetry/sdk/trace/tracer.rb', line 29

def start_root_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil, sampling_hint: nil)
  parent_span_context = OpenTelemetry::Trace::SpanContext::INVALID
  start_span(name, with_parent_context: parent_span_context, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind, sampling_hint: sampling_hint)
end

#start_span(name, with_parent: nil, with_parent_context: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil, sampling_hint: nil) ⇒ Object

rubocop:disable Metrics/AbcSize



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

def start_span(name, with_parent: nil, with_parent_context: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil, sampling_hint: nil) # rubocop:disable Metrics/AbcSize
  name ||= 'empty'

  parent_span_context = with_parent&.context || with_parent_context || current_span.context
  parent_span_context = nil unless parent_span_context.valid?
  parent_span_id = parent_span_context&.span_id
  tracestate = parent_span_context&.tracestate
  trace_id = parent_span_context&.trace_id
  trace_id ||= OpenTelemetry::Trace.generate_trace_id
  span_id = OpenTelemetry::Trace.generate_span_id
  sampler = OpenTelemetry.tracer_factory.active_trace_config.sampler
  result = sampler.call(trace_id: trace_id, span_id: span_id, parent_context: parent_span_context, hint: sampling_hint, links: links, name: name, kind: kind, attributes: attributes)

  internal_create_span(result, name, kind, trace_id, span_id, parent_span_id, attributes, links, start_timestamp, tracestate)
end