Class: LaunchDarkly::Otel::TracingHook

Inherits:
Object
  • Object
show all
Includes:
Interfaces::Hooks::Hook
Defined in:
lib/ldclient-otel/tracing_hook.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = TracingHookOptions.new()) ⇒ TracingHook

Returns a new instance of TracingHook.

Parameters:



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.

Parameters:

  • evaluation_series_context (EvaluationSeriesContext)

    Contains read-only information about the evaluation

  • data (Hash)

    A record associated with each stage of hook invocations. Each stage is called with the data

  • detail (LaunchDarkly::EvaluationDetail)

    The result of the evaluation. This value should not be

Returns:

  • (Hash)

    Data to use when executing the next state of the hook in the evaluation series.



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.

Parameters:

  • evaluation_series_context (EvaluationSeriesContext)

    Contains information about the evaluation being

  • data (Hash)

    A record associated with each stage of hook invocations. Each stage is called with the data

Returns:

  • (Hash)

    Data to use when executing the next state of the hook in the evaluation series.



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

#metadataMetadata

Get metadata about the hook implementation.

Returns:

  • (Metadata)


66
67
68
# File 'lib/ldclient-otel/tracing_hook.rb', line 66

def 
  LaunchDarkly::Interfaces::Hooks::Metadata.new('LaunchDarkly Tracing Hook')
end