core

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

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

View Source
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

func (k Key) Bool(v bool) KeyValue

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) Defined

func (k Key) Defined() bool

Defined returns true for non-empty keys.

func (Key) Float32

func (k Key) Float32(v float32) KeyValue

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

func (k Key) Float64(v float64) KeyValue

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

func (k Key) Int(v int) KeyValue

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

func (k Key) Int32(v int32) KeyValue

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

func (k Key) Int64(v int64) KeyValue

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

func (k Key) String(v string) KeyValue

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

func (k Key) Uint(v uint) KeyValue

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

func (k Key) Uint32(v uint32) KeyValue

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).

func (Key) Uint64

func (k Key) Uint64(v uint64) KeyValue

Uint64 creates a KeyValue instance with a UINT64 Value.

If creating both key and a uint64 value at the same time, then instead of calling core.Key(name).Uint64(value) consider using a convenience function provided by the api/key package - key.Uint64(name, value).

type KeyValue

type KeyValue struct {
	Key   Key
	Value Value
}

KeyValue holds a key and value pair.

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

func NewFloat64Number(f float64) Number

NewFloat64Number creates a floating point Number.

func NewInt64Number

func NewInt64Number(i int64) Number

NewInt64Number creates an integral Number.

func NewNumberFromRaw

func NewNumberFromRaw(r uint64) Number

NewNumberFromRaw creates a new Number from a raw value.

func NewUint64Number

func NewUint64Number(u uint64) Number

NewInt64Number creates an integral Number.

func (*Number) AddFloat64

func (n *Number) AddFloat64(f float64)

AddFloat64 assumes that the number contains a float64 and adds the passed float64 to it.

func (*Number) AddFloat64Atomic

func (n *Number) AddFloat64Atomic(f float64)

AddFloat64Atomic assumes that the number contains a float64 and adds the passed float64 to it atomically.

func (*Number) AddInt64

func (n *Number) AddInt64(i int64)

AddInt64 assumes that the number contains an int64 and adds the passed int64 to it.

func (*Number) AddInt64Atomic

func (n *Number) AddInt64Atomic(i int64)

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

func (n *Number) AddUint64(u uint64)

AddUint64 assumes that the number contains a uint64 and adds the passed uint64 to it.

func (*Number) AddUint64Atomic

func (n *Number) AddUint64Atomic(u uint64)

AddUint64Atomic assumes that the number contains a uint64 and atomically adds the passed uint64 to it.

func (*Number) AsFloat64

func (n *Number) AsFloat64() float64

AsFloat64 assumes that the measurement value contains a float64 and returns it as such.

func (*Number) AsFloat64Atomic

func (n *Number) AsFloat64Atomic() float64

AsFloat64Atomic assumes that the measurement value contains a float64 and returns it as such atomically.

func (*Number) AsFloat64Ptr

func (n *Number) AsFloat64Ptr() *float64

AsFloat64Ptr assumes that the number contains a float64 and returns a pointer to it.

func (*Number) AsInt64

func (n *Number) AsInt64() int64

AsInt64 assumes that the value contains an int64 and returns it as such.

func (*Number) AsInt64Atomic

func (n *Number) AsInt64Atomic() int64

AsInt64Atomic assumes that the number contains an int64 and returns it as such atomically.

func (*Number) AsInt64Ptr

func (n *Number) AsInt64Ptr() *int64

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) AsNumber

func (n *Number) AsNumber() Number

AsNumber gets the Number.

func (*Number) AsNumberAtomic

func (n *Number) AsNumberAtomic() Number

AsNumberAtomic gets the Number atomically.

func (*Number) AsRaw

func (n *Number) AsRaw() uint64

AsRaw gets the uninterpreted raw value. Might be useful for some atomic operations.

func (*Number) AsRawAtomic

func (n *Number) AsRawAtomic() uint64

AsRawAtomic gets the uninterpreted raw value atomically. Might be useful for some atomic operations.

func (*Number) AsRawPtr

func (n *Number) AsRawPtr() *uint64

AsRawPtr gets the pointer to the raw, uninterpreted raw value. Might be useful for some atomic operations.

