otelpgxpool

package module
v0.0.0-...-f58ca84 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

README

Go Reference

otelpgx

Provides OpenTelemetry instrumentation for the jackc/pgx library.

It has support for otelpgx which the library is based on.

Requirements

  • go 1.21 (or higher)
  • pgx v5 (or higher)

Usage

Install the library:

go get github.com/quantumsheep/otelpgxpool

Create the tracer as part of your connection:

cfg, err := pgxpool.ParseConfig(connString)
if err != nil {
    return nil, fmt.Errorf("create connection pool: %w", err)
}

cfg.ConnConfig.Tracer = otelpgx.NewTracer()

conn, err := pgxpool.NewWithConfig(ctx, cfg)
if err != nil {
    return nil, fmt.Errorf("connect to database: %w", err)
}

See options.go for the full list of options.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option specifies instrumentation configuration options.

func WithAttributes

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

WithAttributes specifies additional attributes to be added to the span.

func WithOtelPgxTracer

func WithOtelPgxTracer(tracer *otelpgx.Tracer) Option

WithOtelPgxTracer specifies an otelpgx.Tracer to use for tracing pgx queries.

func WithTracerProvider

func WithTracerProvider(provider trace.TracerProvider) Option

WithTracerProvider specifies a tracer provider to use for creating a tracer. If none is specified, the global provider is used.

type OtelPgxTracer

type OtelPgxTracer = otelpgx.Tracer

type Tracer

type Tracer struct {
	*OtelPgxTracer
	// contains filtered or unexported fields
}

Tracer is a wrapper around the pgx tracer interfaces which instrument queries.

func NewTracer

func NewTracer(opts ...Option) *Tracer

NewTracer returns a new Tracer.

func (*Tracer) TraceAcquireEnd

func (t *Tracer) TraceAcquireEnd(ctx context.Context, pool *pgxpool.Pool, data pgxpool.TraceAcquireEndData)

TraceAcquireEnd is called when a connection has been acquired.

func (*Tracer) TraceAcquireStart

func (t *Tracer) TraceAcquireStart(ctx context.Context, pool *pgxpool.Pool, data pgxpool.TraceAcquireStartData) context.Context

TraceAcquireStart is called at the beginning of Acquire. The returned context is used for the rest of the call and will be passed to the TraceAcquireEnd.

Jump to

Keyboard shortcuts

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