2021-08-09 07:19:24 +00:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2024-08-19 08:01:33 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2021-08-09 07:19:24 +00:00
|
|
|
|
|
|
|
package attribute // import "go.opentelemetry.io/otel/attribute"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// KeyValue holds a key and value pair.
|
|
|
|
type KeyValue struct {
|
|
|
|
Key Key
|
|
|
|
Value Value
|
|
|
|
}
|
|
|
|
|
|
|
|
// Valid returns if kv is a valid OpenTelemetry attribute.
|
|
|
|
func (kv KeyValue) Valid() bool {
|
2023-02-01 17:06:36 +00:00
|
|
|
return kv.Key.Defined() && kv.Value.Type() != INVALID
|
2021-08-09 07:19:24 +00:00
|
|
|
}
|
|
|
|
|
2023-02-01 17:06:36 +00:00
|
|
|
// Bool creates a KeyValue with a BOOL Value type.
|
2021-08-09 07:19:24 +00:00
|
|
|
func Bool(k string, v bool) KeyValue {
|
|
|
|
return Key(k).Bool(v)
|
|
|
|
}
|
|
|
|
|
2023-02-01 17:06:36 +00:00
|
|
|
// BoolSlice creates a KeyValue with a BOOLSLICE Value type.
|
|
|
|
func BoolSlice(k string, v []bool) KeyValue {
|
|
|
|
return Key(k).BoolSlice(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Int creates a KeyValue with an INT64 Value type.
|
|
|
|
func Int(k string, v int) KeyValue {
|
|
|
|
return Key(k).Int(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// IntSlice creates a KeyValue with an INT64SLICE Value type.
|
|
|
|
func IntSlice(k string, v []int) KeyValue {
|
|
|
|
return Key(k).IntSlice(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Int64 creates a KeyValue with an INT64 Value type.
|
2021-08-09 07:19:24 +00:00
|
|
|
func Int64(k string, v int64) KeyValue {
|
|
|
|
return Key(k).Int64(v)
|
|
|
|
}
|
|
|
|
|
2023-02-01 17:06:36 +00:00
|
|
|
// Int64Slice creates a KeyValue with an INT64SLICE Value type.
|
|
|
|
func Int64Slice(k string, v []int64) KeyValue {
|
|
|
|
return Key(k).Int64Slice(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Float64 creates a KeyValue with a FLOAT64 Value type.
|
2021-08-09 07:19:24 +00:00
|
|
|
func Float64(k string, v float64) KeyValue {
|
|
|
|
return Key(k).Float64(v)
|
|
|
|
}
|
|
|
|
|
2023-02-01 17:06:36 +00:00
|
|
|
// Float64Slice creates a KeyValue with a FLOAT64SLICE Value type.
|
|
|
|
func Float64Slice(k string, v []float64) KeyValue {
|
|
|
|
return Key(k).Float64Slice(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// String creates a KeyValue with a STRING Value type.
|
2021-08-09 07:19:24 +00:00
|
|
|
func String(k, v string) KeyValue {
|
|
|
|
return Key(k).String(v)
|
|
|
|
}
|
|
|
|
|
2023-02-01 17:06:36 +00:00
|
|
|
// StringSlice creates a KeyValue with a STRINGSLICE Value type.
|
|
|
|
func StringSlice(k string, v []string) KeyValue {
|
|
|
|
return Key(k).StringSlice(v)
|
|
|
|
}
|
|
|
|
|
2021-08-09 07:19:24 +00:00
|
|
|
// Stringer creates a new key-value pair with a passed name and a string
|
|
|
|
// value generated by the passed Stringer interface.
|
|
|
|
func Stringer(k string, v fmt.Stringer) KeyValue {
|
|
|
|
return Key(k).String(v.String())
|
|
|
|
}
|