Class: OpenTelemetry::SDK::Trace::TracerProvider

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

Overview

TracerProvider is the SDK implementation of Trace::TracerProvider.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource = OpenTelemetry::SDK::Resources::Resource.create) ⇒ TracerProvider



22
23
24
25
26
27
28
29
30
# File 'lib/opentelemetry/sdk/trace/tracer_provider.rb', line 22

def initialize(resource = OpenTelemetry::SDK::Resources::Resource.create)
  @mutex = Mutex.new
  @registry = {}
  @active_span_processor = NoopSpanProcessor.instance
  @active_trace_config = Config::TraceConfig::DEFAULT
  @registered_span_processors = []
  @stopped = false
  @resource = resource
end

Instance Attribute Details

#active_span_processorObject (readonly)

Returns the value of attribute active_span_processor.



16
17
18
# File 'lib/opentelemetry/sdk/trace/tracer_provider.rb', line 16

def active_span_processor
  @active_span_processor
end

#active_trace_configObject

Returns the value of attribute active_trace_config.



15
16
17
# File 'lib/opentelemetry/sdk/trace/tracer_provider.rb', line 15

def active_trace_config
  @active_trace_config
end

#resourceObject (readonly)

Returns the value of attribute resource.



16
17
18
# File 'lib/opentelemetry/sdk/trace/tracer_provider.rb', line 16

def resource
  @resource
end

#stoppedObject (readonly) Also known as: stopped?

Returns the value of attribute stopped.



16
17
18
# File 'lib/opentelemetry/sdk/trace/tracer_provider.rb', line 16

def stopped
  @stopped
end

Instance Method Details

#add_span_processor(span_processor) ⇒ Object

Adds a new SpanProcessor to this OpenTelemetry::SDK::Trace::Tracer.

Any registered processor causes overhead, consider to use an async/batch processor especially for span exporting, and export to multiple backends using the OpenTelemetry::SDK::Trace::TracerProvider.ioio.opentelemetryio.opentelemetry.sdkio.opentelemetry.sdk.traceio.opentelemetry.sdk.trace.exportio.opentelemetry.sdk.trace.export.MultiSpanExporter.

Parameters:

  • span_processor

    the new SpanProcessor to be added.



73
74
75
76
77
78
79
80
81
82
# File 'lib/opentelemetry/sdk/trace/tracer_provider.rb', line 73

def add_span_processor(span_processor)
  @mutex.synchronize do
    if @stopped
      OpenTelemetry.logger.warn('calling Tracer#add_span_processor after shutdown.')
      return
    end
    @registered_span_processors << span_processor
    @active_span_processor = MultiSpanProcessor.new(@registered_span_processors.dup)
  end
end

#shutdown(timeout: nil) ⇒ Object

Attempts to stop all the activity for this OpenTelemetry::SDK::Trace::Tracer. Calls SpanProcessor#shutdown for all registered SpanProcessors.

This operation may block until all the Spans are processed. Must be called before turning off the main application to ensure all data are processed and exported.

After this is called all the newly created Spans will be no-op.

Parameters:

  • timeout (optional Numeric) (defaults to: nil)

    An optional timeout in seconds.



54
55
56
57
58
59
60
61
62
63
# File 'lib/opentelemetry/sdk/trace/tracer_provider.rb', line 54

def shutdown(timeout: nil)
  @mutex.synchronize do
    if @stopped
      OpenTelemetry.logger.warn('calling Tracer#shutdown multiple times.')
      return
    end
    @active_span_processor.shutdown(timeout: timeout)
    @stopped = true
  end
end

#tracer(name = nil, version = nil) ⇒ Tracer

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

Parameters:

  • name (optional String) (defaults to: nil)

    Instrumentation package name

  • version (optional String) (defaults to: nil)

    Instrumentation package version

Returns:



38
39
40
41
42
# File 'lib/opentelemetry/sdk/trace/tracer_provider.rb', line 38

def tracer(name = nil, version = nil)
  name ||= ''
  version ||= ''
  @mutex.synchronize { @registry[Key.new(name, version)] ||= Tracer.new(name, version, self) }
end