| 1 | // Copyright 2026 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package otelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/ |
| 6 | |
| 7 | import ( |
| 8 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 9 | |
| 10 | "golang.org/x/tools/internal/event/keysscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/" |
| 11 | "golang.org/x/tools/internal/event/labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/" |
| 12 | ) |
| 13 | |
| 14 | // labelToAttribute converts a label to an OTLP attribute. |
| 15 | // It returns false if the label has no value. |
| 16 | func labelToAttributescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/labelToAttribute().(l labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/.Labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Label#) (otlpAttributescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#, bool) { |
| 17 | key := l.Keyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Label#Key().() |
| 18 | var v otlpAttributeValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue# |
| 19 | |
| 20 | switch key := key.(type) { |
| 21 | case *keysscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/.Intscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/Int#: |
| 22 | v = otlpAttributeValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#{IntValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#IntValue.: varOfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/varOf().(intAsStringscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/intAsString#(key.Fromscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/Int#From().(l)))} |
| 23 | case *keysscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/.Uintscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/Uint#: |
| 24 | v = otlpAttributeValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#{IntValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#IntValue.: varOfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/varOf().(intAsStringscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/intAsString#(key.Fromscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/Uint#From().(l)))} |
| 25 | case *keysscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/.Floatscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/Float#: |
| 26 | v = otlpAttributeValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#{DoubleValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#DoubleValue.: varOfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/varOf().(key.Fromscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/Float#From().(l))} |
| 27 | case *keysscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/String#: |
| 28 | v = otlpAttributeValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#{StringValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#StringValue.: varOfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/varOf().(key.Fromscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/String#From().(l))} |
| 29 | case *keysscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/.Errorscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/Error#: |
| 30 | if err := key.Fromscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/Error#From().(l); err != nil { |
| 31 | v = otlpAttributeValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#{StringValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#StringValue.: varOfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/varOf().(err.Error())} |
| 32 | } |
| 33 | case *keysscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/.Valuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/Value#: |
| 34 | v = otlpAttributeValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#{StringValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#StringValue.: varOfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/varOf().(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprint().(key.Fromscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/Value#From().(l)))} |
| 35 | default: |
| 36 | if l.Validscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Label#Valid().() { |
| 37 | v = otlpAttributeValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#{StringValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#StringValue.: varOfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/varOf().(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprint().(l))} |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | hasValue := v.StringValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#StringValue. != nil || v.IntValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#IntValue. != nil || v.DoubleValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#DoubleValue. != nil |
| 42 | return otlpAttributescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#{Keyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Key.: key.Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Key#Name.(), Valuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Value.: v}, hasValue |
| 43 | } |
| 44 | |
| 45 | // TODO(adonovan): use go1.26 new(expr) |
| 46 | func varOfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/varOf().[T any](x T) *T { return &x } |