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.
56 57 58 59 |
# File 'lib/ldclient-otel/tracing_hook.rb', line 56 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.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ldclient-otel/tracing_hook.rb', line 106 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.key' => evaluation_series_context.context.fully_qualified_key, } event['feature_flag.variant'] = detail.value.to_s if @config.include_variant 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.
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ldclient-otel/tracing_hook.rb', line 80 def before_evaluation(evaluation_series_context, data) return data unless @config.add_spans attributes = { 'feature_flag.context.key' => 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.
66 67 68 |
# File 'lib/ldclient-otel/tracing_hook.rb', line 66 def LaunchDarkly::Interfaces::Hooks::Metadata.new('LaunchDarkly Tracing Hook') end |