sqltracer

package
v0.0.0-...-425f0b4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

sqltracer implements a sql driver that wraps the original driver and adds Sentry tracing capabilities to all queries. The trace is valid if there is a parent span exists in the context.

Please note that when initializing the sqltracer, you will need to specify the `sqltracer.WithDatabaseSystem` option, so that Sentry will picks up the span as a correct query trace.

Example with "github.com/go-sql-driver/mysql" package.

package main

import "github.com/go-sql-driver/mysql"
import "github.com/aldy505/sentry-integration/sqltracer"

func main() {
	sql.Register("sentrymysql", sqltracer.NewSentrySql(&mysql.MySQLDriver{}, sqltracer.WithDatabaseSystem("mysql"), sqltracer.WithDatabaseName("mydb"), sqltracer.WithServerAddress("localhost", "3306")))

	db, err := sql.Open("sentrymysql", "username:password@protocol(address)/dbname?param=value")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSentrySQL

func NewSentrySQL(driver driver.Driver, options ...Option) driver.Driver

NewSentrySQL is a wrapper for driver.Driver that provides tracing for SQL queries. The span will only be created if the parent span is available.

func NewSentrySQLConnector

func NewSentrySQLConnector(connector driver.Connector, options ...Option) driver.Connector

NewSentrySQLConnector is a wrapper for driver.Connector that provides tracing for SQL queries. The span will only be created if the parent span is available.

Types

type DatabaseSystem

type DatabaseSystem string

DatabaseSystem points to the list of accepted OpenTelemetry database system. The ones defined here are not exhaustive, but are the ones that are supported by Sentry. Although you can override the value by creating your own, it will still be sent to Sentry, but it most likely will not appear on the Queries Insights page.

const (
	// PostgreSQL specifies the PostgreSQL database system.
	PostgreSQL DatabaseSystem = "postgresql"
	// MySQL specifies the MySQL database system.
	MySQL DatabaseSystem = "mysql"
	// SQLite specifies the SQLite database system.
	SQLite DatabaseSystem = "sqlite"
	// Oracle specifies the Oracle database system.
	Oracle DatabaseSystem = "oracle"
	// MSSQL specifies the Microsoft SQL Server database system.
	MSSQL DatabaseSystem = "mssql"
)

type Option

type Option func(*sentrySQLConfig)

func WithDatabaseName

func WithDatabaseName(name string) Option

WithDatabaseName specifies the name of the current database.

func WithDatabaseSystem

func WithDatabaseSystem(system DatabaseSystem) Option

WithDatabaseSystem specifies the current database system.

func WithServerAddress

func WithServerAddress(address string, port string) Option

WithServerAddress specifies the address and port of the current database server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL