Class: LaunchDarklyObservability::OpenTelemetryConfig
- Inherits:
-
Object
- Object
- LaunchDarklyObservability::OpenTelemetryConfig
- Defined in:
- lib/launchdarkly_observability/opentelemetry_config.rb
Overview
Configures OpenTelemetry SDK with appropriate providers and exporters for traces, logs, and metrics.
This class handles the setup of:
- Tracer provider with OTLP exporter and batch processing
- Logger provider with OTLP log exporter (included by default)
- Meter provider with OTLP metrics exporter (if available)
- Auto-instrumentation for Rails, ActiveRecord, Net::HTTP, etc.
Constant Summary collapse
- BATCH_SCHEDULE_DELAY_MS =
Default batch processor configuration
1000- BATCH_MAX_EXPORT_SIZE =
128- BATCH_MAX_QUEUE_SIZE =
1024- METRICS_EXPORT_INTERVAL_MS =
Metrics export interval
60_000
Instance Attribute Summary collapse
-
#environment ⇒ String
readonly
The deployment environment.
-
#logger_provider ⇒ OpenTelemetry::SDK::Logs::LoggerProvider?
readonly
The logger provider (nil if logs disabled or setup failed).
-
#otlp_endpoint ⇒ String
readonly
The OTLP endpoint.
-
#project_id ⇒ String
readonly
The LaunchDarkly project ID.
Instance Method Summary collapse
-
#configure ⇒ Object
Configure OpenTelemetry SDK.
-
#flush ⇒ Object
Flush all pending telemetry data.
-
#initialize(project_id:, otlp_endpoint:, environment: nil, sdk_metadata: nil, **options) ⇒ OpenTelemetryConfig
constructor
Initialize OpenTelemetry configuration.
-
#install_instrumentation_only ⇒ Object
Install the SDK tracer provider and auto-instrumentation WITHOUT exporters.
-
#shutdown ⇒ Object
Shutdown all providers.
Constructor Details
#initialize(project_id:, otlp_endpoint:, environment: nil, sdk_metadata: nil, **options) ⇒ OpenTelemetryConfig
Initialize OpenTelemetry configuration
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/launchdarkly_observability/opentelemetry_config.rb', line 47 def initialize(project_id:, otlp_endpoint:, environment: nil, sdk_metadata: nil, **) @project_id = project_id @otlp_endpoint = otlp_endpoint @environment = environment @sdk_metadata = @options = @configured = false @logger_provider = nil @meter_provider = nil end |
Instance Attribute Details
#environment ⇒ String (readonly)
Returns The deployment environment.
35 36 37 |
# File 'lib/launchdarkly_observability/opentelemetry_config.rb', line 35 def environment @environment end |
#logger_provider ⇒ OpenTelemetry::SDK::Logs::LoggerProvider? (readonly)
Returns The logger provider (nil if logs disabled or setup failed).
38 39 40 |
# File 'lib/launchdarkly_observability/opentelemetry_config.rb', line 38 def logger_provider @logger_provider end |
#otlp_endpoint ⇒ String (readonly)
Returns The OTLP endpoint.
32 33 34 |
# File 'lib/launchdarkly_observability/opentelemetry_config.rb', line 32 def otlp_endpoint @otlp_endpoint end |
#project_id ⇒ String (readonly)
Returns The LaunchDarkly project ID.
29 30 31 |
# File 'lib/launchdarkly_observability/opentelemetry_config.rb', line 29 def project_id @project_id end |
Instance Method Details
#configure ⇒ Object
Configure OpenTelemetry SDK
Sets up tracer provider with OTLP exporter, logger provider for OTLP log export, and optionally meter provider if available.
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/launchdarkly_observability/opentelemetry_config.rb', line 62 def configure return if @configured if LaunchDarklyObservability.instrumentation_installed_at_boot? configure_traces if @options.fetch(:enable_traces, true) configure_logs if @options.fetch(:enable_logs, true) configure_metrics if @options.fetch(:enable_metrics, true) setup_shutdown_hook @configured = true end |
#flush ⇒ Object
Flush all pending telemetry data
91 92 93 94 95 96 97 |
# File 'lib/launchdarkly_observability/opentelemetry_config.rb', line 91 def flush OpenTelemetry.tracer_provider&.force_flush @logger_provider&.force_flush @meter_provider&.force_flush rescue StandardError => e warn "[LaunchDarklyObservability] Error flushing telemetry: #{e.}" end |
#install_instrumentation_only ⇒ Object
Install the SDK tracer provider and auto-instrumentation WITHOUT exporters.
Called from the Rails Railtie during boot so the Rails-family instrumentations (which patch via ActiveSupport.on_load hooks that fire during boot) attach even when the LaunchDarkly client — and therefore #register / #configure — is created lazily afterward. Exporters are added later by #configure_traces when the client registers the plugin.
83 84 85 86 87 88 |
# File 'lib/launchdarkly_observability/opentelemetry_config.rb', line 83 def install_instrumentation_only configure_sdk_capturing_failures do |c| c.resource = create_resource configure_instrumentations(c) end end |
#shutdown ⇒ Object
Shutdown all providers
100 101 102 103 104 105 106 |
# File 'lib/launchdarkly_observability/opentelemetry_config.rb', line 100 def shutdown OpenTelemetry.tracer_provider&.shutdown @logger_provider&.shutdown @meter_provider&.shutdown rescue StandardError => e warn "[LaunchDarklyObservability] Error shutting down telemetry: #{e.}" end |