func (*Number) AsUint64

func (n *Number) AsUint64() uint64

AsUint64 assumes that the value contains an uint64 and returns it as such.

func (*Number) AsUint64Atomic

func (n *Number) AsUint64Atomic() uint64

AsUint64Atomic assumes that the number contains a uint64 and returns it as such atomically.

func (*Number) AsUint64Ptr

func (n *Number) AsUint64Ptr() *uint64

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

func (n *Number) CompareAndSwapFloat64(of, nf float64) bool

CompareAndSwapFloat64 assumes that this number contains a float64 and does the atomic CAS operation on it.

func (*Number) CompareAndSwapInt64

func (n *Number) CompareAndSwapInt64(oi, ni int64) bool

CompareAndSwapInt64 assumes that this number contains an int64 and does the atomic CAS operation on it.

func (*Number) CompareAndSwapNumber

func (n *Number) CompareAndSwapNumber(on, nn Number) bool

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

func (n *Number) CompareAndSwapRaw(or, nr uint64) bool

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

func (n *Number) CompareAndSwapUint64(ou, nu uint64) bool

CompareAndSwapUint64 assumes that this number contains a uint64 and does the atomic CAS operation on it.

func (*Number) CompareFloat64

func (n *Number) CompareFloat64(f float64) int

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

func (n *Number) CompareInt64(i int64) int

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

func (n *Number) CompareUint64(u uint64) int

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

func (n *Number) SetFloat64(f float64)

SetFloat64 assumes that the number contains a float64 and sets it to the passed value.

func (*Number) SetFloat64Atomic

func (n *Number) SetFloat64Atomic(f float64)

SetFloat64Atomic assumes that the number contains a float64 and sets it to the passed value atomically.

func (*Number) SetInt64

func (n *Number) SetInt64(i int64)

SetInt64 assumes that the number contains an int64 and sets it to the passed value.

func (*Number) SetInt64Atomic

func (n *Number) SetInt64Atomic(i int64)

SetInt64Atomic assumes that the number contains an int64 and sets it to the passed value atomically.

func (*Number) SetNumber

func (n *Number) SetNumber(nn Number)

SetNumber sets the number to the passed number. Both should be of the same kind.

func (*Number) SetNumberAtomic

func (n *Number) SetNumberAtomic(nn Number)

SetNumberAtomic sets the number to the passed number atomically. Both should be of the same kind.

func (*Number) SetRaw

func (n *Number) SetRaw(r uint64)

SetRaw sets the number to the passed raw value. Both number and the raw number should represent the same kind.

func (*Number) SetRawAtomic

func (n *Number) SetRawAtomic(r uint64)

SetRawAtomic sets the number to the passed raw value atomically. Both number and the raw number should represent the same kind.

func (*Number) SetUint64

func (n *Number) SetUint64(u uint64)

SetUint64 assumes that the number contains a uint64 and sets it to the passed value.

func (*Number) SetUint64Atomic

func (n *Number) SetUint64Atomic(u uint64)

SetUint64Atomic assumes that the number contains a uint64 and sets it to the passed value atomically.

func (*Number) SwapFloat64

func (n *Number) SwapFloat64(f float64) float64

SwapFloat64 assumes that the number contains an float64, sets it to the passed value and returns the old float64 value.

func (*Number) SwapFloat64Atomic

func (n *Number) SwapFloat64Atomic(f float64) float64

SwapFloat64Atomic assumes that the number contains an float64, sets it to the passed value and returns the old float64 value atomically.

func (*Number) SwapInt64

func (n *Number) SwapInt64(i int64) int64

SwapInt64 assumes that the number contains an int64, sets it to the passed value and returns the old int64 value.

func (*Number) SwapInt64Atomic

func (n *Number) SwapInt64Atomic(i int64) int64

SwapInt64Atomic assumes that the number contains an int64, sets it to the passed value and returns the old int64 value atomically.

func (*Number) SwapNumber

func (n *Number) SwapNumber(nn Number) Number

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

func (n *Number) SwapNumberAtomic(nn Number) Number

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

