pcommon

package
v0.0.0-...-0e6f340 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteSlice

type ByteSlice internal.ByteSlice

ByteSlice represents a []byte slice. The instance of ByteSlice can be assigned to multiple objects since it's immutable.

Must use NewByteSlice function to create new instances. Important: zero-initialized instance is not valid for use.

func NewByteSlice

func NewByteSlice() ByteSlice

NewByteSlice creates a new empty ByteSlice.

func (ByteSlice) Append

func (ms ByteSlice) Append(elms ...byte)

Append appends extra elements to ByteSlice. Equivalent of byteSlice = append(byteSlice, elms...)

func (ByteSlice) AsRaw

func (ms ByteSlice) AsRaw() []byte

AsRaw returns a copy of the []byte slice.

func (ByteSlice) At

func (ms ByteSlice) At(i int) byte

At returns an item from particular index. Equivalent of byteSlice[i].

func (ByteSlice) CopyTo

func (ms ByteSlice) CopyTo(dest ByteSlice)

CopyTo copies all elements from the current slice overriding the destination.

func (ByteSlice) EnsureCapacity

func (ms ByteSlice) EnsureCapacity(newCap int)

EnsureCapacity ensures ByteSlice has at least the specified capacity.

  1. If the newCap <= cap, then is no change in capacity.
  2. If the newCap > cap, then the slice capacity will be expanded to the provided value which will be equivalent of: buf := make([]byte, len(byteSlice), newCap) copy(buf, byteSlice) byteSlice = buf

func (ByteSlice) FromRaw

func (ms ByteSlice) FromRaw(val []byte)

FromRaw copies raw []byte into the slice ByteSlice.

func (ByteSlice) Len

func (ms ByteSlice) Len() int

Len returns length of the []byte slice value. Equivalent of len(byteSlice).

func (ByteSlice) MoveTo

func (ms ByteSlice) MoveTo(dest ByteSlice)

MoveTo moves all elements from the current slice overriding the destination and resetting the current instance to its zero value.

func (ByteSlice) SetAt

func (ms ByteSlice) SetAt(i int, val byte)

SetAt sets byte item at particular index. Equivalent of byteSlice[i] = val

type Float64Slice

type Float64Slice internal.Float64Slice

Float64Slice represents a []float64 slice. The instance of Float64Slice can be assigned to multiple objects since it's immutable.

Must use NewFloat64Slice function to create new instances. Important: zero-initialized instance is not valid for use.

func NewFloat64Slice

func NewFloat64Slice() Float64Slice

NewFloat64Slice creates a new empty Float64Slice.

func (Float64Slice) Append

func (ms Float64Slice) Append(elms ...float64)

Append appends extra elements to Float64Slice. Equivalent of float64Slice = append(float64Slice, elms...)

func (Float64Slice) AsRaw

func (ms Float64Slice) AsRaw() []float64

AsRaw returns a copy of the []float64 slice.

func (Float64Slice) At

func (ms Float64Slice) At(i int) float64

At returns an item from particular index. Equivalent of float64Slice[i].

func (Float64Slice) CopyTo

func (ms Float64Slice) CopyTo(dest Float64Slice)

CopyTo copies all elements from the current slice overriding the destination.

func (Float64Slice) EnsureCapacity

func (ms Float64Slice) EnsureCapacity(newCap int)

EnsureCapacity ensures Float64Slice has at least the specified capacity.

  1. If the newCap <= cap, then is no change in capacity.
  2. If the newCap > cap, then the slice capacity will be expanded to the provided value which will be equivalent of: buf := make([]float64, len(float64Slice), newCap) copy(buf, float64Slice) float64Slice = buf

func (Float64Slice) FromRaw

func (ms Float64Slice) FromRaw(val []float64)

FromRaw copies raw []float64 into the slice Float64Slice.

func (Float64Slice) Len

func (ms Float64Slice) Len() int

Len returns length of the []float64 slice value. Equivalent of len(float64Slice).

