NAME

Sentry::Integration::DBI - Spans and breadcrumbs for DBI statements

DESCRIPTION

Enabled by default. Records statements run via do, the select* methods and execute as spans (op db) and breadcrumbs (category query). Connections made (by connect, connect_cached when it connects, or Apache::DBI) get a span connect (op db) with the data of the data source and the user name passed (db.user, never the password), like sentry-python's Django integration.

Spans of queries carry the number of rows returned (db.response.returned_rows): of the select* methods (unless called in void context), and of statement handles the rows fetched after execute so far. As many drivers (e.g. DBD::SQLite, DBD::mysql with mysql_use_result) read rows only when they are fetched, which the span of execute does not cover, the time spent in the fetch methods is added as db.fetch.duration_ms. Fetches after the transaction has been sent are not recorded.

Statements taking, releasing or testing locks get the op db.lock instead, so that waiting for a lock stands out from slow queries: named locks of MySQL and MariaDB (GET_LOCK, RELEASE_LOCK, RELEASE_ALL_LOCKS, IS_FREE_LOCK, IS_USED_LOCK), advisory locks of PostgreSQL (pg_advisory_lock and its variants) and LOCK TABLES / UNLOCK TABLES (LOCK TABLE of PostgreSQL). They still count as queries in Sentry's Queries insight. Spans carry the attributes sentry-python's SQLAlchemy integration sends: db.system.name (e.g. mysql), db.driver.name (e.g. DBD::mysql), db.query.text (the statement) and, as far as the data source names them, db.namespace (the database), server.address and server.port; never its credentials. Bind values are only recorded with "record_sql_params" in Sentry::SDK.

Sentry::SDK->init({
  integrations => [Sentry::Integration::DBI->new(breadcrumbs => 0)],
});

Transactions

Where a transaction begins and ends, how long its commit or rollback took (e.g. syncing to disk, waiting for locks) and whether it was rolled back: begin_work, commit and rollback are spans BEGIN, COMMIT and ROLLBACK (op db, with db.operation.name and the data of the connection) and breadcrumbs, like the transaction spans of sentry-python's Django integration (db_transaction_spans) and sentry-java's JDBC integration, though on by default. So is turning AutoCommit off (BEGIN) and on again, which commits (COMMIT):

my $was = $dbh->{AutoCommit};
$dbh->{AutoCommit} = 0;    # span BEGIN
$dbh->do('CALL import_orders()');
$dbh->rollback;            # span ROLLBACK
$dbh->{AutoCommit} = $was; # span COMMIT (of the transaction begun anew)

A commit or rollback failing gets the status internal_error, also when it returns false without RaiseError (unless called in void context); a rollback itself is no error. commit and rollback with AutoCommit on (ineffective) and the attributes passed to connect are not recorded. No statement is added; storing other attributes costs some 0.2 microseconds more. Explicit SQL like $dbh->do('COMMIT') is a statement like any other.

ATTRIBUTES

See "ATTRIBUTES" in Sentry::Integration::Base.

METHODS

install

See "install" in Sentry::Integration::Base.

record_operation

my $result = $integration->record_operation($dbh, 'SAVEPOINT',
  sub { $storage->_exec_svp_begin($name) }, "SAVEPOINT $name");

Records $code, which does on $dbh what the SQL $operation would (e.g. a method of the driver instead of SQL), as a span (op db, the description defaulting to $operation, which is its db.operation.name) and breadcrumb, and returns its result in the caller's context. Statements and operations $code runs are part of it, not recorded on their own. For integrations of modules on top of DBI (see Sentry::Integration::DBIxClass).

handle_data

my %data = Sentry::Integration::DBI->handle_data($dbh);

The data the spans of $dbh carry: db.system.name, db.driver.name and, as far as the data source names them, db.namespace, server.address and server.port.

SPAN ORIGIN

origin

The spans of this integration have the origin auto.db.dbi (see "origin" in Sentry::Integration::Base).