Class: LaunchDarkly::Otel::TracingHook
- Inherits:
-
Object
- Object
- LaunchDarkly::Otel::TracingHook
- Includes:
- Interfaces::Hooks::Hook
- Defined in:
- lib/ldclient-otel/tracing_hook.rb
Instance Method Summary collapse
-
#after_evaluation(evaluation_series_context, data, detail) ⇒ Hash
The after method is called during the execution of the variation method after the flag value has been determined.
-
#before_evaluation(evaluation_series_context, data) ⇒ Hash
The before method is called during the execution of a variation method before the flag value has been determined.
-
#initialize(config = TracingHookOptions.new()) ⇒ TracingHook
constructor
A new instance of TracingHook.
-
#metadata ⇒ Metadata
Get metadata about the hook implementation.
Constructor Details
#initialize(config = TracingHookOptions.new()) ⇒ TracingHook
Returns a new instance of TracingHook.
82 83 84 85 |
# File 'lib/ldclient-otel/tracing_hook.rb', line 82 def initialize(config = TracingHookOptions.new()) @config = config @tracer = OpenTelemetry.tracer_provider.tracer('launchdarkly') end |
Instance Method Details
#after_evaluation(evaluation_series_context, data, detail) ⇒ Hash
The after method is called during the execution of the variation method after the flag value has been determined. The method is executed synchronously.
being performed. of the previous stage for a series. modified.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/ldclient-otel/tracing_hook.rb', line 132 def after_evaluation(evaluation_series_context, data, detail) if data[:span].is_a?(OpenTelemetry::Trace::Span) OpenTelemetry::Context.detach(data[:token]) data[:span].finish() end span = OpenTelemetry::Trace.current_span return data if span.nil? event = { 'feature_flag.key' => evaluation_series_context.key, 'feature_flag.provider.name' => 'LaunchDarkly', 'feature_flag.context.id' => evaluation_series_context.context.fully_qualified_key, } event['feature_flag.result.value'] = detail.value.to_s if @config.include_value || @config.include_variant event['feature_flag.result.reason.inExperiment'] = true if detail.reason&.in_experiment event['feature_flag.result.variationIndex'] = detail.variation_index if detail.variation_index event['feature_flag.set.id'] = @config.environment_id if @config.environment_id span.add_event('feature_flag', attributes: event) data end |
#before_evaluation(evaluation_series_context, data) ⇒ Hash
The before method is called during the execution of a variation method before the flag value has been determined. The method is executed synchronously.
performed. This is not mutable. of the previous stage for a series. The input record should not be modified.
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ldclient-otel/tracing_hook.rb', line 106 def before_evaluation(evaluation_series_context, data) return data unless @config.add_spans attributes = { 'feature_flag.context.id' => evaluation_series_context.context.fully_qualified_key, 'feature_flag.key' => evaluation_series_context.key, } span = @tracer.start_span(evaluation_series_context.method, attributes: attributes) ctx = OpenTelemetry::Trace.context_with_span(span) token = OpenTelemetry::Context.attach(ctx) data.merge({span: span, token: token}) end |
#metadata ⇒ Metadata
Get metadata about the hook implementation.
92 93 94 |
# File 'lib/ldclient-otel/tracing_hook.rb', line 92 def LaunchDarkly::Interfaces::Hooks::Metadata.new('LaunchDarkly Tracing Hook') end |