firebirdotel

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 26 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

firebirdsql-otel

OpenTelemetry instrumentation for the Go Firebird driver nakagami/firebirdsql v0.9.21. Uses OpenTelemetry Go v1.44.0 and requires Go 1.27.1 or later.

Quick start

Initialize OpenTelemetry in your application as usual. Enable instrumentation once at startup, then use the returned driver name in your existing database setup:

driverName, err := firebirdotel.Instrument()
if err != nil {
    return err
}

// Your ordinary database/sql setup.
db, err := sql.Open(driverName, dsn)
if err != nil {
    return err
}
defer db.Close()

// Existing queries use the request context.
_, err = db.ExecContext(ctx, "execute procedure BILL_UPDATE(?)", id)

Imports: database/sql and firebirdotel "github.com/Makarechi/firebirdsql-otel". See the complete example.

Instrument() needs no configuration object. It uses the application's global OTel providers and adds child spans to the trace in the query context, records operation duration metrics, and sanitizes SQL before exporting it. Attributes include db.system.name=firebirdsql, db.operation.name, and sanitized db.query.text. Bind values and raw error messages are never exported.

Your application keeps its connection settings, pool limits, startup checks and shutdown. Reuse the returned driver name; registration lasts until process exit. Frameworks such as GORM can use the same name as their DriverName. Instrumentation is attached before creating *sql.DB; database/sql cannot change the driver of an already-open pool.

Optional features

  • Frameworks, connectors and pool statistics.
  • Custom telemetry settings, privacy and compatibility. Use RegisterWithConfig only when you need overrides such as pool labels or specific providers. Existing Open/Register APIs retain their legacy behavior.
  • Server diagnostics: metadata, MON$, Trace and Profiler. A configured server Trace collector adds plan and procedure spans. Profiling requires the separate Config.Profiler.Enabled switch, which defaults to false even when a Profiler starter is supplied. Ordinary client tracing is enabled by default; the application owns the server collector lifecycle. Nested server spans connect observed procedure, function and trigger calls to the application's client span.

Development

go test -race ./...
go vet ./...

CI also tests against an isolated Firebird 5.0.3 database. See validation and measured costs, design decisions, and handoff coverage.

Documentation

Overview

Code generated by internal/generate/capabilities.py; DO NOT EDIT.

Code generated by internal/generate/capabilities.py; DO NOT EDIT.

Code generated by internal/generate/capabilities.py; DO NOT EDIT.

Package firebirdotel provides OpenTelemetry instrumentation helpers for the github.com/nakagami/firebirdsql database/sql driver.

Index

Constants

View Source
const (
	// DriverName is the standard driver name registered by github.com/nakagami/firebirdsql.
	DriverName = "firebirdsql"

	// CreateDBDriverName is the create-database driver name registered by github.com/nakagami/firebirdsql.
	CreateDBDriverName = "firebirdsql_createdb"
)

Variables

View Source
var ErrInstrumentation = errors.New("firebirdotel: instrumentation failure")

ErrInstrumentation identifies a failure to initialize telemetry, not a database error.

Functions

func AttributesFromDSN

func AttributesFromDSN(dsn string) []attribute.KeyValue

AttributesFromDSN returns best-effort network attributes parsed from dsn.

func DefaultAttributes

func DefaultAttributes(dsn string) []attribute.KeyValue

DefaultAttributes returns Firebird database semantic attributes plus best-effort network attributes parsed from dsn.

func ErrorAttributes added in v0.1.2

func ErrorAttributes(err error) []attribute.KeyValue

ErrorAttributes returns bounded codes, never err.Error(), Message, Params or wrapped messages.

func Instrument added in v0.1.2

func Instrument() (string, error)

Instrument enables safe Firebird query spans and operation duration metrics using the application's global OpenTelemetry providers. Pass the returned driver name to the existing sql.Open or framework setup. Call once at startup and reuse the name; the application still owns connections and pool settings. For optional telemetry overrides, use RegisterWithConfig.

func Open

