Class: OpenTelemetry::SDK::Configurator
- Inherits:
-
Object
- Object
- OpenTelemetry::SDK::Configurator
- 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
-
#id_generator ⇒ Object
writeonly
Sets the attribute id_generator.
-
#propagators ⇒ Object
writeonly
Sets the attribute propagators.
Instance Method Summary collapse
-
#add_log_record_processor(log_record_processor) ⇒ Object
Add a log record processor to the export pipeline.
-
#add_span_processor(span_processor) ⇒ Object
Add a span processor to the export pipeline.
-
#configure ⇒ Object
private
The configure method is where we define the setup process.
-
#error_handler ⇒ Object
Returns the configured error handler or the global OpenTelemetry error handler.
-
#error_handler=(error_handler) ⇒ Object
Configures the error handler that will be installed on OpenTelemetry during SDK configuration.
-
#initialize ⇒ Configurator
constructor
A new instance of Configurator.
-
#logger ⇒ Object
Returns the configured logger or the global OpenTelemetry logger.
-
#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.
-
#resource=(new_resource) ⇒ Object
Accepts a resource object that is merged with the default telemetry sdk resource.
-
#service_name=(service_name) ⇒ Object
Accepts a string that is merged in as the service.name resource attribute.
-
#service_version=(service_version) ⇒ Object
Accepts a string that is merged in as the service.version resource attribute.
-
#use(instrumentation_name, config = nil) ⇒ Object
Install an instrumentation with specified optional
config. -
#use_all(instrumentation_config_map = {}) ⇒ Object
Install all registered instrumentation.
Constructor Details
#initialize ⇒ Configurator
Returns a new instance of Configurator.
39 40 41 42 43 44 45 46 47 |
# File 'lib/opentelemetry/sdk/configurator.rb', line 39 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
#id_generator=(value) ⇒ Object (writeonly)
Sets the attribute id_generator
37 38 39 |
# File 'lib/opentelemetry/sdk/configurator.rb', line 37 def id_generator=(value) @id_generator = value end |
#propagators=(value) ⇒ Object (writeonly)
Sets the attribute propagators
37 38 39 |
# File 'lib/opentelemetry/sdk/configurator.rb', line 37 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
158 |
# File 'lib/opentelemetry/sdk/configurator.rb', line 158 def add_log_record_processor(log_record_processor); end |
#add_span_processor(span_processor) ⇒ Object
Add a span processor to the export pipeline
149 150 151 |
# File 'lib/opentelemetry/sdk/configurator.rb', line 149 def add_span_processor(span_processor) @span_processors << span_processor end |
#configure ⇒ Object
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
168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/opentelemetry/sdk/configurator.rb', line 168 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 |
#error_handler ⇒ Object
Returns the configured error handler or the global OpenTelemetry error handler.
83 84 85 |
# File 'lib/opentelemetry/sdk/configurator.rb', line 83 def error_handler @error_handler ||= OpenTelemetry.error_handler end |
#error_handler=(error_handler) ⇒ Object
Configures the error handler that will be installed on OpenTelemetry during SDK configuration.
Assigned object must respond to #call and accept the keyword
arguments exception: and message:.
rubocop:disable-next Style/TrivialAccessors
78 79 80 |
# File 'lib/opentelemetry/sdk/configurator.rb', line 78 def error_handler=(error_handler) @error_handler = error_handler end |
#logger ⇒ Object
Returns the configured logger or the global OpenTelemetry logger.
50 51 52 |
# File 'lib/opentelemetry/sdk/configurator.rb', line 50 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.
59 60 61 |
# File 'lib/opentelemetry/sdk/configurator.rb', line 59 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.
93 94 95 |
# File 'lib/opentelemetry/sdk/configurator.rb', line 93 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.
101 102 103 104 105 |
# File 'lib/opentelemetry/sdk/configurator.rb', line 101 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.
111 112 113 114 115 |
# File 'lib/opentelemetry/sdk/configurator.rb', line 111 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.
125 126 127 128 129 |
# File 'lib/opentelemetry/sdk/configurator.rb', line 125 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.
139 140 141 142 |
# File 'lib/opentelemetry/sdk/configurator.rb', line 139 def use_all(instrumentation_config_map = {}) check_use_mode!(USE_MODE_ALL) @instrumentation_config_map = instrumentation_config_map end |