Class: OpenTelemetry::SDK::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/sdk/configurator.rb

Overview

The configurator provides defaults and facilitates configuring the SDK for use.

Defined Under Namespace

Classes: NoopTextMapPropagator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigurator

Returns a new instance of Configurator.



36
37
38
39
40
41
42
43
44
# File 'lib/opentelemetry/sdk/configurator.rb', line 36

def initialize
  @instrumentation_names = []
  @instrumentation_config_map = {}
  @propagators = nil
  @span_processors = []
  @use_mode = USE_MODE_UNSPECIFIED
  @resource = Resources::Resource.default
  @id_generator = OpenTelemetry::Trace
end

Instance Attribute Details

#error_handlerObject



59
60
61
# File 'lib/opentelemetry/sdk/configurator.rb', line 59

def error_handler
  @error_handler ||= OpenTelemetry.error_handler
end

#id_generator=(value) ⇒ Object (writeonly)

Sets the attribute id_generator

Parameters:

  • value

    the value to set the attribute id_generator to.



34
35
36
# File 'lib/opentelemetry/sdk/configurator.rb', line 34

def id_generator=(value)
  @id_generator = value
end

#propagators=(value) ⇒ Object (writeonly)

Sets the attribute propagators

Parameters:

  • value

    the value to set the attribute propagators to.



34
35
36
# File 'lib/opentelemetry/sdk/configurator.rb', line 34

def propagators=(value)
  @propagators = value
end

Instance Method Details

#add_log_record_processor(log_record_processor) ⇒ Object

Add a log record processor to the export pipeline

Parameters:

  • log_record_processor (#emit, #shutdown, #force_flush)

    A log_record_processor that satisfies the duck type #emit, #shutdown, #force_flush. See SimpleLogRecordProcessor for an example.



134
# File 'lib/opentelemetry/sdk/configurator.rb', line 134

def add_log_record_processor(log_record_processor); end

#add_span_processor(span_processor) ⇒ Object

Add a span processor to the export pipeline

Parameters:

  • span_processor (#on_start, #on_finish, #shutdown, #force_flush)

    A span_processor that satisfies the duck type #on_start, #on_finish, #shutdown, #force_flush. See SimpleSpanProcessor for an example.



125
126
127
# File 'lib/opentelemetry/sdk/configurator.rb', line 125

def add_span_processor(span_processor)
  @span_processors << span_processor
end

#configureObject

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.

The configure method is where we define the setup process. This allows us to make certain guarantees about which systems and globals are setup at each stage. The setup process is: - setup logging - setup propagation - setup tracer_provider, meter_provider, and logger_provider - install instrumentation



144
145
146
147
148
149
150
151
152
153
154
# File 'lib/opentelemetry/sdk/configurator.rb', line 144

def configure
  OpenTelemetry.logger = logger
  OpenTelemetry.error_handler = error_handler
  configure_propagation
  configure_span_processors
  tracer_provider.id_generator = @id_generator
  OpenTelemetry.tracer_provider = tracer_provider
  metrics_configuration_hook
  logs_configuration_hook
  install_instrumentation
end

#loggerObject



46
47
48
# File 'lib/opentelemetry/sdk/configurator.rb', line 46

def logger
  @logger ||= OpenTelemetry.logger
end

#logger=(new_logger) ⇒ Object

Accepts a logger and wraps it in the ForwardingLogger which allows for controlling the severity level emitted by the OpenTelemetry.logger independently of the supplied logger.

Parameters:

  • new_logger (Logger)

    The logger for OpenTelemetry to use



55
56
57
# File 'lib/opentelemetry/sdk/configurator.rb', line 55

def logger=(new_logger)
  @logger = ForwardingLogger.new(new_logger, level: ENV['OTEL_LOG_LEVEL'] || Logger::INFO)
end

#resource=(new_resource) ⇒ Object

Accepts a resource object that is merged with the default telemetry sdk resource. The use of this method is optional, and is provided as means to include additional resource information. If a resource key collision occurs the passed in resource takes priority.

Parameters:

  • new_resource (Resource)

    The resource to be merged



69
70
71
# File 'lib/opentelemetry/sdk/configurator.rb', line 69

def resource=(new_resource)
  @resource = @resource.merge(new_resource)
end

#service_name=(service_name) ⇒ Object

Accepts a string that is merged in as the service.name resource attribute. The most recent assigned value will be used in the event of repeated calls to this setter.

Parameters:

  • service_name (String)

    The value to be used as the service name



77
78
79
80
81
# File 'lib/opentelemetry/sdk/configurator.rb', line 77

def service_name=(service_name)
  self.resource = OpenTelemetry::SDK::Resources::Resource.create(
    OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME => service_name
  )
end

#service_version=(service_version) ⇒ Object

Accepts a string that is merged in as the service.version resource attribute. The most recent assigned value will be used in the event of repeated calls to this setter.

Parameters:

  • service_version (String)

    The value to be used as the service version



87
88
89
90
91
# File 'lib/opentelemetry/sdk/configurator.rb', line 87

def service_version=(service_version)
  self.resource = OpenTelemetry::SDK::Resources::Resource.create(
    OpenTelemetry::SemanticConventions::Resource::SERVICE_VERSION => service_version
  )
end

#use(instrumentation_name, config = nil) ⇒ Object

Install an instrumentation with specified optional config. Use can be called multiple times to install multiple instrumentation. Only use or use_all, but not both when installing instrumentation. A call to use_all after use will result in an exception.

Parameters:

  • instrumentation_name (String)

    The name of the instrumentation

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

    The config for this instrumentation



101
102
103
104
105
# File 'lib/opentelemetry/sdk/configurator.rb', line 101

def use(instrumentation_name, config = nil)
  check_use_mode!(USE_MODE_ONE)
  @instrumentation_names << instrumentation_name
  @instrumentation_config_map[instrumentation_name] = config if config
end

#use_all(instrumentation_config_map = {}) ⇒ Object

Install all registered instrumentation. Configuration for specific instrumentation can be provided with the optional instrumentation_config_map parameter. Only use or use_all, but not both when installing instrumentation. A call to use after use_all will result in an exception.

Parameters:

  • instrumentation_config_map (optional Hash<String,Hash>) (defaults to: {})

    A map with string keys representing the instrumentation name and values specifying the instrumentation config



115
116
117
118
# File 'lib/opentelemetry/sdk/configurator.rb', line 115

def use_all(instrumentation_config_map = {})
  check_use_mode!(USE_MODE_ALL)
  @instrumentation_config_map = instrumentation_config_map
end