func Open(dsn string, options ...Option) (*sql.DB, error)

Open opens an instrumented Firebird database handle.

func OpenCreateDB

func OpenCreateDB(dsn string, options ...Option) (*sql.DB, error)

OpenCreateDB opens an instrumented Firebird create-database handle.

func OpenDB

func OpenDB(connector driver.Connector, options ...Option) *sql.DB

OpenDB wraps a driver connector in OpenTelemetry instrumentation.

func OpenDBWithConfig added in v0.1.2

func OpenDBWithConfig(connector driver.Connector, c Config) (*sql.DB, error)

OpenDBWithConfig takes an uninstrumented, client-dialect-3 connector. Call Raw to access native connections.

func OpenDBWithDSN

func OpenDBWithDSN(connector driver.Connector, dsn string, options ...Option) *sql.DB

OpenDBWithDSN wraps a driver connector and also derives network attributes from dsn.

func OpenWithConfig added in v0.1.2

func OpenWithConfig(dsn string, c Config) (*sql.DB, error)

OpenWithConfig opts into safe instrumentation. The zero Config is safe_client. SQL descriptions use client dialect 3, as does the pinned Firebird driver.

func OpenWithDriver

func OpenWithDriver(driverName, dsn string, options ...Option) (*sql.DB, error)

OpenWithDriver opens an instrumented database handle using a registered driver.

This is useful for tests and for applications that register a custom Firebird driver name.

func OpenWithDriverConfig added in v0.1.2

func OpenWithDriverConfig(d driver.Driver, dsn string, c Config) (*sql.DB, error)

OpenWithDriverConfig accepts an explicit driver using client dialect 3. DriverContext factories run exactly once; named compatibility APIs are unchanged.

func Raw added in v0.1.2

func Raw(conn *sql.Conn, fn func(any) error) error

Raw calls fn with the underlying connection only while database/sql holds it. The connection must not be retained after fn returns; the same contract as sql.Conn.Raw applies.

func Register

func Register(options ...Option) (string, error)

Register registers an instrumented wrapper around the Firebird driver and returns the generated driver name.

Prefer Open when each sql.DB handle has a known DSN. Register is useful for frameworks that need a driver name before calling sql.Open themselves.

func RegisterCreateDB

func RegisterCreateDB(options ...Option) (string, error)

RegisterCreateDB registers an instrumented wrapper around the create-database driver.

func RegisterDBStatsMetrics

func RegisterDBStatsMetrics(db *sql.DB, dsn string, options ...Option) (metric.Registration, error)

RegisterDBStatsMetrics registers database/sql pool statistics metrics for db.

func RegisterDBStatsMetricsWithConfig added in v0.1.2

func RegisterDBStatsMetricsWithConfig(db *sql.DB, c Config) (metric.Registration, error)

RegisterDBStatsMetricsWithConfig registers pool statistics using metric dimensions only. Keep the registration and call Unregister before closing the providers.

func RegisterWithConfig added in v0.1.2

func RegisterWithConfig(c Config) (string, error)

RegisterWithConfig registers instrumented Firebird and returns a driver name for the application's existing sql.Open or framework configuration. It does not connect to Firebird, configure a pool, or register pool statistics. The zero Config enables safe tracing and operation metrics with global providers. Register once at startup per telemetry configuration and reuse the name: database/sql registrations last for the lifetime of the process. Use Register for the legacy compatibility profile.

func RegisterWithDriver

func RegisterWithDriver(driverName, dsn string, options ...Option) (string, error)

RegisterWithDriver registers an instrumented wrapper around driverName.

func WithOperationHint added in v0.1.2

func WithOperationHint(ctx context.Context, h OperationHint) context.Context

WithOperationHint adds a trusted object name, never SQL or argument values. Invalid identifiers are ignored. The executed SQL is unchanged.

func WrapConnector added in v0.1.2

func WrapConnector(connector driver.Connector, c Config) (driver.Connector, error)

WrapConnector requires client dialect 3, preserves optional driver interfaces and does not create global registrations.