func (Float64Slice) MoveTo

func (ms Float64Slice) MoveTo(dest Float64Slice)

MoveTo moves all elements from the current slice overriding the destination and resetting the current instance to its zero value.

func (Float64Slice) SetAt

func (ms Float64Slice) SetAt(i int, val float64)

SetAt sets float64 item at particular index. Equivalent of float64Slice[i] = val

type InstrumentationScope

type InstrumentationScope internal.InstrumentationScope

InstrumentationScope is a message representing the instrumentation scope information.

This is a reference type, if passed by value and callee modifies it the caller will see the modification.

Must use NewInstrumentationScope function to create new instances. Important: zero-initialized instance is not valid for use.

func NewInstrumentationScope

func NewInstrumentationScope() InstrumentationScope

NewInstrumentationScope creates a new empty InstrumentationScope.

This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, OR directly access the member if this is embedded in another struct.

func (InstrumentationScope) Attributes

func (ms InstrumentationScope) Attributes() Map

Attributes returns the Attributes associated with this InstrumentationScope.

func (InstrumentationScope) CopyTo

CopyTo copies all properties from the current struct overriding the destination.

func (InstrumentationScope) DroppedAttributesCount

func (ms InstrumentationScope) DroppedAttributesCount() uint32

DroppedAttributesCount returns the droppedattributescount associated with this InstrumentationScope.

func (InstrumentationScope) MoveTo

MoveTo moves all properties from the current struct overriding the destination and resetting the current instance to its zero value

func (InstrumentationScope) Name

func (ms InstrumentationScope) Name() string

Name returns the name associated with this InstrumentationScope.

func (InstrumentationScope) SetDroppedAttributesCount

func (ms InstrumentationScope) SetDroppedAttributesCount(v uint32)

SetDroppedAttributesCount replaces the droppedattributescount associated with this InstrumentationScope.

func (InstrumentationScope) SetName

func (ms InstrumentationScope) SetName(v string)

SetName replaces the name associated with this InstrumentationScope.

func (InstrumentationScope) SetVersion

func (ms InstrumentationScope) SetVersion(v string)

SetVersion replaces the version associated with this InstrumentationScope.

func (InstrumentationScope) Version

func (ms InstrumentationScope) Version() string

Version returns the version associated with this InstrumentationScope.

type Map

type Map internal.Map

Map stores a map of string keys to elements of Value type.

func NewMap

func NewMap() Map

NewMap creates a Map with 0 elements.

func (Map) AsRaw

func (m Map) AsRaw() map[string]any

AsRaw returns a standard go map representation of this Map.

func (Map) Clear

func (m Map) Clear()

Clear erases any existing entries in this Map instance.

func (Map) CopyTo

func (m Map) CopyTo(dest Map)

CopyTo copies all elements from the current map overriding the destination.

func (Map) EnsureCapacity

func (m Map) EnsureCapacity(capacity int)

EnsureCapacity increases the capacity of this Map instance, if necessary, to ensure that it can hold at least the number of elements specified by the capacity argument.

func (Map) FromRaw

func (m Map) FromRaw(rawMap map[string]any) error

FromRaw overrides this Map instance from a standard go map.

func (Map) Get

func (m Map) Get(key string) (Value, bool)

Get returns the Value associated with the key and true. Returned Value is not a copy, it is a reference to the value stored in this map. It is allowed to modify the returned value using Value.Set* functions. Such modification will be applied to the value stored in this map.

If the key does not exist returns an invalid instance of the KeyValue and false. Calling any functions on the returned invalid instance will cause a panic.

func (Map) Len

func (m Map) Len() int

Len returns the length of this map.

Because the Map is represented internally by a slice of pointers, and the data are comping from the wire, it is possible that when iterating using "Range" to get access to fewer elements because nil elements are skipped.

func (Map) PutBool

func (m Map) PutBool(k string, v bool)

PutBool performs the Insert or Update action. The bool Value is inserted to the map that did not originally have the key. The key/value is updated to the map where the key already existed.

