helix

PostgreSQL

The postgres integration provides an opinionated way to interact with PostgreSQL as OLTP database for helix services.

The integration works with all PostgreSQL-compatible databases, such as:

Trace attributes

The postgres integration sets the following trace attributes:

  • postgres.database
  • span.kind

When applicable, these attributes can be set as well:

  • postgres.query
  • postgres.batch.length
  • postgres.transaction.query
  • postgres.transaction.batch.length

Example:

postgres.database: "my_db"
postgres.query: "SELECT id, username FROM users;"
span.kind: "server"

Usage

The integration uses the jackc/pgx Go library.

Install the Go module with:

$ go get go.nunchi.studio/helix/integration/postgres

Simple example on how to import, configure, and use the integration:

import (
  "context"

  "go.nunchi.studio/helix/integration/postgres"
  "go.nunchi.studio/helix/service"
)

func main() {
  cfg := postgres.Config{
    Address:  "127.0.0.1:5432",
    Database: "my_db",
    User:     "username",
    Password: "password",
  }

  db, err := postgres.Connect(cfg)
  if err != nil {
    return err
  }

  ctx := context.Background()
  rows, err := db.Query(ctx, "QUERY", args...)
  if err != nil {
    // ...
  }

  defer rows.Close()
  for rows.Next() {
    // ...
  }

  if err := service.Start(); err != nil {
    panic(err)
  }

  if err := service.Close(); err != nil {
    panic(err)
  }
}

Is something missing?

Built by
Nunchi