Skip to content

Commit

Permalink
gohbase: Add table and key attributes to span
Browse files Browse the repository at this point in the history
Improve the observability of RPC spans by including the table and key.
The values are quoted to improve readability of table and key values
that combine printable unicode characters with non-printable raw
binary. For example, "\xc4x03Qux".
  • Loading branch information
aaronbee authored and tsuna committed Jul 15, 2024
1 parent 1504720 commit 731f0bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 1 addition & 2 deletions internal/observability/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ func StartSpan(
name string,
opts ...trace.SpanStartOption,
) (context.Context, trace.Span) {
tracer := otel.GetTracerProvider().Tracer("gohbase")
return tracer.Start(ctx, name, opts...)
return otel.Tracer("gohbase").Start(ctx, name, opts...)
}

// ObserveWithTrace observes the value, providing the traceID as
Expand Down
8 changes: 7 additions & 1 deletion rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import (
"github.com/tsuna/gohbase/internal/observability"
"github.com/tsuna/gohbase/region"
"github.com/tsuna/gohbase/zk"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -76,7 +78,11 @@ func (c *client) getRegionForRpc(ctx context.Context, rpc hrpc.Call) (hrpc.Regio
func (c *client) SendRPC(rpc hrpc.Call) (msg proto.Message, err error) {
start := time.Now()
description := rpc.Description()
ctx, sp := observability.StartSpan(rpc.Context(), description)
ctx, sp := observability.StartSpan(rpc.Context(), description,
trace.WithAttributes(
attribute.String("table", strconv.Quote(string(rpc.Table()))),
attribute.String("key", strconv.Quote(string(rpc.Key()))),
))
defer func() {
result := "ok"
if err != nil {
Expand Down

0 comments on commit 731f0bd

Please sign in to comment.