func (Map) PutDouble

func (m Map) PutDouble(k string, v float64)

PutDouble performs the Insert or Update action. The double Value is inserted to the map that did not originally have the key. The key/value is updated to the map where the key already existed.

func (Map) PutEmpty

func (m Map) PutEmpty(k string) Value

PutEmpty inserts or updates an empty value to the map under given key and return the updated/inserted value.

func (Map) PutEmptyBytes

func (m Map) PutEmptyBytes(k string) ByteSlice

PutEmptyBytes inserts or updates an empty byte slice under given key and returns it.

func (Map) PutEmptyMap

func (m Map) PutEmptyMap(k string) Map

PutEmptyMap inserts or updates an empty map under given key and returns it.

func (Map) PutEmptySlice

func (m Map) PutEmptySlice(k string) Slice

PutEmptySlice inserts or updates an empty slice under given key and returns it.

func (Map) PutInt

func (m Map) PutInt(k string, v int64)

PutInt performs the Insert or Update action. The int Value is inserted to the map that did not originally have the key. The key/value is updated to the map where the key already existed.

func (Map) PutStr

func (m Map) PutStr(k string, v string)

PutStr performs the Insert or Update action. The Value is inserted to the map that did not originally have the key. The key/value is updated to the map where the key already existed.

func (Map) Range

