| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry" |
| 5 |
|
| 6 |
// Attr is a key-value pair. |
| 7 |
type Attr struct { |
| 8 |
Key string `json:"key,omitempty"` |
| 9 |
Value Value `json:"value,omitempty"` |
| 10 |
} |
| 11 |
|
| 12 |
// String returns an Attr for a string value. |
| 13 |
func String(key, value string) Attr { |
| 14 |
return Attr{key, StringValue(value)} |
| 15 |
} |
| 16 |
|
| 17 |
// Int64 returns an Attr for an int64 value. |
| 18 |
func Int64(key string, value int64) Attr { |
| 19 |
return Attr{key, Int64Value(value)} |
| 20 |
} |
| 21 |
|
| 22 |
// Int returns an Attr for an int value. |
| 23 |
func Int(key string, value int) Attr { |
| 24 |
return Int64(key, int64(value)) |
| 25 |
} |
| 26 |
|
| 27 |
// Float64 returns an Attr for a float64 value. |
| 28 |
func Float64(key string, value float64) Attr { |
| 29 |
return Attr{key, Float64Value(value)} |
| 30 |
} |
| 31 |
|
| 32 |
// Bool returns an Attr for a bool value. |
| 33 |
func Bool(key string, value bool) Attr { |
| 34 |
return Attr{key, BoolValue(value)} |
| 35 |
} |
| 36 |
|
| 37 |
// Bytes returns an Attr for a []byte value. |
| 38 |
// The passed slice must not be changed after it is passed. |
| 39 |
func Bytes(key string, value []byte) Attr { |
| 40 |
return Attr{key, BytesValue(value)} |
| 41 |
} |
| 42 |
|
| 43 |
// Slice returns an Attr for a []Value value. |
| 44 |
// The passed slice must not be changed after it is passed. |
| 45 |
func Slice(key string, value ...Value) Attr { |
| 46 |
return Attr{key, SliceValue(value...)} |
| 47 |
} |
| 48 |
|
| 49 |
// Map returns an Attr for a map value. |
| 50 |
// The passed slice must not be changed after it is passed. |
| 51 |
func Map(key string, value ...Attr) Attr { |
| 52 |
return Attr{key, MapValue(value...)} |
| 53 |
} |
| 54 |
|
| 55 |
// Equal reports whether a is equal to b. |
| 56 |
func (a Attr) Equal(b Attr) bool { |
| 57 |
return a.Key == b.Key && a.Value.Equal(b.Value) |
| 58 |
} |