pppgsql

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: 7 Imported by: 1

README

pppgsql

This package instruments the lib/pq package.

Installation

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

Usage

PkgGoDev

This package instruments the postgres driver calls. Use this package's driver in place of the postgres driver.

db, err := sql.Open("pq-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")
import (
    pinpoint "github.com/pinpoint-apm/pinpoint-go-agent"
    "github.com/pinpoint-apm/pinpoint-go-agent/plugin/http"
    _ "github.com/pinpoint-apm/pinpoint-go-agent/plugin/pgsql"
)

func query(w http.ResponseWriter, r *http.Request) {
    db, err := sql.Open("pq-pinpoint", "postgresql://test:test!@localhost/testdb?sslmode=disable")
    row := db.QueryRowContext(r.Context(), "SELECT count(*) FROM pg_catalog.pg_tables")

    var count int
    err = row.Scan(&count)
    fmt.Println("number of entries in pg_catalog.pg_tables", count)
}

Full Example Source

Documentation

Overview

Package pppgsql instruments the lib/pq package (https://github.com/lib/pq).

This package instruments the postgres driver calls. Use this package's driver in place of the postgres driver.

db, err := sql.Open("pq-pinpoint", "postgresql://testuser:p123@localhost/testdb?sslmode=disable")

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")

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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