otel

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package otel provides a Quark Middleware that emits OpenTelemetry tracing spans and metrics for every database operation.

Activation:

client, _ := quark.New("pgx", dsn, quark.WithMiddleware(otel.New()))

The default is span-redaction ON (bind arguments never reach the span; only the parameterised SQL does) and no db.system attribute. Use the Options to opt out of redaction or to tag spans/metrics with a system name:

otel.New(otel.WithSpanRedaction(otel.IncludeArgs), otel.WithDBSystem("postgres"))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware struct {
	quark.BaseMiddleware
	// contains filtered or unexported fields
}

Middleware implements quark.Middleware with OpenTelemetry tracing (spans) and metrics. Instruments are resolved lazily from the global MeterProvider on first use, so the middleware uses whatever provider is registered at query-execution time.

func New

func New(opts ...Option) *Middleware

New creates a new OTel Middleware. Defaults: span redaction ON, no db.system attribute.

func (*Middleware) WrapExec

func (m *Middleware) WrapExec(next quark.ExecFunc) quark.ExecFunc

WrapExec instruments INSERT / UPDATE / DELETE / DDL: span + counter + duration histogram + rows histogram (from sql.Result.RowsAffected when available).

func (*Middleware) WrapQuery

func (m *Middleware) WrapQuery(next quark.QueryFunc) quark.QueryFunc

WrapQuery instruments a multi-row SELECT: span + counter + duration histogram. The rows histogram is NOT emitted here — counting rows would require wrapping *sql.Rows (consumed by the caller via Next / Scan) and is out of scope for F4-1.

func (*Middleware) WrapQueryRow

func (m *Middleware) WrapQueryRow(next quark.QueryRowFunc) quark.QueryRowFunc

WrapQueryRow instruments a single-row SELECT: span + counter + duration histogram. Errors surface only on Scan, so the span has no error status here (mirrors the historical comment). The rows histogram is not emitted (no result handle to consult).

type Option added in v0.8.0

type Option func(*Middleware)

Option configures the OTel Middleware.

func WithDBSystem added in v0.8.0

func WithDBSystem(name string) Option

WithDBSystem sets the value of the db.system attribute on every span and every metric data point (e.g. "postgres", "mysql", "mariadb", "mssql", "oracle", "sqlite"). The Middleware does not introspect the Quark Client; if you want this attribute populated, pass the dialect name when constructing the Middleware. When unset (the default), the attribute is omitted.

func WithSpanRedaction added in v0.8.0

func WithSpanRedaction(mode RedactionMode) Option

WithSpanRedaction sets whether bind args are exposed on spans. The default is RedactArgs (args never reach the span).

type RedactionMode added in v0.8.0

type RedactionMode int

RedactionMode controls whether bind arguments are exposed on the span attributes that the OTel Middleware emits.

const (
	// RedactArgs is the default. Bind arguments are NOT placed on any
	// span attribute — only the parameterised SQL (which already uses
	// ?, $N, @pN or :N placeholders) reaches db.statement. Use this in
	// production: a tracing backend MUST NOT see user values it has no
	// authority to retain.
	RedactArgs RedactionMode = iota

	// IncludeArgs places the bind arguments on the optional
	// db.statement.args attribute (a string slice). Opt in only for
	// local debugging — values render via fmt.Sprintf("%v", arg), with
	// no scrubbing.
	IncludeArgs
)

Jump to

Keyboard shortcuts

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