Skip to content

Commit 2d88ee4

Browse files
feat(product-catalog): add DSN-derived attributes to DB telemetry
Extract connection attributes from the DSN (e.g. host, port) using otelsql.AttributesFromDSN and include them alongside the existing semconv.DBSystemNamePostgreSQL attribute on both spans and DB stats metrics. Note: AttributesFromDSN does not yet extract db.namespace (database name). Co Authored By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1cdd4e0 commit 2d88ee4

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/product-catalog/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,13 @@ func initDatabase() error {
6565
return fmt.Errorf("DB_CONNECTION_STRING environment variable not set")
6666
}
6767

68+
dbAttrs := otelsql.WithAttributes(
69+
append(otelsql.AttributesFromDSN(connStr), semconv.DBSystemNamePostgreSQL)...,
70+
)
71+
6872
var err error
6973
db, err = otelsql.Open("postgres", connStr,
70-
otelsql.WithAttributes(semconv.DBSystemNamePostgreSQL),
74+
dbAttrs,
7175
otelsql.WithSpanOptions(otelsql.SpanOptions{
7276
OmitConnResetSession: true,
7377
OmitRows: true,
@@ -76,7 +80,7 @@ func initDatabase() error {
7680
return fmt.Errorf("failed to open database connection: %w", err)
7781
}
7882

79-
reg, err = otelsql.RegisterDBStatsMetrics(db, otelsql.WithAttributes(semconv.DBSystemNamePostgreSQL))
83+
reg, err = otelsql.RegisterDBStatsMetrics(db, dbAttrs)
8084
if err != nil {
8185
return fmt.Errorf("failed to register database metrics: %w", err)
8286
}

0 commit comments

Comments
 (0)