Class: Atatus::Spies::ElasticsearchSpy Private

Inherits:
Object
  • Object
show all
Defined in:
lib/atatus/spies/elasticsearch.rb

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.

Constant Summary collapse

NAME_FORMAT =

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.

'%s %s'
TYPE =

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.

'db'
SUBTYPE =

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'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.sanitizerObject

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.



29
30
31
# File 'lib/atatus/spies/elasticsearch.rb', line 29

def self.sanitizer
  @sanitizer ||= Atatus::Transport::Filters::HashSanitizer.new
end

Instance Method Details

#installObject

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.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/atatus/spies/elasticsearch.rb', line 33

def install
  if defined?(::Elasticsearch) &&
      defined?(::Elasticsearch::Transport) &&
      defined?(::Elasticsearch::Transport::Client)

    ::Elasticsearch::Transport::Client.class_eval do
      alias perform_request_without_apm perform_request

      def perform_request(method, path, *args, &block)
        unless Atatus.current_transaction
          return perform_request_without_apm(method, path, *args, &block)
        end

        name = format(NAME_FORMAT, method, path)
        statement = []

        statement << { params: args&.[](0) }

        if Atatus.agent.config.capture_elasticsearch_queries
          unless args[1].nil? || args[1].empty?
            statement << {
              body: Atatus::Spies::ElasticsearchSpy.sanitizer.strip_from!(args[1])
            }
          end
        end

        context = Span::Context.new(
          db: { statement: statement.reduce({}, :merge).to_json },
          destination: {
            name: SUBTYPE,
            resource: SUBTYPE,
            type: TYPE
          }
        )

        Atatus.with_span(
          name,
          TYPE,
          subtype: SUBTYPE,
          context: context
        ) { perform_request_without_apm(method, path, *args, &block) }
      end
    end

  end
end