Class: Appsignal::EventFormatter::ElasticSearch::SearchFormatter

Inherits:
Appsignal::EventFormatter show all
Defined in:
lib/appsignal/event_formatter/elastic_search/search_formatter.rb

Constant Summary

Constants inherited from Appsignal::EventFormatter

DEFAULT, SQL_BODY_FORMAT

Instance Method Summary collapse

Methods inherited from Appsignal::EventFormatter

register, registered?, unregister

Instance Method Details

#format(payload) ⇒ Object



23
24
25
26
27
28
# File 'lib/appsignal/event_formatter/elastic_search/search_formatter.rb', line 23

def format(payload)
  [
    "#{payload[:name]}: #{payload[:klass]}",
    sanitized_search(payload[:search]).inspect
  ]
end

#opentelemetry_attributes(payload) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/appsignal/event_formatter/elastic_search/search_formatter.rb', line 13

def opentelemetry_attributes(payload)
  {
    "db.system.name" => "elasticsearch",
    # This notification is only emitted for a search, so that is the
    # operation every one of these spans describes.
    "db.operation.name" => "search",
    "db.collection.name" => search_index(payload)
  }.compact
end

#opentelemetry_kindObject

A search is an outgoing call to an Elasticsearch cluster.



9
10
11
# File 'lib/appsignal/event_formatter/elastic_search/search_formatter.rb', line 9

def opentelemetry_kind
  :client
end

#sanitized_search(search) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/appsignal/event_formatter/elastic_search/search_formatter.rb', line 42

def sanitized_search(search)
  return unless search.is_a?(Hash)

  {}.tap do |hsh|
    search.each do |key, val|
      hsh[key] =
        if [:index, :type].include?(key)
          val
        else
          Appsignal::Utils::QueryParamsSanitizer.sanitize(val)
        end
    end
  end
end

#search_index(payload) ⇒ Object

The index a search ran against, which the notification carries in the search it describes. A search that names more than one index, or none at all, is left without this attribute rather than described with a value that is not an index name.



34
35
36
37
38
39
40
# File 'lib/appsignal/event_formatter/elastic_search/search_formatter.rb', line 34

def search_index(payload)
  search = payload[:search]
  return unless search.respond_to?(:[])

  index = search[:index]
  index if index.is_a?(String)
end