Class: Appsignal::EventFormatter::Rom::SqlFormatter

Inherits:
Appsignal::EventFormatter show all
Defined in:
lib/appsignal/event_formatter/rom/sql_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

dry-monitor reports an event under an id rather than a name, so the first value here names the event. Naming it after ROM keeps every ROM query in one group.

The payload also says which database ROM is talking to, as Sequel's database type. That is deliberately not part of the name. It would put an application's queries in a group per database engine, so the same application would report one group in production and another in its tests.



29
30
31
# File 'lib/appsignal/event_formatter/rom/sql_formatter.rb', line 29

def format(payload)
  ["query.rom", payload[:query], SQL_BODY_FORMAT]
end

#opentelemetry_attributes(payload) ⇒ Object

The payload's name is Sequel's database_type symbol for the database ROM is talking to, so this uses Sequel's own lookup rather than a coincidentally similar one. A symbol the mapping does not recognise is left to the SQL sentinel, same as an engine this gem has never heard of.



38
39
40
41
42
43
# File 'lib/appsignal/event_formatter/rom/sql_formatter.rb', line 38

def opentelemetry_attributes(payload)
  name = Appsignal::OpenTelemetry::SqlDbSystem.name_for_sequel(payload[:name])
  return unless name

  { "db.system.name" => name }
end

#opentelemetry_kindObject

A query is an outgoing call to a datastore.



16
17
18
# File 'lib/appsignal/event_formatter/rom/sql_formatter.rb', line 16

def opentelemetry_kind
  :client
end

#opentelemetry_scopeObject

These events arrive over dry-monitor, which is a notification bus rather than a library that queries a database. ROM is what emits them, so that is what the scope names.



11
12
13
# File 'lib/appsignal/event_formatter/rom/sql_formatter.rb', line 11

def opentelemetry_scope
  ["appsignal-ruby/rom", Appsignal::VERSION]
end