pgxotel

package module
v0.0.0-...-755f583 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: MIT Imports: 15 Imported by: 0

README

pgxotel

A Open Telemetry collector for pgx

Getting Started

You can use these examples to get started.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithNextTracer

func WithNextTracer(nextTracer Tracer) queryMeterOption

func WithQueryMeter

func WithQueryMeter(mp metric.MeterProvider) queryMeterOption

Types

type QueryMeter

type QueryMeter struct {
	// contains filtered or unexported fields
}

func NewQueryMeter

func NewQueryMeter(options ...queryMeterOption) (*QueryMeter, error)

func (*QueryMeter) TraceBatchEnd

func (q *QueryMeter) TraceBatchEnd(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchEndData)

func (*QueryMeter) TraceBatchQuery

func (q *QueryMeter) TraceBatchQuery(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchQueryData)

func (*QueryMeter) TraceBatchStart

func (q *QueryMeter) TraceBatchStart(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchStartData) context.Context

func (*QueryMeter) TraceConnectEnd

func (q *QueryMeter) TraceConnectEnd(ctx context.Context, data pgx.TraceConnectEndData)

func (*QueryMeter) TraceConnectStart

func (q *QueryMeter) TraceConnectStart(ctx context.Context, data pgx.TraceConnectStartData) context.Context

func (*QueryMeter) TracePrepareEnd

func (q *QueryMeter) TracePrepareEnd(ctx context.Context, conn *pgx.Conn, data pgx.TracePrepareEndData)

func (*QueryMeter) TracePrepareStart

func (q *QueryMeter) TracePrepareStart(ctx context.Context, conn *pgx.Conn, data pgx.TracePrepareStartData) context.Context

func (*QueryMeter) TraceQueryEnd

func (q *QueryMeter) TraceQueryEnd(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryEndData)

func (*QueryMeter) TraceQueryStart

func (q *QueryMeter) TraceQueryStart(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryStartData) context.Context

type QueryTracer

type QueryTracer struct {
	// Name of the tracer
	Name string
	// Options to provide to the tracer
	Options []trace.TracerOption
}

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

Example
config, err := pgxpool.ParseConfig(os.Getenv("PGX_DATABASE_URL"))
if err != nil {
	panic(err)
}

config.ConnConfig.Tracer = &pgxotel.QueryTracer{
	Name: "example-api",
}

conn, err := pgxpool.NewWithConfig(context.TODO(), config)
if err != nil {
	panic(err)
}
// close the connection
defer conn.Close()

rows, err := conn.Query(context.TODO(), "SELECT * from customer")
if err != nil {
	panic(err)
}
// close the rows
defer rows.Close()

// Customer struct must be defined
type Customer struct {
	FirstName string `db:"first_name"`
	LastName  string `db:"last_name"`
}

for rows.Next() {
	customer, err := pgx.RowToStructByName[Customer](rows)
	if err != nil {
		panic(err)
	}

	fmt.Println(customer.FirstName)
}
Output:

func (*QueryTracer) TraceBatchEnd

func (t *QueryTracer) TraceBatchEnd(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchEndData)

TraceBatchEnd implements pgx.BatchTracer.

func (*QueryTracer) TraceBatchQuery

func (t *QueryTracer) TraceBatchQuery(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchQueryData)

TraceBatchQuery implements pgx.BatchTracer.

func (*QueryTracer) TraceBatchStart

func (t *QueryTracer) TraceBatchStart(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchStartData) context.Context

TraceBatchStart implements pgx.BatchTracer.

func (*QueryTracer) TraceConnectEnd

func (t *QueryTracer) TraceConnectEnd(ctx context.Context, data pgx.TraceConnectEndData)

TraceConnectEnd implements pgx.ConnectTracer.

func (*QueryTracer) TraceConnectStart

func (t *QueryTracer) TraceConnectStart(ctx context.Context, data pgx.TraceConnectStartData) context.Context

TraceConnectStart implements pgx.ConnectTracer.

func (*QueryTracer) TraceCopyFromEnd

func (t *QueryTracer) TraceCopyFromEnd(ctx context.Context, conn *pgx.Conn, data pgx.TraceCopyFromEndData)

TraceCopyFromEnd implements pgx.CopyFromTracer.

func (*QueryTracer) TraceCopyFromStart

func (t *QueryTracer) TraceCopyFromStart(ctx context.Context, conn *pgx.Conn, data pgx.TraceCopyFromStartData) context.Context

TraceCopyFromStart implements pgx.CopyFromTracer.

func (*QueryTracer) TracePrepareEnd

func (t *QueryTracer) TracePrepareEnd(ctx context.Context, conn *pgx.Conn, data pgx.TracePrepareEndData)

TracePrepareEnd implements pgx.PrepareTracer.

func (*QueryTracer) TracePrepareStart

func (t *QueryTracer) TracePrepareStart(ctx context.Context, conn *pgx.Conn, data pgx.TracePrepareStartData) context.Context

TracePrepareStart implements pgx.PrepareTracer.

func (*QueryTracer) TraceQueryEnd

func (t *QueryTracer) TraceQueryEnd(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryEndData)

TraceQueryEnd implements pgx.QueryTracer.

func (*QueryTracer) TraceQueryStart

func (t *QueryTracer) TraceQueryStart(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryStartData) context.Context

TraceQueryStart implements pgx.QueryTracer.

type Tracer

type Tracer interface {
	pgx.QueryTracer
	pgx.BatchTracer
	pgx.ConnectTracer
	pgx.PrepareTracer
}

Jump to

Keyboard shortcuts

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