Documentation
¶
Overview ¶
Package sentrysql provides Sentry instrumentation for database/sql drivers.
It wraps an existing driver so that queries and executions become Sentry spans and are surfaced in the Queries module.
Example:
import (
_ "modernc.org/sqlite"
"github.com/getsentry/sentry-go"
sentrysql "github.com/getsentry/sentry-go/sql"
)
db, err := sentrysql.Open("sqlite", ":memory:",
sentrysql.WithDatabaseSystem(sentrysql.SystemSQLite),
sentrysql.WithDatabaseName("main"),
)
For well-known drivers (postgres, pgx, mysql, sqlite, sqlite3, sqlserver, mssql, mariadb, oracle, godror, clickhouse, snowflake, ...), Open and Register can infer db.system from the registration name, so the option is optional:
db, err := sentrysql.Open("postgres", dsn) // db.system = "postgresql"
OpenDB, WrapDriver, and WrapConnector cannot see a driver name and always require WithDatabaseSystem.
Index ¶
- Constants
- func Open(driverName, dataSourceName string, opts ...Option) (*sql.DB, error)
- func OpenDB(c driver.Connector, opts ...Option) (*sql.DB, error)
- func Register(name string, drv driver.Driver, opts ...Option) error
- func WrapConnector(c driver.Connector, opts ...Option) (driver.Connector, error)
- func WrapDriver(drv driver.Driver, opts ...Option) (driver.Driver, error)
- type DatabaseSystem
- type Option
Constants ¶
const ( SystemPostgreSQL = dbsystem.PostgreSQL SystemMySQL = dbsystem.MySQL SystemMariaDB = dbsystem.MariaDB SystemSQLite = dbsystem.SQLite SystemMSSQL = dbsystem.MSSQL SystemOracle = dbsystem.Oracle SystemClickhouse = dbsystem.Clickhouse SystemSnowflake = dbsystem.Snowflake )
const SpanOrigin sentry.SpanOrigin = "auto.db.sentrysql"
SpanOrigin identifies spans emitted by this package.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
Register registers a wrapped version of drv under the name "sentrysql-<name>". It is safe to call once per process; subsequent calls with the same name return nil without re-registering.
func WrapConnector ¶
WrapConnector wraps a driver.Connector so connections it hands out are instrumented. WithDatabaseSystem is required.
Types ¶
type DatabaseSystem ¶
type Option ¶
type Option func(*config)
Option configures sql wrappers.
func WithDatabaseName ¶
WithDatabaseName sets the db.namespace span attribute (logical database name).
func WithDatabaseSystem ¶
func WithDatabaseSystem(system DatabaseSystem) Option
WithDatabaseSystem sets the db.system span attribute. Prefer one of the System* constants; pass DatabaseSystem("...") for databases not enumerated.
When Open is used and this option is omitted, sentrysql attempts to detect the system from the driver registration name. For OpenDB / WrapDriver / WrapConnector this option is required because the driver name is not available to the wrapper.
func WithDatabaseUser ¶
WithDatabaseUser sets the db.user span attribute.
func WithDriverName ¶
WithDriverName sets the db.driver.name span attribute. Open and Register populate this automatically from the registered driver name; pass it explicitly when using OpenDB / WrapDriver / WrapConnector.
func WithServerAddress ¶
WithServerAddress sets the server.address (logical hostname) and server.port (logical port) span attributes. Pass port = 0 to omit it.
func WithServerSocketAddress ¶
WithServerSocketAddress sets the server.socket.address (physical IP or Unix socket path) and server.socket.port (physical port) span attributes. Pass port = 0 to omit it.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
fakedriver
Package fakedriver is a minimal in-memory database/sql driver used by the sentrysql tests.
|
Package fakedriver is a minimal in-memory database/sql driver used by the sentrysql tests. |