Debian Codegraph @

otelconf/internal/kv/keyvalue.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 // Package kv contains function to translate name value pairs into
5 // attribute.KeyValue.
6 package kv // import "go.opentelemetry.io/contrib/otelconf/internal/kv"
7
8 import (
9 "fmt"
10 "strconv"
11
12 "go.opentelemetry.io/otel/attribute"
13 )
14
15 func FromNameValue(k string, v any) attribute.KeyValue {
16 switch val := v.(type) {
17 case bool:
18 return attribute.Bool(k, val)
19 case int64:
20 return attribute.Int64(k, val)
21 case uint64:
22 return attribute.String(k, strconv.FormatUint(val, 10))
23 case float64:
24 return attribute.Float64(k, val)
25 case int8:
26 return attribute.Int64(k, int64(val))
27 case uint8:
28 return attribute.Int64(k, int64(val))
29 case int16:
30 return attribute.Int64(k, int64(val))
31 case uint16:
32 return attribute.Int64(k, int64(val))
33 case int32:
34 return attribute.Int64(k, int64(val))
35 case uint32:
36 return attribute.Int64(k, int64(val))
37 case float32:
38 return attribute.Float64(k, float64(val))
39 case int:
40 return attribute.Int(k, val)
41 case uint:
42 return attribute.String(k, strconv.FormatUint(uint64(val), 10))
43 case string:
44 return attribute.String(k, val)
45 default:
46 return attribute.String(k, fmt.Sprint(v))
47 }
48 }