Documentation ¶
Overview ¶
This package provides basic types used in OpenTelemetry - keys, values, numbers and span contexts.
See the api/key package for convenience functions for creating keys and key-value pairs.
Index ¶
- Constants
- type Key
- func (k Key) Bool(v bool) KeyValue
- func (k Key) Defined() bool
- func (k Key) Float32(v float32) KeyValue
- func (k Key) Float64(v float64) KeyValue
- func (k Key) Int(v int) KeyValue
- func (k Key) Int32(v int32) KeyValue
- func (k Key) Int64(v int64) KeyValue
- func (k Key) String(v string) KeyValue
- func (k Key) Uint(v uint) KeyValue
- func (k Key) Uint32(v uint32) KeyValue
- func (k Key) Uint64(v uint64) KeyValue
- type KeyValue
- type Number
- func (n *Number) AddFloat64(f float64)
- func (n *Number) AddFloat64Atomic(f float64)
- func (n *Number) AddInt64(i int64)
- func (n *Number) AddInt64Atomic(i int64)
- func (n *Number) AddNumber(kind NumberKind, nn Number)
- func (n *Number) AddNumberAtomic(kind NumberKind, nn Number)
- func (n *Number) AddRaw(kind NumberKind, r uint64)
- func (n *Number) AddRawAtomic(kind NumberKind, r uint64)
- func (n *Number) AddUint64(u uint64)
- func (n *Number) AddUint64Atomic(u uint64)
- func (n *Number) AsFloat64() float64
- func (n *Number) AsFloat64Atomic() float64
- func (n *Number) AsFloat64Ptr() *float64
- func (n *Number) AsInt64() int64
- func (n *Number) AsInt64Atomic() int64
- func (n *Number) AsInt64Ptr() *int64
- func (n *Number) AsInterface(kind NumberKind) interface{}
- func (n *Number) AsNumber() Number
- func (n *Number) AsNumberAtomic() Number
- func (n *Number) AsRaw() uint64
- func (n *Number) AsRawAtomic() uint64
- func (n *Number) AsRawPtr() *uint64
- func (n *Number) AsUint64() uint64
- func (n *Number) AsUint64Atomic() uint64
- func (n *Number) AsUint64Ptr() *uint64
- func (n *Number) CoerceToFloat64(kind NumberKind) float64
- func (n *Number) CoerceToInt64(kind NumberKind) int64
- func (n *Number) CoerceToUint64(kind NumberKind) uint64
- func (n *Number) CompareAndSwapFloat64(of, nf float64) bool
- func (n *Number) CompareAndSwapInt64(oi, ni int64) bool
- func (n *Number) CompareAndSwapNumber(on, nn Number) bool
- func (n *Number) CompareAndSwapRaw(or, nr uint64) bool
- func (n *Number) CompareAndSwapUint64(ou, nu uint64) bool
- func (n *Number) CompareFloat64(f float64) int
- func (n *Number) CompareInt64(i int64) int
- func (n *Number) CompareNumber(kind NumberKind, nn Number) int
- func (n *Number) CompareRaw(kind NumberKind, r uint64) int
- func (n *Number) CompareUint64(u uint64) int
- func (n *Number) Emit(kind NumberKind) string
- func (n *Number) IsNegative(kind NumberKind) bool
- func (n *Number) IsPositive(kind NumberKind) bool
- func (n *Number) IsZero(kind NumberKind) bool
- func (n *Number) SetFloat64(f float64)
- func (n *Number) SetFloat64Atomic(f float64)
- func (n *Number) SetInt64(i int64)
- func (n *Number) SetInt64Atomic(i int64)
- func (n *Number) SetNumber(nn Number)
- func (n *Number) SetNumberAtomic(nn Number)
- func (n *Number) SetRaw(r uint64)
- func (n *Number) SetRawAtomic(r uint64)
- func (n *Number) SetUint64(u uint64)
- func (n *Number) SetUint64Atomic(u uint64)
- func (n *Number) SwapFloat64(f float64) float64
- func (n *Number) SwapFloat64Atomic(f float64) float64
- func (n *Number) SwapInt64(i int64) int64
- func (n *Number) SwapInt64Atomic(i int64) int64
- func (n *Number) SwapNumber(nn Number) Number
- func (n *Number) SwapNumberAtomic(nn Number) Number
- func (n *Number) SwapRaw(r uint64) uint64
- func (n *Number) SwapRawAtomic(r uint64) uint64
- func (n *Number) SwapUint64(u uint64) uint64
- func (n *Number) SwapUint64Atomic(u uint64) uint64
- type NumberKind
- type SpanContext
- type SpanID
- type TraceID
- type Value
- func (v Value) AsBool() bool
- func (v Value) AsFloat32() float32
- func (v Value) AsFloat64() float64
- func (v Value) AsInt32() int32
- func (v Value) AsInt64() int64
- func (v Value) AsInterface() interface{}
- func (v Value) AsString() string
- func (v Value) AsUint32() uint32
- func (v Value) AsUint64() uint64
- func (v Value) Emit() string
- func (v Value) MarshalJSON() ([]byte, error)
- func (v Value) Type() ValueType
- type ValueType
Constants ¶
const ( // TraceFlagsSampled is a byte with sampled bit set. It is a convenient value initializer // for SpanContext TraceFlags field when a trace is sampled. TraceFlagsSampled = traceFlagsBitMaskSampled TraceFlagsUnused = traceFlagsBitMaskUnused ErrInvalidHexID errorConst = "trace-id and span-id can only contain [0-9a-f] characters, all lowercase" ErrInvalidTraceIDLength errorConst = "hex encoded trace-id must have length equals to 32" ErrNilTraceID errorConst = "trace-id can't be all zero" ErrInvalidSpanIDLength errorConst = "hex encoded span-id must have length equals to 16" ErrNilSpanID errorConst = "span-id can't be all zero" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Key ¶
type Key string
Key represents the key part in key-value pairs. It's a string. The allowed character set in the key depends on the use of the key.
func (Key) Bool ¶
Bool creates a KeyValue instance with a BOOL Value.
If creating both key and a bool value at the same time, then instead of calling core.Key(name).Bool(value) consider using a convenience function provided by the api/key package - key.Bool(name, value).
func (Key) Float32 ¶
Float32 creates a KeyValue instance with a FLOAT32 Value.
If creating both key and a float32 value at the same time, then instead of calling core.Key(name).Float32(value) consider using a convenience function provided by the api/key package - key.Float32(name, value).
func (Key) Float64 ¶
Float64 creates a KeyValue instance with a FLOAT64 Value.
If creating both key and a float64 value at the same time, then instead of calling core.Key(name).Float64(value) consider using a convenience function provided by the api/key package - key.Float64(name, value).
func (Key) Int ¶
Int creates a KeyValue instance with either an INT32 or an INT64 Value, depending on whether the int type is 32 or 64 bits wide.
If creating both key and an int value at the same time, then instead of calling core.Key(name).Int(value) consider using a convenience function provided by the api/key package - key.Int(name, value).
func (Key) Int32 ¶
Int32 creates a KeyValue instance with an INT32 Value.
If creating both key and an int32 value at the same time, then instead of calling core.Key(name).Int32(value) consider using a convenience function provided by the api/key package - key.Int32(name, value).
func (Key) Int64 ¶
Int64 creates a KeyValue instance with an INT64 Value.
If creating both key and an int64 value at the same time, then instead of calling core.Key(name).Int64(value) consider using a convenience function provided by the api/key package - key.Int64(name, value).
func (Key) String ¶
String creates a KeyValue instance with a STRING Value.
If creating both key and a string value at the same time, then instead of calling core.Key(name).String(value) consider using a convenience function provided by the api/key package - key.String(name, value).
func (Key) Uint ¶
Uint creates a KeyValue instance with either a UINT32 or a UINT64 Value, depending on whether the uint type is 32 or 64 bits wide.
If creating both key and a uint value at the same time, then instead of calling core.Key(name).Uint(value) consider using a convenience function provided by the api/key package - key.Uint(name, value).
func (Key) Uint32 ¶
Uint32 creates a KeyValue instance with a UINT32 Value.
If creating both key and a uint32 value at the same time, then instead of calling core.Key(name).Uint32(value) consider using a convenience function provided by the api/key package - key.Uint32(name, value).
type Number ¶
type Number uint64
Number represents either an integral or a floating point value. It needs to be accompanied with a source of NumberKind that describes the actual type of the value stored within Number.
func NewFloat64Number ¶
NewFloat64Number creates a floating point Number.
func NewInt64Number ¶
NewInt64Number creates an integral Number.
func NewNumberFromRaw ¶
NewNumberFromRaw creates a new Number from a raw value.
func NewUint64Number ¶
NewInt64Number creates an integral Number.
func (*Number) AddFloat64 ¶
AddFloat64 assumes that the number contains a float64 and adds the passed float64 to it.
func (*Number) AddFloat64Atomic ¶
AddFloat64Atomic assumes that the number contains a float64 and adds the passed float64 to it atomically.
func (*Number) AddInt64 ¶
AddInt64 assumes that the number contains an int64 and adds the passed int64 to it.
func (*Number) AddInt64Atomic ¶
AddInt64Atomic assumes that the number contains an int64 and adds the passed int64 to it atomically.
func (*Number) AddNumber ¶
func (n *Number) AddNumber(kind NumberKind, nn Number)
AddNumber assumes that this and the passed number are of the passed kind and adds the passed number to this number.
func (*Number) AddNumberAtomic ¶
func (n *Number) AddNumberAtomic(kind NumberKind, nn Number)
AddNumberAtomic assumes that this and the passed number are of the passed kind and adds the passed number to this number atomically.
func (*Number) AddRaw ¶
func (n *Number) AddRaw(kind NumberKind, r uint64)
AddRaw assumes that this number and the passed raw value are of the passed kind and adds the passed raw value to this number.
func (*Number) AddRawAtomic ¶
func (n *Number) AddRawAtomic(kind NumberKind, r uint64)
AddRawAtomic assumes that this number and the passed raw value are of the passed kind and adds the passed raw value to this number atomically.
func (*Number) AddUint64 ¶
AddUint64 assumes that the number contains a uint64 and adds the passed uint64 to it.
func (*Number) AddUint64Atomic ¶
AddUint64Atomic assumes that the number contains a uint64 and atomically adds the passed uint64 to it.
func (*Number) AsFloat64 ¶
AsFloat64 assumes that the measurement value contains a float64 and returns it as such.
func (*Number) AsFloat64Atomic ¶
AsFloat64Atomic assumes that the measurement value contains a float64 and returns it as such atomically.
func (*Number) AsFloat64Ptr ¶
AsFloat64Ptr assumes that the number contains a float64 and returns a pointer to it.
func (*Number) AsInt64Atomic ¶
AsInt64Atomic assumes that the number contains an int64 and returns it as such atomically.
func (*Number) AsInt64Ptr ¶
AsInt64Ptr assumes that the number contains an int64 and returns a pointer to it.
func (*Number) AsInterface ¶ added in v0.1.1
func (n *Number) AsInterface(kind NumberKind) interface{}
AsInterface returns the number as an interface{}, typically used for NumberKind-correct JSON conversion.
func (*Number) AsNumberAtomic ¶
AsNumberAtomic gets the Number atomically.
func (*Number) AsRaw ¶
AsRaw gets the uninterpreted raw value. Might be useful for some atomic operations.
func (*Number) AsRawAtomic ¶
AsRawAtomic gets the uninterpreted raw value atomically. Might be useful for some atomic operations.
func (*Number) AsRawPtr ¶
AsRawPtr gets the pointer to the raw, uninterpreted raw value. Might be useful for some atomic operations.
func (*Number) AsUint64 ¶
AsUint64 assumes that the value contains an uint64 and returns it as such.
func (*Number) AsUint64Atomic ¶
AsUint64Atomic assumes that the number contains a uint64 and returns it as such atomically.
func (*Number) AsUint64Ptr ¶
AsUint64Ptr assumes that the number contains a uint64 and returns a pointer to it.
func (*Number) CoerceToFloat64 ¶
func (n *Number) CoerceToFloat64(kind NumberKind) float64
CoerceToFloat64 casts the number to float64. May result in data/precision loss.
func (*Number) CoerceToInt64 ¶
func (n *Number) CoerceToInt64(kind NumberKind) int64
CoerceToInt64 casts the number to int64. May result in data/precision loss.
func (*Number) CoerceToUint64 ¶
func (n *Number) CoerceToUint64(kind NumberKind) uint64
CoerceToUint64 casts the number to uint64. May result in data/precision loss.
func (*Number) CompareAndSwapFloat64 ¶
CompareAndSwapFloat64 assumes that this number contains a float64 and does the atomic CAS operation on it.
func (*Number) CompareAndSwapInt64 ¶
CompareAndSwapInt64 assumes that this number contains an int64 and does the atomic CAS operation on it.
func (*Number) CompareAndSwapNumber ¶
CompareAndSwapNumber does the atomic CAS operation on this number. This number and passed old and new numbers should be of the same kind.
func (*Number) CompareAndSwapRaw ¶
CompareAndSwapRaw does the atomic CAS operation on this number. This number and passed old and new raw values should be of the same kind.
func (*Number) CompareAndSwapUint64 ¶
CompareAndSwapUint64 assumes that this number contains a uint64 and does the atomic CAS operation on it.
func (*Number) CompareFloat64 ¶
CompareFloat64 assumes that the Number contains a float64 and performs a comparison between the value and the other value. It returns the typical result of the compare function: -1 if the value is less than the other, 0 if both are equal, 1 if the value is greater than the other.
Do not compare NaN values.
func (*Number) CompareInt64 ¶
CompareInt64 assumes that the Number contains an int64 and performs a comparison between the value and the other value. It returns the typical result of the compare function: -1 if the value is less than the other, 0 if both are equal, 1 if the value is greater than the other.
func (*Number) CompareNumber ¶
func (n *Number) CompareNumber(kind NumberKind, nn Number) int
CompareNumber compares two Numbers given their kind. Both numbers should have the same kind. This returns:
0 if the numbers are equal -1 if the subject `n` is less than the argument `nn` +1 if the subject `n` is greater than the argument `nn`
func (*Number) CompareRaw ¶
func (n *Number) CompareRaw(kind NumberKind, r uint64) int
CompareRaw compares two numbers, where one is input as a raw uint64, interpreting both values as a `kind` of number.
func (*Number) CompareUint64 ¶
CompareUint64 assumes that the Number contains an uint64 and performs a comparison between the value and the other value. It returns the typical result of the compare function: -1 if the value is less than the other, 0 if both are equal, 1 if the value is greater than the other.
func (*Number) Emit ¶
func (n *Number) Emit(kind NumberKind) string
Emit returns a string representation of the raw value of the Number. A %d is used for integral values, %f for floating point values.
func (*Number) IsNegative ¶
func (n *Number) IsNegative(kind NumberKind) bool
IsNegative returns true if the actual value is less than zero.
func (*Number) IsPositive ¶
func (n *Number) IsPositive(kind NumberKind) bool
IsPositive returns true if the actual value is greater than zero.
func (*Number) IsZero ¶
func (n *Number) IsZero(kind NumberKind) bool
IsZero returns true if the actual value is equal to zero.
func (*Number) SetFloat64 ¶
SetFloat64 assumes that the number contains a float64 and sets it to the passed value.
func (*Number) SetFloat64Atomic ¶
SetFloat64Atomic assumes that the number contains a float64 and sets it to the passed value atomically.
func (*Number) SetInt64 ¶
SetInt64 assumes that the number contains an int64 and sets it to the passed value.
func (*Number) SetInt64Atomic ¶
SetInt64Atomic assumes that the number contains an int64 and sets it to the passed value atomically.
func (*Number) SetNumber ¶
SetNumber sets the number to the passed number. Both should be of the same kind.
func (*Number) SetNumberAtomic ¶
SetNumberAtomic sets the number to the passed number atomically. Both should be of the same kind.
func (*Number) SetRaw ¶
SetRaw sets the number to the passed raw value. Both number and the raw number should represent the same kind.
func (*Number) SetRawAtomic ¶
SetRawAtomic sets the number to the passed raw value atomically. Both number and the raw number should represent the same kind.
func (*Number) SetUint64 ¶
SetUint64 assumes that the number contains a uint64 and sets it to the passed value.
func (*Number) SetUint64Atomic ¶
SetUint64Atomic assumes that the number contains a uint64 and sets it to the passed value atomically.
func (*Number) SwapFloat64 ¶
SwapFloat64 assumes that the number contains an float64, sets it to the passed value and returns the old float64 value.
func (*Number) SwapFloat64Atomic ¶
SwapFloat64Atomic assumes that the number contains an float64, sets it to the passed value and returns the old float64 value atomically.
func (*Number) SwapInt64 ¶
SwapInt64 assumes that the number contains an int64, sets it to the passed value and returns the old int64 value.
func (*Number) SwapInt64Atomic ¶
SwapInt64Atomic assumes that the number contains an int64, sets it to the passed value and returns the old int64 value atomically.
func (*Number) SwapNumber ¶
SwapNumber sets the number to the passed number and returns the old number. Both this number and the passed number should be of the same kind.
func (*Number) SwapNumberAtomic ¶
SwapNumberAtomic sets the number to the passed number and returns the old number atomically. Both this number and the passed number should be of the same kind.
func (*Number) SwapRaw ¶
SwapRaw sets the number to the passed raw value and returns the old raw value. Both number and the raw number should represent the same kind.
func (*Number) SwapRawAtomic ¶
SwapRawAtomic sets the number to the passed raw value and returns the old raw value atomically. Both number and the raw number should represent the same kind.
func (*Number) SwapUint64 ¶
SwapUint64 assumes that the number contains an uint64, sets it to the passed value and returns the old uint64 value.
func (*Number) SwapUint64Atomic ¶
SwapUint64Atomic assumes that the number contains an uint64, sets it to the passed value and returns the old uint64 value atomically.
type NumberKind ¶
type NumberKind int8
NumberKind describes the data type of the Number.
const ( // Int64NumberKind means that the Number stores int64. Int64NumberKind NumberKind = iota // Float64NumberKind means that the Number stores float64. Float64NumberKind // Uint64NumberKind means that the Number stores uint64. Uint64NumberKind )
func (NumberKind) Maximum ¶ added in v0.2.0
func (k NumberKind) Maximum() Number
Maximum returns the maximum representable value for a given NumberKind
func (NumberKind) Minimum ¶ added in v0.2.0
func (k NumberKind) Minimum() Number
Minimum returns the minimum representable value for a given NumberKind
func (NumberKind) String ¶
func (i NumberKind) String() string
func (NumberKind) Zero ¶ added in v0.3.0
func (k NumberKind) Zero() Number
Zero returns a zero value for a given NumberKind
type SpanContext ¶
SpanContext contains basic information about the span - its trace ID, span ID and trace flags.
func EmptySpanContext ¶
func EmptySpanContext() SpanContext
EmptySpanContext is meant for internal use to return invalid span context during error conditions.
func (SpanContext) HasSpanID ¶
func (sc SpanContext) HasSpanID() bool
HasSpanID checks if the span context has a valid span ID.
func (SpanContext) HasTraceID ¶
func (sc SpanContext) HasTraceID() bool
HasTraceID checks if the span context has a valid trace ID.
func (SpanContext) IsSampled ¶
func (sc SpanContext) IsSampled() bool
IsSampled check if the sampling bit in trace flags is set.
func (SpanContext) IsValid ¶
func (sc SpanContext) IsValid() bool
IsValid checks if the span context is valid. A valid span context has a valid trace ID and a valid span ID.
type SpanID ¶
type SpanID [8]byte
SpanID is a unique identify of a span in a trace.
func SpanIDFromHex ¶
SpanIDFromHex returns a SpanID from a hex string if it is compliant with the w3c trace-context specification. See more at https://www.w3.org/TR/trace-context/#parent-id
func (SpanID) IsValid ¶
IsValid checks whether the span ID is valid. A valid span ID does not consist of zeros only.
func (SpanID) MarshalJSON ¶
MarshalJSON implements a custom marshal function to encode SpanID as a hex string.
type TraceID ¶
type TraceID [16]byte
TraceID is a unique identity of a trace.
func TraceIDFromHex ¶
TraceIDFromHex returns a TraceID from a hex string if it is compliant with the w3c trace-context specification. See more at https://www.w3.org/TR/trace-context/#trace-id
func (TraceID) IsValid ¶
IsValid checks whether the trace ID is valid. A valid trace ID does not consist of zeros only.
func (TraceID) MarshalJSON ¶
MarshalJSON implements a custom marshal function to encode TraceID as a hex string.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value represents the value part in key-value pairs.
func Int ¶
Int creates either an INT32 or an INT64 Value, depending on whether the int type is 32 or 64 bits wide.
func Uint ¶
Uint creates either a UINT32 or a UINT64 Value, depending on whether the uint type is 32 or 64 bits wide.
func (Value) AsFloat32 ¶
AsFloat32 returns the float32 value. Make sure that the Value's type is FLOAT32.
func (Value) AsFloat64 ¶
AsFloat64 returns the float64 value. Make sure that the Value's type is FLOAT64.
func (Value) AsInterface ¶
func (v Value) AsInterface() interface{}
AsInterface returns Value's data as interface{}.
func (Value) AsString ¶
AsString returns the string value. Make sure that the Value's type is STRING.
func (Value) AsUint32 ¶
AsUint32 returns the uint32 value. Make sure that the Value's type is UINT32.
func (Value) AsUint64 ¶
AsUint64 returns the uint64 value. Make sure that the Value's type is UINT64.
func (Value) MarshalJSON ¶ added in v0.1.1
MarshalJSON returns the JSON encoding of the Value.
type ValueType ¶
type ValueType int
ValueType describes the type of the data Value holds.
const ( INVALID ValueType = iota // No value. BOOL // Boolean value, use AsBool() to get it. INT32 // 32 bit signed integral value, use AsInt32() to get it. INT64 // 64 bit signed integral value, use AsInt64() to get it. UINT32 // 32 bit unsigned integral value, use AsUint32() to get it. UINT64 // 64 bit unsigned integral value, use AsUint64() to get it. FLOAT32 // 32 bit floating point value, use AsFloat32() to get it. FLOAT64 // 64 bit floating point value, use AsFloat64() to get it. STRING // String value, use AsString() to get it. )