Types

type AttributesGetter

type AttributesGetter = otelsql.AttributesGetter

AttributesGetter returns span attributes for a database/sql operation.

type ClientDiagnosticsConfig added in v0.1.2

type ClientDiagnosticsConfig struct {
	Rows                          bool
	Connect, Prepare, Reset, Ping bool
	// Filter receives a bounded, sanitized description, before execution. It cannot select by duration.
	Filter func(context.Context, Operation) bool
}

type Config added in v0.1.2

type Config struct {
	// ServerTrace optionally associates sampled operations with a separately started
	// server collector. It adds a reserved session marker query before execution.
	ServerTrace    ServerTrace
	Profiler       ProfilerConfig
	Profile        Profile
	SQL            SQLPolicy
	Connection     ConnectionAttributes
	Client         ClientDiagnosticsConfig
	TracerProvider trace.TracerProvider
	MeterProvider  metric.MeterProvider
	// SpanAttributes are never copied to metric dimensions. Caller-supplied attributes are trusted.
	SpanAttributes []attribute.KeyValue
	// MetricAttributes must be a bounded, low-cardinality vocabulary chosen by the application.
	MetricAttributes []attribute.KeyValue
	// OTelOptions are accepted only by Compatibility. Safe modes reject opaque callbacks/options.
	OTelOptions []Option
}

func CompatibilityConfig added in v0.1.2

func CompatibilityConfig(options ...Option) Config

CompatibilityConfig retains the original otelsql behavior, including its SQL/error policy.

func DiagnosticConfig added in v0.1.2

func DiagnosticConfig() Config

func SafeConfig added in v0.1.2

func SafeConfig() Config

type ConnectionAttributes added in v0.1.2

type ConnectionAttributes struct {
	// Namespace is an explicitly chosen logical alias, never inferred from a file path.
	Namespace string
	Host      string
	Port      int
	// ParseDSNNetwork enables conservative host/port extraction. No username/path is exported.
	ParseDSNNetwork bool
}

type InstrumentAttributesGetter

type InstrumentAttributesGetter = otelsql.InstrumentAttributesGetter

InstrumentAttributesGetter returns metric attributes for a successful operation.

type InstrumentErrorAttributesGetter

type InstrumentErrorAttributesGetter = otelsql.InstrumentErrorAttributesGetter

InstrumentErrorAttributesGetter returns metric attributes for a failed operation.

type Method

type Method = otelsql.Method

Method is the database/sql operation name passed to span name formatters.

type Operation added in v0.1.2

type Operation struct{ Method, Name, Summary, Procedure string }

type OperationHint added in v0.1.2

type OperationHint struct{ Procedure string }

type Option

type Option = otelsql.Option

Option configures OpenTelemetry behavior.

func WithAttributes

func WithAttributes(attributes ...attribute.KeyValue) Option

WithAttributes adds static attributes to spans and metrics.

func WithAttributesGetter

func WithAttributesGetter(getter AttributesGetter) Option

WithAttributesGetter configures per-operation span attributes.

func WithDefaultAttributes

func WithDefaultAttributes(dsn string) Option

WithDefaultAttributes adds Firebird database semantic attributes and best-effort network attributes parsed from dsn.

func WithInstrumentAttributesGetter

func WithInstrumentAttributesGetter(getter InstrumentAttributesGetter) Option

WithInstrumentAttributesGetter configures per-operation metric attributes.

func WithInstrumentErrorAttributesGetter

func WithInstrumentErrorAttributesGetter(getter InstrumentErrorAttributesGetter) Option

WithInstrumentErrorAttributesGetter configures per-operation metric error attributes.

func WithMeterProvider

func WithMeterProvider(provider metric.MeterProvider) Option

WithMeterProvider configures the meter provider used by metrics.

func WithSQLCommenter

func WithSQLCommenter(enabled bool) Option

WithSQLCommenter enables SQLCommenter trace context injection.

func WithSpanNameFormatter

func WithSpanNameFormatter(formatter SpanNameFormatter) Option

