From 731f0bdb6be56dfe0b5a5a79582161bc7fbed32b Mon Sep 17 00:00:00 2001 From: Aaron Beitch Date: Mon, 24 Jun 2024 16:22:22 -0700 Subject: [PATCH] gohbase: Add table and key attributes to span 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". --- internal/observability/observability.go | 3 +-- rpc.go | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/observability/observability.go b/internal/observability/observability.go index 7f2a1def..e1e59d1f 100644 --- a/internal/observability/observability.go +++ b/internal/observability/observability.go @@ -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 diff --git a/rpc.go b/rpc.go index b13e5788..666ce404 100644 --- a/rpc.go +++ b/rpc.go @@ -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" ) @@ -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 {