func (n *Number) SwapRaw(r uint64) uint64

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

func (n *Number) SwapRawAtomic(r uint64) uint64

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

func (n *Number) SwapUint64(u uint64) uint64

SwapUint64 assumes that the number contains an uint64, sets it to the passed value and returns the old uint64 value.

func (*Number) SwapUint64Atomic

func (n *Number) SwapUint64Atomic(u uint64) uint64

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

type SpanContext struct {
	TraceID    TraceID
	SpanID     SpanID
	TraceFlags byte
}

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

func SpanIDFromHex(h string) (SpanID, error)

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

func (s SpanID) IsValid() bool

IsValid checks whether the span ID is valid. A valid span ID does not consist of zeros only.

func (SpanID) MarshalJSON

func (s SpanID) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom marshal function to encode SpanID as a hex string.

func (SpanID) String added in v0.4.3

func (s SpanID) String() string

String returns the hex string representation form of a SpanID

type TraceID

type TraceID [16]byte

TraceID is a unique identity of a trace.

func TraceIDFromHex

func TraceIDFromHex(h string) (TraceID, error)

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

func (t TraceID) IsValid() bool

IsValid checks whether the trace ID is valid. A valid trace ID does not consist of zeros only.

func (TraceID) MarshalJSON

func (t TraceID) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom marshal function to encode TraceID as a hex string.

func (TraceID) String added in v0.4.3

func (t TraceID) String() string

String returns the hex string representation form of a TraceID

type Value

type Value struct {
	// contains filtered or unexported fields
}

Value represents the value part in key-value pairs.

func Bool

func Bool(v bool) Value

Bool creates a BOOL Value.

func Float32

func Float32(v float32) Value

Float32 creates a FLOAT32 Value.

func Float64

func Float64(v float64) Value

Float64 creates a FLOAT64 Value.

func Int

func Int(v int) Value

Int creates either an INT32 or an INT64 Value, depending on whether the int type is 32 or 64 bits wide.

func Int32

func Int32(v int32) Value

Int32 creates an INT32 Value.

func Int64

func Int64(v int64) Value

Int64 creates an INT64 Value.

func String

func String(v string) Value

String creates a STRING Value.

func Uint

func Uint(v uint) Value

Uint creates either a UINT32 or a UINT64 Value, depending on whether the uint type is 32 or 64 bits wide.

func Uint32

func Uint32(v uint32) Value

Uint32 creates a UINT32 Value.

func Uint64

func Uint64(v uint64) Value

Uint64 creates a UINT64 Value.

func (Value) AsBool

func (v Value) AsBool() bool

AsBool returns the bool value. Make sure that the Value's type is BOOL.

func (Value) AsFloat32

func (v Value) AsFloat32() float32

AsFloat32 returns the float32 value. Make sure that the Value's type is FLOAT32.

func (Value) AsFloat64

func (v Value) AsFloat64() float64

AsFloat64 returns the float64 value. Make sure that the Value's type is FLOAT64.

func (Value) AsInt32

func (v Value) AsInt32() int32

AsInt32 returns the int32 value. Make sure that the Value's type is INT32.

func (Value) AsInt64

func (v Value) AsInt64() int64

AsInt64 returns the int64 value. Make sure that the Value's type is INT64.

func (Value) AsInterface

func (v Value) AsInterface() interface{}

AsInterface returns Value's data as interface{}.

func (Value) AsString

func (v Value) AsString() string

AsString returns the string value. Make sure that the Value's type is STRING.

func (Value) AsUint32

func (v Value) AsUint32() uint32

AsUint32 returns the uint32 value. Make sure that the Value's type is UINT32.

func (Value) AsUint64

func (v Value) AsUint64() uint64

AsUint64 returns the uint64 value. Make sure that the Value's type is UINT64.

func (Value) Emit

func (v Value) Emit() string

Emit returns a string representation of Value's data.

func (Value) MarshalJSON added in v0.1.1

func (v Value) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the Value.

func (Value) Type

func (v Value) Type() ValueType

Type returns a type 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.
)

func (ValueType) String

func (i ValueType) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL