pppgxv5

package module
v1.4.0 Latest Latest
Warning

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

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

README

pppgxv5

This package instruments the jackc/pgx/v5 package.

Installation

$ go get github.com/pinpoint-apm/pinpoint-go-agent/plugin/pgxv5
import "github.com/pinpoint-apm/pinpoint-go-agent/plugin/pgxv5"

Usage

PkgGoDev

This package instruments the jackc/pgx/v5. Use the NewTracer as the pgx.ConnConfig.Tracer.

cfg, err := pgx.ParseConfig("postgresql://test:test!@localhost/testdb?sslmode=disable")
cfg.Tracer = pppgxv5.NewTracer()
conn, err := pgx.ConnectConfig(context.Background(), cfg)

It is necessary to pass the context containing the pinpoint.Tracer to pgx calls.

ctx := pinpoint.NewContext(context.Background(), tracer)
rows := conn.QueryRow(ctx, "SELECT count(*) FROM pg_catalog.pg_tables")
import (
    "github.com/jackc/pgx/v5"
    "github.com/pinpoint-apm/pinpoint-go-agent"
    "github.com/pinpoint-apm/pinpoint-go-agent/plugin/pgxv5"
)

func connect() *pgx.Conn {
    cfg, err := pgx.ParseConfig(connUrl)
    cfg.Tracer = pppgxv5.NewTracer()
    conn, err := pgx.ConnectConfig(context.Background(), cfg)
    return conn
}

func tableCount(w http.ResponseWriter, r *http.Request) {
    dbConn := connect()
    defer dbConn.Close(context.Background())

    tracer := pinpoint.FromContext(r.Context())
    ctx := pinpoint.NewContext(context.Background(), tracer)

    rows := dbConn.QueryRow(ctx, "SELECT count(*) FROM pg_catalog.pg_tables")
    ...
}

Full Example Source

database/sql driver

This package instruments the database/sql driver of pgx calls also. Use this package's driver in place of the pgx driver.

db, err := sql.Open("pgxv5-pinpoint", "postgresql://test:test!@localhost/testdb?sslmode=disable")

It is necessary to pass the context containing the pinpoint.Tracer to all exec and query methods on SQL driver. Spans will be created for queries and other statement executions if the context methods are used, and the context includes a transaction.

ctx := pinpoint.NewContext(context.Background(), tracer)
row := db.QueryRowContext(ctx, "SELECT count(*) FROM pg_catalog.pg_tables")

Documentation

Overview

Package pppgxv5 instruments the jackc/pgx/v5 package (https://github.com/jackc/pgx).

This package instruments the jackc/pgx/v5. Use the NewTracer as the pgx.ConnConfig.Tracer.

cfg, err := pgx.ParseConfig(connUrl)
cfg.Tracer = pppgxv5.NewTracer()
conn, err := pgx.ConnectConfig(context.Background(), cfg)

It is necessary to pass the context containing the pinpoint.Tracer to pgx calls.

This package instruments the database/sql driver of pgx calls also. Use this package's driver in place of the pgx driver.

db, err := sql.Open("pgxv5-pinpoint", connUrl)

It is necessary to pass the context containing the pinpoint.Tracer to all exec and query methods on SQL driver.

ctx := pinpoint.NewContext(context.Background(), tracer)
row := db.QueryRowContext(ctx, "SELECT count(*) FROM pg_catalog.pg_tables")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTracer

func NewTracer() *pgxTracer

NewTracer creates a tracer to instrument jackc/pgx calls.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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