fixup finish
Some checks failed
build / test (push) Failing after 1m21s
codeql / analyze (go) (push) Failing after 1m51s
build / lint (push) Successful in 9m15s

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2024-03-15 11:34:31 +03:00
parent 742b86f128
commit 6b9edf3593

View File

@ -118,23 +118,29 @@ func (os *otSpan) Tracer() tracer.Tracer {
} }
func (os *otSpan) Finish(opts ...tracer.SpanOption) { func (os *otSpan) Finish(opts ...tracer.SpanOption) {
if len(os.opts.Labels)%2 != 0 { options := os.opts
os.opts.Labels = os.opts.Labels[:len(os.opts.Labels)-1] for _, o := range opts {
o(&options)
} }
os.opts.Labels = tracer.UniqLabels(os.opts.Labels)
for idx := 0; idx < len(os.opts.Labels); idx += 2 { l := len(options.Labels)
k, ok := os.opts.Labels[idx].(string) for idx := 0; idx < len(options.Labels); idx++ {
if !ok { switch lt := options.Labels[idx].(type) {
continue 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 { if os.status == tracer.SpanStatusError {
os.span.SetTag("error", true) os.span.SetTag("error", true)
os.span.LogKV("error", os.statusMsg) os.span.LogKV("error", os.statusMsg)
} }
os.span.SetTag("span.kind", os.opts.Kind) os.span.SetTag("span.kind", options.Kind)
os.span.Finish() os.span.Finish()
} }