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_provider) ⇒ 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

  • tracer_provider (TracerProvider)

    TracerProvider that initialized the tracer



25
26
27
28
29
30
# File 'lib/opentelemetry/sdk/trace/tracer.rb', line 25

def initialize(name, version, tracer_provider)
  @name = name
  @version = version
  @instrumentation_library = InstrumentationLibrary.new(name, version)
  @tracer_provider = tracer_provider
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

#tracer_providerObject (readonly)

Returns the value of attribute tracer_provider.



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

def tracer_provider
  @tracer_provider
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) ⇒ Object



32
33
34
# File 'lib/opentelemetry/sdk/trace/tracer.rb', line 32

def start_root_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
  start_span(name, with_parent: Context.empty, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind)
end

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



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

def start_span(name, with_parent: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
  name ||= 'empty'

  with_parent ||= Context.current
  parent_span_context = OpenTelemetry::Trace.current_span(with_parent).context
  if parent_span_context.valid?
    parent_span_id = parent_span_context.span_id
    tracestate = parent_span_context.tracestate
    trace_id = parent_span_context.trace_id
  end
  trace_id ||= OpenTelemetry::Trace.generate_trace_id
  sampler = tracer_provider.active_trace_config.sampler
  result = sampler.should_sample?(trace_id: trace_id, parent_context: with_parent, links: links, name: name, kind: kind, attributes: attributes)
  internal_create_span(result, name, kind, trace_id, parent_span_id, attributes, links, start_timestamp, tracestate, with_parent)
end