WithSpanNameFormatter configures span names.

func WithSpanOptions

func WithSpanOptions(options SpanOptions) Option

WithSpanOptions configures which database/sql operations create spans.

func WithTracerProvider

func WithTracerProvider(provider trace.TracerProvider) Option

WithTracerProvider configures the tracer provider used by spans.

type Profile added in v0.1.2

type Profile string
const (
	Compatibility Profile = "compatibility"
	SafeClient    Profile = "safe_client"
	Diagnostic    Profile = "diagnostic"
)

type ProfilerConfig added in v0.3.0

type ProfilerConfig struct {
	Enabled bool
	Starter fbprofiler.Starter
}

ProfilerConfig keeps Firebird Profiler opt-in even when a Starter is supplied. Profiling follows the application's existing trace sampling decision.

type RowsColumnTypeDatabaseTypeNameMethods added in v0.1.2

type RowsColumnTypeDatabaseTypeNameMethods interface{ ColumnTypeDatabaseTypeName(int) string }

type RowsColumnTypeLengthMethods added in v0.1.2

type RowsColumnTypeLengthMethods interface{ ColumnTypeLength(int) (int64, bool) }

type RowsColumnTypeNullableMethods added in v0.1.2

type RowsColumnTypeNullableMethods interface{ ColumnTypeNullable(int) (bool, bool) }

type RowsColumnTypePrecisionScaleMethods added in v0.1.2

type RowsColumnTypePrecisionScaleMethods interface {
	ColumnTypePrecisionScale(int) (int64, int64, bool)
}

type RowsColumnTypeScanTypeMethods added in v0.1.2

type RowsColumnTypeScanTypeMethods interface{ ColumnTypeScanType(int) reflect.Type }

type RowsNextResultSetMethods added in v0.1.2

type RowsNextResultSetMethods interface {
	HasNextResultSet() bool
	NextResultSet() error
}

type SQLMode added in v0.1.2

type SQLMode string
const (
	SQLOff         SQLMode = "off"
	SQLSanitized   SQLMode = "sanitized"
	SQLRawExplicit SQLMode = "raw_explicit"
)

type SQLPolicy added in v0.1.2

type SQLPolicy struct {
	Mode                          SQLMode
	MaxInputBytes, MaxOutputBytes int
}

type ServerTrace added in v0.1.2

type ServerTrace interface {
	Register(trace.SpanContext) string
	Bind(string, trace.SpanContext)
	Discard(string)
}

type SpanNameFormatter

type SpanNameFormatter = otelsql.SpanNameFormatter

SpanNameFormatter formats span names.

type SpanOptions

type SpanOptions = otelsql.SpanOptions

SpanOptions controls which database/sql operations create spans.

Directories

Path Synopsis
examples
basic command
benchmark command
Run only against testdata/firebird5.
Run only against testdata/firebird5.
profiler command
A manual Firebird 5 profiling scope.
A manual Firebird 5 profiling scope.
safe command
internal
otelsqlfirebird
Package otelsqlfirebird is a regression fixture for coincidental package names.
Package otelsqlfirebird is a regression fixture for coincidental package names.
sqltext
Package sqltext implements bounded, fail-closed Firebird SQL descriptions.
Package sqltext implements bounded, fail-closed Firebird SQL descriptions.
traceparse
Package traceparse parses a bounded subset of Firebird 5 text Trace.
Package traceparse parses a bounded subset of Firebird 5 text Trace.
Package metadata reads possible schema dependencies.
Package metadata reads possible schema dependencies.
Package monitoring reads one scoped MON$ snapshot per owned transaction.
Package monitoring reads one scoped MON$ snapshot per owned transaction.
Package profiler collects Firebird 5 record-source measurements for sampled SQL operations.
Package profiler collects Firebird 5 record-source measurements for sampled SQL operations.
Package trace provides an experimental in-process Firebird Trace collector.
Package trace provides an experimental in-process Firebird Trace collector.

Jump to

Keyboard shortcuts

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