func (m Map) Range(f func(k string, v Value) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

Example:

sm.Range(func(k string, v Value) bool {
    ...
})

func (Map) Remove

func (m Map) Remove(key string) bool

Remove removes the entry associated with the key and returns true if the key was present in the map, otherwise returns false.

func (Map) RemoveIf

func (m Map) RemoveIf(f func(string, Value) bool)

RemoveIf removes the entries for which the function in question returns true

type Resource

type Resource internal.Resource

Resource is a message representing the resource information.

This is a reference type, if passed by value and callee modifies it the caller will see the modification.

Must use NewResource function to create new instances. Important: zero-initialized instance is not valid for use.

func NewResource

func NewResource() Resource

NewResource creates a new empty Resource.

This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, OR directly access the member if this is embedded in another struct.

func (Resource) Attributes

func (ms Resource) Attributes() Map

Attributes returns the Attributes associated with this Resource.

func (Resource) CopyTo

func (ms Resource) CopyTo(dest Resource)

CopyTo copies all properties from the current struct overriding the destination.

func (Resource) DroppedAttributesCount

func (ms Resource) DroppedAttributesCount() uint32

DroppedAttributesCount returns the droppedattributescount associated with this Resource.

func (Resource) MoveTo

func (ms Resource) MoveTo(dest Resource)

MoveTo moves all properties from the current struct overriding the destination and resetting the current instance to its zero value

func (Resource) SetDroppedAttributesCount

func (ms Resource) SetDroppedAttributesCount(v uint32)

SetDroppedAttributesCount replaces the droppedattributescount associated with this Resource.

type Slice

type Slice internal.Slice

Slice logically represents a slice of Value.

This is a reference type. If passed by value and callee modifies it, the caller will see the modification.

Must use NewSlice function to create new instances. Important: zero-initialized instance is not valid for use.

func NewSlice

func NewSlice() Slice

NewSlice creates a Slice with 0 elements. Can use "EnsureCapacity" to initialize with a given capacity.

func (Slice) AppendEmpty

func (es Slice) AppendEmpty() Value

AppendEmpty will append to the end of the slice an empty Value. It returns the newly added Value.

func (Slice) AsRaw

func (es Slice) AsRaw() []any

AsRaw return []any copy of the Slice.

func (Slice) At

func (es Slice) At(ix int) Value

At returns the element at the given index.

This function is used mostly for iterating over all the values in the slice:

for i := 0; i < es.Len(); i++ {
    e := es.At(i)
    ... // Do something with the element
}

func (Slice) CopyTo

func (es Slice) CopyTo(dest Slice)

CopyTo copies all elements from the current slice overriding the destination.

func (Slice) EnsureCapacity

func (es Slice) EnsureCapacity(newCap int)

EnsureCapacity is an operation that ensures the slice has at least the specified capacity. 1. If the newCap <= cap then no change in capacity. 2. If the newCap > cap then the slice capacity will be expanded to equal newCap.

Here is how a new Slice can be initialized:

es := NewSlice()
es.EnsureCapacity(4)
for i := 0; i < 4; i++ {
    e := es.AppendEmpty()
    // Here should set all the values for e.
}

func (Slice) FromRaw

func (es Slice) FromRaw(rawSlice []any) error

FromRaw copies []any into the Slice.

func (Slice) Len

func (es Slice) Len() int

Len returns the number of elements in the slice.

Returns "0" for a newly instance created with "NewSlice()".

func (Slice) MoveAndAppendTo

func (es Slice) MoveAndAppendTo(dest Slice)

MoveAndAppendTo moves all elements from the current slice and appends them to the dest. The current slice will be cleared.

func (Slice) RemoveIf

func (es Slice) RemoveIf(f func(Value) bool)

RemoveIf calls f sequentially for each element present in the slice. If f returns true, the element is removed from the slice.

type SpanID

type SpanID [8]byte

SpanID is span identifier.

func NewSpanIDEmpty

func NewSpanIDEmpty() SpanID

NewSpanIDEmpty returns a new empty (all zero bytes) SpanID.

func (SpanID) IsEmpty

func (ms SpanID) IsEmpty() bool

IsEmpty returns true if id doesn't contain at least one non-zero byte.

func (SpanID) String

func (ms SpanID) String() string

String returns string representation of the SpanID.

Important: Don't rely on this method to get a string identifier of SpanID, Use hex.EncodeToString explicitly instead. This method meant to implement Stringer interface for display purposes only.

type Timestamp

type Timestamp uint64

Timestamp is a time specified as UNIX Epoch time in nanoseconds since 1970-01-01 00:00:00 +0000 UTC.

func NewTimestampFromTime

func NewTimestampFromTime(t time.Time) Timestamp

NewTimestampFromTime constructs a new Timestamp from the provided time.Time.

func (Timestamp) AsTime

func (ts Timestamp) AsTime() time.Time

AsTime converts this to a time.Time.

func (Timestamp) String

func (ts Timestamp) String() string

String returns the string representation of this in UTC.

type TraceID

type TraceID [16]byte

TraceID is a trace identifier.

func NewTraceIDEmpty

func NewTraceIDEmpty() TraceID

NewTraceIDEmpty returns a new empty (all zero bytes) TraceID.

func (TraceID) IsEmpty

func (ms TraceID) IsEmpty() bool

IsEmpty returns true if id doesn't contain at least one non-zero byte.

func (TraceID) String

func (ms TraceID) String() string

String returns string representation of the TraceID.

Important: Don't rely on this method to get a string identifier of TraceID. Use hex.EncodeToString explicitly instead. This method meant to implement Stringer interface for display purposes only.

type TraceState

type TraceState internal.TraceState

TraceState represents the trace state from the w3c-trace-context.

func NewTraceState

func NewTraceState() TraceState

func (TraceState) AsRaw

func (ms TraceState) AsRaw() string

AsRaw returns the string representation of the tracestate in w3c-trace-context format: https://www.w3.org/TR/trace-context/#tracestate-header

func (TraceState) CopyTo

func (ms TraceState) CopyTo(dest TraceState)

CopyTo copies the TraceState instance overriding the destination.

func (TraceState) FromRaw

func (ms TraceState) FromRaw(v string)

FromRaw copies the string representation in w3c-trace-context format of the tracestate into this TraceState.

func (TraceState) MoveTo

func (ms TraceState) MoveTo(dest TraceState)

MoveTo moves the TraceState instance overriding the destination and resetting the current instance to its zero value.

type UInt64Slice

type UInt64Slice internal.UInt64Slice

UInt64Slice represents a []uint64 slice. The instance of UInt64Slice can be assigned to multiple objects since it's immutable.

Must use NewUInt64Slice function to create new instances. Important: zero-initialized instance is not valid for use.

func NewUInt64Slice

func NewUInt64Slice() UInt64Slice

NewUInt64Slice creates a new empty UInt64Slice.

func (UInt64Slice) Append

func (ms UInt64Slice) Append(elms ...uint64)

Append appends extra elements to UInt64Slice. Equivalent of uInt64Slice = append(uInt64Slice, elms...)

func (UInt64Slice) AsRaw

func (ms UInt64Slice) AsRaw() []uint64

AsRaw returns a copy of the []uint64 slice.

func (UInt64Slice) At

func (ms UInt64Slice) At(i int) uint64

At returns an item from particular index. Equivalent of uInt64Slice[i].

func (UInt64Slice) CopyTo

func (ms UInt64Slice) CopyTo(dest UInt64Slice)

CopyTo copies all elements from the current slice overriding the destination.

func (UInt64Slice) EnsureCapacity

func (ms UInt64Slice) EnsureCapacity(newCap int)

EnsureCapacity ensures UInt64Slice has at least the specified capacity.

  1. If the newCap <= cap, then is no change in capacity.
  2. If the newCap > cap, then the slice capacity will be expanded to the provided value which will be equivalent of: buf := make([]uint64, len(uInt64Slice), newCap) copy(buf, uInt64Slice) uInt64Slice = buf

func (UInt64Slice) FromRaw

func (ms UInt64Slice) FromRaw(val []uint64)

FromRaw copies raw []uint64 into the slice UInt64Slice.

func (UInt64Slice) Len

func (ms UInt64Slice) Len() int

Len returns length of the []uint64 slice value. Equivalent of len(uInt64Slice).

func (UInt64Slice) MoveTo

func (ms UInt64Slice) MoveTo(dest UInt64Slice)

MoveTo moves all elements from the current slice overriding the destination and resetting the current instance to its zero value.

func (UInt64Slice) SetAt

func (ms UInt64Slice) SetAt(i int, val uint64)

SetAt sets uint64 item at particular index. Equivalent of uInt64Slice[i] = val

type Value

type Value internal.Value

Value is a mutable cell containing any value. Typically used as an element of Map or Slice. Must use one of NewValue+ functions below to create new instances.

Intended to be passed by value since internally it is just a pointer to actual value representation. For the same reason passing by value and calling setters will modify the original, e.g.:

func f1(val Value) { val.SetInt(234) }
func f2() {
    v := NewValueStr("a string")
    f1(v)
    _ := v.Type() // this will return ValueTypeInt
}

Important: zero-initialized instance is not valid for use. All Value functions below must be called only on instances that are created via NewValue+ functions.

func NewValueBool

func NewValueBool(v bool) Value

NewValueBool creates a new Value with the given bool value.

func NewValueBytes

func NewValueBytes() Value

NewValueBytes creates a new empty Value of byte type.

func NewValueDouble

func NewValueDouble(v float64) Value

NewValueDouble creates a new Value with the given float64 value.

func NewValueEmpty

func NewValueEmpty() Value

NewValueEmpty creates a new Value with an empty value.

func NewValueInt

func NewValueInt(v int64) Value

NewValueInt creates a new Value with the given int64 value.

func NewValueMap

func NewValueMap() Value

NewValueMap creates a new Value of map type.

func NewValueSlice

func NewValueSlice() Value

NewValueSlice creates a new Value of array type.

func NewValueStr

func NewValueStr(v string) Value

NewValueStr creates a new Value with the given string value.

func (Value) AsRaw

func (v Value) AsRaw() any

func (Value) AsString

func (v Value) AsString() string

AsString converts an OTLP Value object of any type to its equivalent string representation. This differs from Str which only returns a non-empty value if the ValueType is ValueTypeStr.

func (Value) Bool

func (v Value) Bool() bool

Bool returns the bool value associated with this Value. If the Type() is not ValueTypeBool then returns false. Calling this function on zero-initialized Value will cause a panic.

func (Value) Bytes

func (v Value) Bytes() ByteSlice

Bytes returns the ByteSlice value associated with this Value. If the Type() is not ValueTypeBytes then returns an invalid ByteSlice object. Note that using such slice can cause panic.

Calling this function on zero-initialized Value will cause a panic.

func (Value) CopyTo

func (v Value) CopyTo(dest Value)

CopyTo copies the Value instance overriding the destination.

func (Value) Double

func (v Value) Double() float64

Double returns the float64 value associated with this Value. If the Type() is not ValueTypeDouble then returns float64(0). Calling this function on zero-initialized Value will cause a panic.

func (Value) FromRaw

func (v Value) FromRaw(iv any) error

func (Value) Int

func (v Value) Int() int64

Int returns the int64 value associated with this Value. If the Type() is not ValueTypeInt then returns int64(0). Calling this function on zero-initialized Value will cause a panic.

func (Value) Map

func (v Value) Map() Map

Map returns the map value associated with this Value. If the Type() is not ValueTypeMap then returns an invalid map. Note that using such map can cause panic.

Calling this function on zero-initialized Value will cause a panic.

func (Value) SetBool

func (v Value) SetBool(bv bool)

SetBool replaces the bool value associated with this Value, it also changes the type to be ValueTypeBool. Calling this function on zero-initialized Value will cause a panic.

func (Value) SetDouble

func (v Value) SetDouble(dv float64)

SetDouble replaces the float64 value associated with this Value, it also changes the type to be ValueTypeDouble. Calling this function on zero-initialized Value will cause a panic.

func (Value) SetEmptyBytes

func (v Value) SetEmptyBytes() ByteSlice

SetEmptyBytes sets value to an empty byte slice and returns it. Calling this function on zero-initialized Value will cause a panic.

func (Value) SetEmptyMap

func (v Value) SetEmptyMap() Map

SetEmptyMap sets value to an empty map and returns it. Calling this function on zero-initialized Value will cause a panic.

func (Value) SetEmptySlice

func (v Value) SetEmptySlice() Slice

SetEmptySlice sets value to an empty slice and returns it. Calling this function on zero-initialized Value will cause a panic.

func (Value) SetInt

func (v Value) SetInt(iv int64)

SetInt replaces the int64 value associated with this Value, it also changes the type to be ValueTypeInt. Calling this function on zero-initialized Value will cause a panic.

func (Value) SetStr

func (v Value) SetStr(sv string)

SetStr replaces the string value associated with this Value, it also changes the type to be ValueTypeStr. The shorter name is used instead of SetString to avoid implementing fmt.Stringer interface by the corresponding getter method. Calling this function on zero-initialized Value will cause a panic.

func (Value) Slice

func (v Value) Slice() Slice

Slice returns the slice value associated with this Value. If the Type() is not ValueTypeSlice then returns an invalid slice. Note that using such slice can cause panic.

Calling this function on zero-initialized Value will cause a panic.

func (Value) Str

func (v Value) Str() string

Str returns the string value associated with this Value. The shorter name is used instead of String to avoid implementing fmt.Stringer interface. If the Type() is not ValueTypeStr then returns empty string. Calling this function on zero-initialized Value will cause a panic.

func (Value) Type

func (v Value) Type() ValueType

Type returns the type of the value for this Value. Calling this function on zero-initialized Value will cause a panic.

type ValueType

type ValueType int32

ValueType specifies the type of Value.

const (
	ValueTypeEmpty ValueType = iota
	ValueTypeStr
	ValueTypeInt
	ValueTypeDouble
	ValueTypeBool
	ValueTypeMap
	ValueTypeSlice
	ValueTypeBytes
)

func (ValueType) String

func (avt ValueType) String() string

String returns the string representation of the ValueType.

Jump to

Keyboard shortcuts

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