Class: LaunchDarklyObservability::Plugin
- Inherits:
-
Object
- Object
- LaunchDarklyObservability::Plugin
- Includes:
- LaunchDarkly::Interfaces::Plugins::Plugin
- Defined in:
- lib/launchdarkly_observability/plugin.rb
Overview
LaunchDarkly SDK Plugin that provides observability instrumentation.
This plugin integrates with the LaunchDarkly Ruby SDK to automatically instrument flag evaluations with OpenTelemetry traces, logs, and metrics.
Instance Attribute Summary collapse
-
#environment ⇒ String
readonly
The deployment environment.
-
#options ⇒ Hash
readonly
Additional options.
-
#otlp_endpoint ⇒ String
readonly
The OTLP endpoint URL.
-
#project_id ⇒ String
readonly
The LaunchDarkly project ID.
Instance Method Summary collapse
-
#flush ⇒ Object
Flush all pending telemetry data.
-
#get_hooks(_environment_metadata) ⇒ Array<LaunchDarkly::Interfaces::Hooks::Hook>
Returns the hooks provided by this plugin.
-
#initialize(project_id: nil, sdk_key: nil, otlp_endpoint: DEFAULT_ENDPOINT, environment: nil, **options) ⇒ Plugin
constructor
Initialize a new observability plugin.
-
#metadata ⇒ LaunchDarkly::Interfaces::Plugins::PluginMetadata
Returns metadata about this plugin.
-
#register(_client, environment_metadata) ⇒ Object
Register the plugin with the LaunchDarkly client.
-
#registered? ⇒ Boolean
Check if the plugin has been registered.
-
#shutdown ⇒ Object
Shutdown the plugin and flush remaining data.
Constructor Details
#initialize(project_id: nil, sdk_key: nil, otlp_endpoint: DEFAULT_ENDPOINT, environment: nil, **options) ⇒ Plugin
Initialize a new observability plugin
56 57 58 59 60 61 62 63 64 |
# File 'lib/launchdarkly_observability/plugin.rb', line 56 def initialize(project_id: nil, sdk_key: nil, otlp_endpoint: DEFAULT_ENDPOINT, environment: nil, **) @project_id = project_id || sdk_key @otlp_endpoint = otlp_endpoint @environment = environment&.to_s @options = .merge() @hook = Hook.new @otel_config = nil @registered = false end |
Instance Attribute Details
#environment ⇒ String (readonly)
Returns The deployment environment.
35 36 37 |
# File 'lib/launchdarkly_observability/plugin.rb', line 35 def environment @environment end |
#options ⇒ Hash (readonly)
Returns Additional options.
38 39 40 |
# File 'lib/launchdarkly_observability/plugin.rb', line 38 def @options end |
#otlp_endpoint ⇒ String (readonly)
Returns The OTLP endpoint URL.
32 33 34 |
# File 'lib/launchdarkly_observability/plugin.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/plugin.rb', line 29 def project_id @project_id end |
Instance Method Details
#flush ⇒ Object
Flush all pending telemetry data
119 120 121 |
# File 'lib/launchdarkly_observability/plugin.rb', line 119 def flush @otel_config&.flush end |
#get_hooks(_environment_metadata) ⇒ Array<LaunchDarkly::Interfaces::Hooks::Hook>
Returns the hooks provided by this plugin
77 78 79 |
# File 'lib/launchdarkly_observability/plugin.rb', line 77 def get_hooks() [@hook] end |
#metadata ⇒ LaunchDarkly::Interfaces::Plugins::PluginMetadata
Returns metadata about this plugin
69 70 71 |
# File 'lib/launchdarkly_observability/plugin.rb', line 69 def LaunchDarkly::Interfaces::Plugins::PluginMetadata.new('launchdarkly-observability') end |
#register(_client, environment_metadata) ⇒ Object
Register the plugin with the LaunchDarkly client
This method is called during SDK initialization. It sets up the OpenTelemetry SDK with appropriate providers and exporters.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/launchdarkly_observability/plugin.rb', line 88 def register(_client, ) return if @registered # Use provided project_id, or extract SDK key from the client project_id = @project_id || &.sdk_key if project_id.nil? || project_id.empty? raise ArgumentError, 'Unable to determine project_id: no project_id or sdk_key provided, and client SDK key is unavailable' end @otel_config = OpenTelemetryConfig.new( project_id: project_id, otlp_endpoint: @otlp_endpoint, environment: @environment, sdk_metadata: &.sdk, **@options ) @otel_config.configure @registered = true end |
#registered? ⇒ Boolean
Check if the plugin has been registered
114 115 116 |
# File 'lib/launchdarkly_observability/plugin.rb', line 114 def registered? @registered end |
#shutdown ⇒ Object
Shutdown the plugin and flush remaining data
124 125 126 127 |
# File 'lib/launchdarkly_observability/plugin.rb', line 124 def shutdown @otel_config&.shutdown @registered = false end |