Class: ScoutApm::Instruments::Elasticsearch

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/instruments/elasticsearch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/scout_apm/instruments/elasticsearch.rb', line 4

def logger
  @logger
end

Instance Method Details

#initalize(logger = ScoutApm::Agent.instance.logger) ⇒ Object



6
7
8
9
# File 'lib/scout_apm/instruments/elasticsearch.rb', line 6

def initalize(logger=ScoutApm::Agent.instance.logger)
  @logger = logger
  @installed = false
end

#installObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
# File 'lib/scout_apm/instruments/elasticsearch.rb', line 15

def install
  @installed = true

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

    ScoutApm::Agent.instance.logger.info "Instrumenting Elasticsearch"

    ::Elasticsearch::Transport::Client.class_eval do
      include ScoutApm::Tracer

      def perform_request_with_scout_instruments(*args, &block)
        name = _sanitize_name(args[1])

        self.class.instrument("Elasticsearch", name, :ignore_children => true) do
          perform_request_without_scout_instruments(*args, &block)
        end
      end

      alias_method :perform_request_without_scout_instruments, :perform_request
      alias_method :perform_request, :perform_request_with_scout_instruments

      def _sanitize_name(name)
        name = name.split("/").last.gsub(/^_/, '')
        allowed_names = ["bench",
                         "bulk",
                         "count",
                         "exists",
                         "explain",
                         "field_stats",
                         "health",
                         "mget",
                         "mlt",
                         "mpercolate",
                         "msearch",
                         "mtermvectors",
                         "percolate",
                         "query",
                         "scroll",
                         "search_shards",
                         "source",
                         "suggest",
                         "template",
                         "termvectors",
                         "update",
                         "search", ]

        if allowed_names.include?(name)
          name
        else
          "Unknown"
        end
      rescue
        "Unknown"
      end
    end
  end
end

#installed?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/scout_apm/instruments/elasticsearch.rb', line 11

def installed?
  @installed
end