From 6b9edf3593d666064b1bc015daf2ba591b06b0b6 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 15 Mar 2024 11:34:31 +0300 Subject: [PATCH] fixup finish Signed-off-by: Vasiliy Tolstov --- opentracing.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/opentracing.go b/opentracing.go index 4c47ae7..8e930b7 100644 --- a/opentracing.go +++ b/opentracing.go @@ -118,23 +118,29 @@ func (os *otSpan) Tracer() tracer.Tracer { } func (os *otSpan) Finish(opts ...tracer.SpanOption) { - if len(os.opts.Labels)%2 != 0 { - os.opts.Labels = os.opts.Labels[:len(os.opts.Labels)-1] + options := os.opts + for _, o := range opts { + o(&options) } - os.opts.Labels = tracer.UniqLabels(os.opts.Labels) - for idx := 0; idx < len(os.opts.Labels); idx += 2 { - k, ok := os.opts.Labels[idx].(string) - if !ok { - continue + + l := len(options.Labels) + for idx := 0; idx < len(options.Labels); idx++ { + switch lt := options.Labels[idx].(type) { + case attribute.KeyValue: + os.span.SetTag(string(lt.Key), lt.Value.AsInterface()) + case string: + if l < idx+1 { + os.span.SetTag(lt, options.Labels[idx+1]) + idx++ + } } - v := os.opts.Labels[idx+1] - os.span.SetTag(k, v) } + if os.status == tracer.SpanStatusError { os.span.SetTag("error", true) os.span.LogKV("error", os.statusMsg) } - os.span.SetTag("span.kind", os.opts.Kind) + os.span.SetTag("span.kind", options.Kind) os.span.Finish() }