Class: Elastic::Transport::OpenTelemetry Private

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic/transport/opentelemetry.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Wrapper object for Open Telemetry objects, associated config and functionality.

Defined Under Namespace

Classes: DeepDup, Sanitizer

Constant Summary collapse

OTEL_TRACER_NAME =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'elasticsearch-api'
ENV_VARIABLE_ENABLED =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Valid values for the enabled config are ‘true’ and ‘false’. Default is ‘true’.

'OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_ENABLED'
ENV_VARIABLE_BODY_STRATEGY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Describes how to handle search queries in the request body when assigned to a span attribute. Valid values are ‘raw’, ‘omit’, ‘sanitize’. Default is ‘omit’.

'OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_CAPTURE_SEARCH_QUERY'
ENV_VARIABLE_DEPRECATED_BODY_STRATEGY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'OTEL_INSTRUMENTATION_ELASTICSEARCH_CAPTURE_SEARCH_QUERY'
DEFAULT_BODY_STRATEGY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'omit'
ENV_VARIABLE_BODY_SANITIZE_KEYS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

A string list of keys whose values are redacted. This is only relevant if the body strategy is ‘sanitize’. For example, a config ‘sensitive-key,other-key’ will redact the values at ‘sensitive-key’ and ‘other-key’ in addition to the default keys.

'OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_SEARCH_QUERY_SANITIZE_KEYS'
SEARCH_ENDPOINTS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

A list of the Elasticsearch endpoints that qualify as “search” endpoints. The search query in the request body may be captured for these endpoints, depending on the body capture strategy.

Set[
  "search",
  "async_search.submit",
  "msearch",
  "eql.search",
  "terms_enum",
  "search_template",
  "msearch_template",
  "render_search_template",
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ OpenTelemetry

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize the Open Telemetry wrapper object. Takes the options originally passed to Client#initialize.



53
54
55
56
57
58
59
60
61
62
# File 'lib/elastic/transport/opentelemetry.rb', line 53

def initialize(opts)
  @tracer = (opts[:opentelemetry_tracer_provider] || ::OpenTelemetry.tracer_provider).tracer(
    OTEL_TRACER_NAME, Elastic::Transport::VERSION
  )
  @body_strategy = ENV[ENV_VARIABLE_DEPRECATED_BODY_STRATEGY] || ENV[ENV_VARIABLE_BODY_STRATEGY] ||
                     DEFAULT_BODY_STRATEGY
  @sanitize_keys = ENV[ENV_VARIABLE_BODY_SANITIZE_KEYS]&.split(',')&.collect! do |pattern|
    Regexp.new(pattern.gsub('*', '.*'))
  end
end

Instance Attribute Details

#tracerObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



63
64
65
# File 'lib/elastic/transport/opentelemetry.rb', line 63

def tracer
  @tracer
end

Instance Method Details

#process_body(body, endpoint) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Process the request body. Applies the body strategy, which can be one of the following: ‘omit’: return nil ‘sanitize’: redact values at the default list of keys + any additional keys provided in the OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_SEARCH_QUERY_SANITIZE_KEYS env variable. ‘raw’: return the original body, unchanged



70
71
72
73
74
75
76
77
78
# File 'lib/elastic/transport/opentelemetry.rb', line 70

def process_body(body, endpoint)
  unless @body_strategy == 'omit' || !SEARCH_ENDPOINTS.include?(endpoint)
    if @body_strategy == 'sanitize'
      Sanitizer.sanitize(body, @sanitize_keys).to_json
    elsif @body_strategy == 'raw'
      body&.is_a?(String) ? body : body.to_json
    end
  end
end