1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3 4 package attribute // import "go.opentelemetry.io/otel/attribute"
5 6 // Key represents the key part in key-value pairs. It's a string. The
7 // allowed character set in the key depends on the use of the key.
8 type Key string
9 10 // Bool creates a KeyValue instance with a BOOL Value.
11 //
12 // If creating both a key and value at the same time, use the provided
13 // convenience function instead -- Bool(name, value).
14 func (k Key) Bool(v bool) KeyValue {
15 return KeyValue{
16 Key: k,
17 Value: BoolValue(v),
18 }
19 }
20 21 // BoolSlice creates a KeyValue instance with a BOOLSLICE Value.
22 //
23 // If creating both a key and value at the same time, use the provided
24 // convenience function instead -- BoolSlice(name, value).
25 func (k Key) BoolSlice(v []bool) KeyValue {
26 return KeyValue{
27 Key: k,
28 Value: BoolSliceValue(v),
29 }
30 }
31 32 // Int creates a KeyValue instance with an INT64 Value.
33 //
34 // If creating both a key and value at the same time, use the provided
35 // convenience function instead -- Int(name, value).
36 func (k Key) Int(v int) KeyValue {
37 return KeyValue{
38 Key: k,
39 Value: IntValue(v),
40 }
41 }
42 43 // IntSlice creates a KeyValue instance with an INT64SLICE Value.
44 //
45 // If creating both a key and value at the same time, use the provided
46 // convenience function instead -- IntSlice(name, value).
47 func (k Key) IntSlice(v []int) KeyValue {
48 return KeyValue{
49 Key: k,
50 Value: IntSliceValue(v),
51 }
52 }
53 54 // Int64 creates a KeyValue instance with an INT64 Value.
55 //
56 // If creating both a key and value at the same time, use the provided
57 // convenience function instead -- Int64(name, value).
58 func (k Key) Int64(v int64) KeyValue {
59 return KeyValue{
60 Key: k,
61 Value: Int64Value(v),
62 }
63 }
64 65 // Int64Slice creates a KeyValue instance with an INT64SLICE Value.
66 //
67 // If creating both a key and value at the same time, use the provided
68 // convenience function instead -- Int64Slice(name, value).
69 func (k Key) Int64Slice(v []int64) KeyValue {
70 return KeyValue{
71 Key: k,
72 Value: Int64SliceValue(v),
73 }
74 }
75 76 // Float64 creates a KeyValue instance with a FLOAT64 Value.
77 //
78 // If creating both a key and value at the same time, use the provided
79 // convenience function instead -- Float64(name, value).
80 func (k Key) Float64(v float64) KeyValue {
81 return KeyValue{
82 Key: k,
83 Value: Float64Value(v),
84 }
85 }
86 87 // Float64Slice creates a KeyValue instance with a FLOAT64SLICE Value.
88 //
89 // If creating both a key and value at the same time, use the provided
90 // convenience function instead -- Float64(name, value).
91 func (k Key) Float64Slice(v []float64) KeyValue {
92 return KeyValue{
93 Key: k,
94 Value: Float64SliceValue(v),
95 }
96 }
97 98 // String creates a KeyValue instance with a STRING Value.
99 //
100 // If creating both a key and value at the same time, use the provided
101 // convenience function instead -- String(name, value).
102 func (k Key) String(v string) KeyValue {
103 return KeyValue{
104 Key: k,
105 Value: StringValue(v),
106 }
107 }
108 109 // StringSlice creates a KeyValue instance with a STRINGSLICE Value.
110 //
111 // If creating both a key and value at the same time, use the provided
112 // convenience function instead -- StringSlice(name, value).
113 func (k Key) StringSlice(v []string) KeyValue {
114 return KeyValue{
115 Key: k,
116 Value: StringSliceValue(v),
117 }
118 }
119 120 // Defined reports whether the key is not empty.
121 func (k Key) Defined() bool {
122 return len(k) != 0
123 }
124