Skip to content

Commit

Permalink
feat: improve OpenTelemetry keys
Browse files Browse the repository at this point in the history
Use keys from semantic conventions for databases.
  • Loading branch information
ernado committed Mar 11, 2022
1 parent 14c65c1 commit debce0e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/go-faster/errors"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"

Expand Down Expand Up @@ -370,7 +371,7 @@ func Connect(ctx context.Context, conn net.Conn, opt Options) (*Client, error) {
newCtx, span := opt.tracer.Start(ctx, "Connect",
trace.WithSpanKind(trace.SpanKindClient),
trace.WithAttributes(
otelch.DB(opt.Database),
semconv.DBNameKey.String(opt.Database),
),
)
ctx = newCtx
Expand Down
18 changes: 0 additions & 18 deletions otelch/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
const (
QueryIDKey = attribute.Key("ch.query.id")
QuotaKeyKey = attribute.Key("ch.quota.key")
QueryBodyKey = attribute.Key("ch.query.body")
DBKey = attribute.Key("ch.db")
ProtocolVersionKey = attribute.Key("ch.protocol.version")
ServerNameKey = attribute.Key("ch.server.name")
ErrorCodeKey = attribute.Key("ch.error.code")
Expand All @@ -31,22 +29,6 @@ func QuotaKey(v string) attribute.KeyValue {
}
}

// QueryBody attribute.
func QueryBody(v string) attribute.KeyValue {
return attribute.KeyValue{
Key: QueryBodyKey,
Value: attribute.StringValue(v),
}
}

// DB attribute.
func DB(v string) attribute.KeyValue {
return attribute.KeyValue{
Key: DBKey,
Value: attribute.StringValue(v),
}
}

// ProtocolVersion attribute.
func ProtocolVersion(v int) attribute.KeyValue {
return attribute.KeyValue{
Expand Down
6 changes: 5 additions & 1 deletion query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/go-faster/errors"
"github.com/google/uuid"
"go.opentelemetry.io/otel/codes"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
"go.opentelemetry.io/otel/trace"
"go.uber.org/atomic"
"go.uber.org/multierr"
Expand Down Expand Up @@ -506,7 +507,10 @@ func (c *Client) Do(ctx context.Context, q Query) (err error) {
newCtx, span := c.tracer.Start(ctx, "Do",
trace.WithSpanKind(trace.SpanKindClient),
trace.WithAttributes(
otelch.QueryBody(q.Body),
semconv.DBSystemKey.String("clickhouse"),
semconv.DBStatementKey.String(q.Body),
semconv.DBUserKey.String(c.info.User),
semconv.DBNameKey.String(c.info.Database),
otelch.ProtocolVersion(c.protocolVersion),
otelch.QuotaKey(q.QuotaKey),
otelch.QueryID(q.QueryID),
Expand Down

0 comments on commit debce0e

Please sign in to comment.