Class: Skywalking::Plugins::Elasticsearch

Inherits:
PluginsManager::SWPlugin show all
Defined in:
lib/skywalking/plugins/elasticsearch.rb

Instance Method Summary collapse

Methods inherited from PluginsManager::SWPlugin

#initialize, #installed?, register, #try_install

Methods included from Log::Logging

#debug, #error, #info, #log, #warn

Constructor Details

This class inherits a constructor from Skywalking::Plugins::PluginsManager::SWPlugin

Instance Method Details

#installObject



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
# File 'lib/skywalking/plugins/elasticsearch.rb', line 23

def install
  inst_target = if defined?(::Elastic::Transport::Client)
                  ::Elastic::Transport::Client
                elsif defined?(::Elasticsearch::Transport::Client)
                  ::Elasticsearch::Transport::Client
                end

  inst_target.class_eval do
    def perform_request_with_skywalking(method, path, *args, &block)
      peer_info = transport.hosts.first
      db_statement = [{ params: args&.[](0) }]
      unless args[1].nil? || args[1].empty?
        db_statement << { body: args[1] }
      end

      Tracing::ContextManager.new_exit_span(
        operation: "Elasticsearch/#{method}/#{path}",
        peer: "#{peer_info[:protocol]}://#{peer_info[:host]}:#{peer_info[:port]}",
        component: Tracing::Component::Elasticsearch
      ) do |span|
        span&.tag(Tracing::TagDbType.new("Elasticsearch"))
        span&.tag(Tracing::TagDbStatement.new(db_statement))
        span&.layer = Tracing::Layer::Database

        zuper_perform_request(method, path, *args, &block)
      rescue
        span&.error_occurred = true
      end
    end

    alias_method :zuper_perform_request, :perform_request
    alias_method :perform_request, :perform_request_with_skywalking
  end
end

#plugin_valid?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/skywalking/plugins/elasticsearch.rb', line 19

def plugin_valid?
  defined?(::Elasticsearch)
end