New: ServiceBase migrated from shortener

This commit is contained in:
2026-06-04 22:14:42 +02:00
parent 36267b0bba
commit de9ddabd8c
7 changed files with 342 additions and 0 deletions

22
database/postgres.go Normal file
View File

@@ -0,0 +1,22 @@
package database
import (
"database/sql"
"github.com/uptrace/opentelemetry-go-extra/otelsql"
"go.opentelemetry.io/otel/attribute"
)
// OpenPostgres establishes a connection to a Postgres database and enables OpenTelemetry tracing and stats reporting.
func OpenPostgres(dbURL string) (*sql.DB, error) {
db, err := otelsql.Open("postgres", dbURL)
if err != nil {
return nil, err
}
otelsql.ReportDBStatsMetrics(db, otelsql.WithAttributes(
attribute.String("db.system", "postgresql"),
))
return db, nil
}