Skip to content

Commit c352499

Browse files
committed
Add db instance name to trace attributes
1 parent ce76473 commit c352499

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

driver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func Wrap(d driver.Driver, options ...TraceOption) driver.Driver {
9494
for _, option := range options {
9595
option(&o)
9696
}
97+
o.DefaultAttributes = append(o.DefaultAttributes, trace.StringAttribute("sql.instance", o.InstanceName))
9798
if o.QueryParams && !o.Query {
9899
o.QueryParams = false
99100
}
@@ -117,6 +118,7 @@ func WrapConn(c driver.Conn, options ...TraceOption) driver.Conn {
117118
for _, option := range options {
118119
option(&o)
119120
}
121+
o.DefaultAttributes = append(o.DefaultAttributes, trace.StringAttribute("sql.instance", o.InstanceName))
120122
return wrapConn(c, o)
121123
}
122124

driver_go1.10.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"context"
77
"database/sql"
88
"database/sql/driver"
9+
10+
"go.opencensus.io/trace"
911
)
1012

1113
var errConnDone = sql.ErrConnDone
@@ -25,6 +27,10 @@ func WrapConnector(dc driver.Connector, options ...TraceOption) driver.Connector
2527
for _, o := range options {
2628
o(&opts)
2729
}
30+
opts.DefaultAttributes = append(
31+
opts.DefaultAttributes,
32+
trace.StringAttribute("sql.instance", opts.InstanceName),
33+
)
2834

2935
return &ocDriver{
3036
parent: dc.Driver(),

0 commit comments

Comments
 (0)