From c94af432a0676303c2b7ed269d6cac3e01f8c7ff Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 12 Mar 2024 12:38:40 +0300 Subject: [PATCH] fixup span tags and logs Signed-off-by: Vasiliy Tolstov --- opentracing.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/opentracing.go b/opentracing.go index 817695d..3f9a715 100644 --- a/opentracing.go +++ b/opentracing.go @@ -122,20 +122,28 @@ func (os *otSpan) Finish(opts ...tracer.SpanOption) { } os.opts.Labels = tracer.UniqLabels(os.opts.Labels) for idx := 0; idx < len(os.opts.Labels); idx += 2 { - switch os.opts.Labels[idx] { + k, ok := os.opts.Labels[idx].(string) + if !ok { + continue + } + v, ok := os.opts.Labels[idx+1].(string) + if !ok { + v = fmt.Sprintf("%v", os.opts.Labels[idx+1]) + } + switch k { case "err": os.status = tracer.SpanStatusError - os.statusMsg = fmt.Sprintf("%v", os.opts.Labels[idx+1]) + os.statusMsg = v case "error": continue case "X-Request-Id", "x-request-id": - os.span.SetTag("x-request-id", os.opts.Labels[idx+1]) + os.span.SetTag("x-request-id", v) case "rpc.call", "rpc.call_type", "rpc.flavor", "rpc.service", "rpc.method", "sdk.database", "db.statement", "db.args", "db.query", "db.method", "messaging.destination.name", "messaging.source.name", "messaging.operation": - os.span.SetTag(fmt.Sprintf("%v", os.opts.Labels[idx]), os.opts.Labels[idx+1]) + os.span.SetTag(k, v) default: - os.span.LogKV(os.opts.Labels[idx], os.opts.Labels[idx+1]) + os.span.LogKV(k, v) } } if os.status == tracer.SpanStatusError {