-
Notifications
You must be signed in to change notification settings - Fork 295
/
main.go
53 lines (45 loc) · 1.14 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"context"
"fmt"
"log"
"os"
"time"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/newrelic/go-agent/v3/integrations/nrpgx5"
"github.com/newrelic/go-agent/v3/newrelic"
)
func main() {
cfg, err := pgxpool.ParseConfig("postgres://postgres:postgres@localhost:5432")
if err != nil {
panic(err)
}
cfg.ConnConfig.Tracer = nrpgx5.NewTracer()
db, err := pgxpool.NewWithConfig(context.Background(), cfg)
if err != nil {
panic(err)
}
app, err := newrelic.NewApplication(
newrelic.ConfigAppName("PostgreSQL App"),
newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
newrelic.ConfigDebugLogger(os.Stdout),
)
if err != nil {
panic(err)
}
//
// N.B.: We do not recommend using app.WaitForConnection in production code.
//
app.WaitForConnection(5 * time.Second)
txn := app.StartTransaction("postgresQuery")
ctx := newrelic.NewContext(context.Background(), txn)
row := db.QueryRow(ctx, "SELECT count(*) FROM pg_catalog.pg_tables")
count := 0
err = row.Scan(&count)
if err != nil {
log.Println(err)
}
txn.End()
app.Shutdown(5 * time.Second)
fmt.Println("number of entries in pg_catalog.pg_tables", count)
}