Class: LaunchDarklyObservability::OpenTelemetryConfig

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(project_id:, otlp_endpoint:, environment: nil, sdk_metadata: nil, **options) ⇒ OpenTelemetryConfig

Initialize OpenTelemetry configuration

Parameters:

  • project_id (String)

    LaunchDarkly project ID

  • otlp_endpoint (String)

    OTLP collector endpoint

  • environment (String, nil) (defaults to: nil)

    Deployment environment name (optional - inferred from SDK key if not provided)

  • sdk_metadata (LaunchDarkly::Interfaces::Plugins::SdkMetadata, nil) (defaults to: nil)
  • options (Hash)

    Additional options



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, **options)
  @project_id = project_id
  @otlp_endpoint = otlp_endpoint
  @environment = environment
  @sdk_metadata = 
  @options = options
  @configured = false
  @logger_provider = nil
  @meter_provider = nil
end

Instance Attribute Details

#environmentString (readonly)

Returns The deployment environment.

Returns:

  • (String)

    The deployment environment



35
36
37
# File 'lib/launchdarkly_observability/opentelemetry_config.rb', line 35

def environment
  @environment
end

#logger_providerOpenTelemetry::SDK::Logs::LoggerProvider? (readonly)

Returns The logger provider (nil if logs disabled or setup failed).

Returns:

  • (OpenTelemetry::SDK::Logs::LoggerProvider, nil)

    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_endpointString (readonly)

Returns The OTLP endpoint.

Returns:

  • (String)

    The OTLP endpoint



32
33
34
# File 'lib/launchdarkly_observability/opentelemetry_config.rb', line 32

def otlp_endpoint
  @otlp_endpoint
end

#project_idString (readonly)

Returns The LaunchDarkly project ID.

Returns:

  • (String)

    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

#configureObject

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

  warn_ignored_boot_options 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

#flushObject

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.message}"
end

#install_instrumentation_onlyObject

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

#shutdownObject

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.message}"
end