Movatterモバイル変換


[0]ホーム

URL:


attribute

package
v1.39.0Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License:Apache-2.0, BSD-3-ClauseImports:13Imported by:11,192

Details

Repository

github.com/open-telemetry/opentelemetry-go

Links

README

Attribute

PkgGoDev

Documentation

Overview

Package attribute provides key and value attributes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcNewSetWithFiltered

func NewSetWithFiltered(kvs []KeyValue, filterFilter) (Set, []KeyValue)

NewSetWithFiltered returns a new Set. See the documentation forNewSetWithSortableFiltered for more details.

This call includes a Filter to include/exclude attribute keys from thereturn value. Excluded keys are returned as a slice of attribute values.

funcNewSetWithSortableFiltereddeprecated

func NewSetWithSortableFiltered(kvs []KeyValue, _ *Sortable, filterFilter) (Set, []KeyValue)

NewSetWithSortableFiltered returns a new Set.

Duplicate keys are eliminated by taking the last value. Thisre-orders the input slice so that unique last-values are contiguousat the end of the slice.

This ensures the following:

- Last-value-wins semantics- Caller sees the reordering, but doesn't lose values- Repeated call preserve last-value wins.

Note that methods are defined on Set, although this returns Set. Callerscan avoid memory allocations by:

- allocating a Sortable for use as a temporary in this method- allocating a Set for storing the return value of this constructor.

The result maintains a cache of encoded attributes, by attribute.EncoderID.This value should not be copied after its first use.

The second []KeyValue return value is a list of attributes that wereexcluded by the Filter (if non-nil).

Deprecated: UseNewSetWithFiltered instead.

Types

typeDistinct

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

Distinct is an identifier of a Set which is very likely to be unique.

Distinct should be used as a map key instead of a Set for to provide betterperformance for map operations.

func (Distinct)Valid

func (dDistinct) Valid()bool

Valid reports whether this value refers to a valid Set.

typeEncoder

type Encoder interface {// Encode returns the serialized encoding of the attribute set using// its Iterator. This result may be cached by an attribute.Set.Encode(iteratorIterator)string// ID returns a value that is unique for each class of attribute// encoder. Attribute encoders allocate these using `NewEncoderID`.ID()EncoderID}

Encoder is a mechanism for serializing an attribute set into a specificstring representation that supports caching, to avoid repeatedserialization. An example could be an exporter encoding the attributeset into a wire representation.

funcDefaultEncoder

func DefaultEncoder()Encoder

DefaultEncoder returns an attribute encoder that encodes attributes in sucha way that each escaped attribute's key is followed by an equal sign andthen by an escaped attribute's value. All key-value pairs are separated bya comma.

Escaping is done by prepending a backslash before either a backslash, equalsign or a comma.

typeEncoderID

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

EncoderID is used to identify distinct Encoderimplementations, for caching encoded results.

funcNewEncoderID

func NewEncoderID()EncoderID

NewEncoderID returns a unique attribute encoder ID. It should be calledonce per each type of attribute encoder. Preferably in init() or in vardefinition.

func (EncoderID)Valid

func (idEncoderID) Valid()bool

Valid reports whether this encoder ID was allocated byNewEncoderID. Invalid encoder IDs will not be cached.

typeFilter

type Filter func(KeyValue)bool

Filter supports removing certain attributes from attribute sets. Whenthe filter returns true, the attribute will be kept in the filteredattribute set. When the filter returns false, the attribute is excludedfrom the filtered attribute set, and the attribute instead appears inthe removed list of excluded attributes.

funcNewAllowKeysFilteradded inv1.17.0

func NewAllowKeysFilter(keys ...Key)Filter

NewAllowKeysFilter returns a Filter that only allows attributes with one ofthe provided keys.

If keys is empty a deny-all filter is returned.

funcNewDenyKeysFilteradded inv1.17.0

func NewDenyKeysFilter(keys ...Key)Filter

NewDenyKeysFilter returns a Filter that only allows attributesthat do not have one of the provided keys.

If keys is empty an allow-all filter is returned.

typeIterator

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

Iterator allows iterating over the set of attributes in order, sorted bykey.

func (*Iterator)Attribute

func (i *Iterator) Attribute()KeyValue

Attribute returns the current KeyValue of the Iterator. It must be calledonly after Next returns true.

func (*Iterator)IndexedAttributeadded inv1.7.0

func (i *Iterator) IndexedAttribute() (int,KeyValue)

IndexedAttribute returns current index and attribute. Must be called onlyafter Next returns true.

func (*Iterator)IndexedLabeldeprecated

func (i *Iterator) IndexedLabel() (int,KeyValue)

IndexedLabel returns current index and attribute. Must be called onlyafter Next returns true.

Deprecated: Use IndexedAttribute instead.

func (*Iterator)Labeldeprecated

func (i *Iterator) Label()KeyValue

Label returns current KeyValue. Must be called only after Next returnstrue.

Deprecated: Use Attribute instead.

func (*Iterator)Len

func (i *Iterator) Len()int

Len returns a number of attributes in the iterated set.

func (*Iterator)Next

func (i *Iterator) Next()bool

Next moves the iterator to the next position.Next reports whether there are more attributes.

func (*Iterator)ToSlice

func (i *Iterator) ToSlice() []KeyValue

ToSlice is a convenience function that creates a slice of attributes fromthe passed iterator. The iterator is set up to start from the beginningbefore creating the slice.

typeKey

type Keystring

Key represents the key part in key-value pairs. It's a string. Theallowed character set in the key depends on the use of the key.

func (Key)Bool

func (kKey) Bool(vbool)KeyValue

Bool creates a KeyValue instance with a BOOL Value.

If creating both a key and value at the same time, use the providedconvenience function instead -- Bool(name, value).

func (Key)BoolSliceadded inv1.0.0

func (kKey) BoolSlice(v []bool)KeyValue

BoolSlice creates a KeyValue instance with a BOOLSLICE Value.

If creating both a key and value at the same time, use the providedconvenience function instead -- BoolSlice(name, value).

func (Key)Defined

func (kKey) Defined()bool

Defined reports whether the key is not empty.

func (Key)Float64

func (kKey) Float64(vfloat64)KeyValue

Float64 creates a KeyValue instance with a FLOAT64 Value.

If creating both a key and value at the same time, use the providedconvenience function instead -- Float64(name, value).

func (Key)Float64Sliceadded inv1.0.0

func (kKey) Float64Slice(v []float64)KeyValue

Float64Slice creates a KeyValue instance with a FLOAT64SLICE Value.

If creating both a key and value at the same time, use the providedconvenience function instead -- Float64(name, value).

func (Key)Int

func (kKey) Int(vint)KeyValue

Int creates a KeyValue instance with an INT64 Value.

If creating both a key and value at the same time, use the providedconvenience function instead -- Int(name, value).

func (Key)Int64

func (kKey) Int64(vint64)KeyValue

Int64 creates a KeyValue instance with an INT64 Value.

If creating both a key and value at the same time, use the providedconvenience function instead -- Int64(name, value).

func (Key)Int64Sliceadded inv1.0.0

func (kKey) Int64Slice(v []int64)KeyValue

Int64Slice creates a KeyValue instance with an INT64SLICE Value.

If creating both a key and value at the same time, use the providedconvenience function instead -- Int64Slice(name, value).

func (Key)IntSliceadded inv1.0.0

func (kKey) IntSlice(v []int)KeyValue

IntSlice creates a KeyValue instance with an INT64SLICE Value.

If creating both a key and value at the same time, use the providedconvenience function instead -- IntSlice(name, value).

func (Key)String

func (kKey) String(vstring)KeyValue

String creates a KeyValue instance with a STRING Value.

If creating both a key and value at the same time, use the providedconvenience function instead -- String(name, value).

func (Key)StringSliceadded inv1.0.0

func (kKey) StringSlice(v []string)KeyValue

StringSlice creates a KeyValue instance with a STRINGSLICE Value.

If creating both a key and value at the same time, use the providedconvenience function instead -- StringSlice(name, value).

typeKeyValue

type KeyValue struct {KeyKeyValueValue}

KeyValue holds a key and value pair.

funcBool

func Bool(kstring, vbool)KeyValue

Bool creates a KeyValue with a BOOL Value type.

funcBoolSliceadded inv1.0.0

func BoolSlice(kstring, v []bool)KeyValue

BoolSlice creates a KeyValue with a BOOLSLICE Value type.

funcFloat64

func Float64(kstring, vfloat64)KeyValue

Float64 creates a KeyValue with a FLOAT64 Value type.

funcFloat64Sliceadded inv1.0.0

func Float64Slice(kstring, v []float64)KeyValue

Float64Slice creates a KeyValue with a FLOAT64SLICE Value type.

funcInt

func Int(kstring, vint)KeyValue

Int creates a KeyValue with an INT64 Value type.

funcInt64

func Int64(kstring, vint64)KeyValue

Int64 creates a KeyValue with an INT64 Value type.

funcInt64Sliceadded inv1.0.0

func Int64Slice(kstring, v []int64)KeyValue

Int64Slice creates a KeyValue with an INT64SLICE Value type.

funcIntSliceadded inv1.0.0

func IntSlice(kstring, v []int)KeyValue

IntSlice creates a KeyValue with an INT64SLICE Value type.

funcString

func String(k, vstring)KeyValue

String creates a KeyValue with a STRING Value type.

funcStringSliceadded inv1.0.0

func StringSlice(kstring, v []string)KeyValue

StringSlice creates a KeyValue with a STRINGSLICE Value type.

funcStringer

func Stringer(kstring, vfmt.Stringer)KeyValue

Stringer creates a new key-value pair with a passed name and a stringvalue generated by the passed Stringer interface.

func (KeyValue)Validadded inv0.19.0

func (kvKeyValue) Valid()bool

Valid reports whether kv is a valid OpenTelemetry attribute.

typeMergeIterator

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

MergeIterator supports iterating over two sets of attributes whileeliminating duplicate values from the combined set. The first iteratorvalue takes precedence.

funcNewMergeIterator

func NewMergeIterator(s1, s2 *Set)MergeIterator

NewMergeIterator returns a MergeIterator for merging two attribute sets.Duplicates are resolved by taking the value from the first set.

func (*MergeIterator)Attributeadded inv1.7.0

func (m *MergeIterator) Attribute()KeyValue

Attribute returns the current value after Next() returns true.

func (*MergeIterator)Labeldeprecated

func (m *MergeIterator) Label()KeyValue

Label returns the current value after Next() returns true.

Deprecated: Use Attribute instead.

func (*MergeIterator)Next

func (m *MergeIterator) Next()bool

Next moves the iterator to the next position.Next reports whether there is another attribute available.

typeSet

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

Set is the representation for a distinct attribute set. It manages animmutable set of attributes, with an internal cache for storingattribute encodings.

This type will remain comparable for backwards compatibility. Theequivalence of Sets across versions is not guaranteed to be stable.Prior versions may find two Sets to be equal or not when compareddirectly (i.e. ==), but subsequent versions may not. Users should usethe Equals method to ensure stable equivalence checking.

Users should also use the Distinct returned from Equivalent as a map keyinstead of a Set directly. Set has relatively poor performance when usedas a map key compared to Distinct.

funcEmptySet

func EmptySet() *Set

EmptySet returns a reference to a Set with no elements.

This is a convenience provided for optimized calling utility.

funcNewSet

func NewSet(kvs ...KeyValue)Set

NewSet returns a new Set. See the documentation forNewSetWithSortableFiltered for more details.

Except for empty sets, this method adds an additional allocation comparedwith calls that include a Sortable.

funcNewSetWithSortabledeprecated

func NewSetWithSortable(kvs []KeyValue, _ *Sortable)Set

NewSetWithSortable returns a new Set. See the documentation forNewSetWithSortableFiltered for more details.

This call includes a Sortable option as a memory optimization.

Deprecated: UseNewSet instead.

func (*Set)Encoded

func (l *Set) Encoded(encoderEncoder)string

Encoded returns the encoded form of this set, according to encoder.

func (*Set)Equals

func (l *Set) Equals(o *Set)bool

Equals reports whether the argument set is equivalent to this set.

func (*Set)Equivalent

func (l *Set) Equivalent()Distinct

Equivalent returns a value that may be used as a map key. Equal Distinctvalues are very likely to be equivalent attribute Sets. Distinct value of anyattribute set with the same elements as this, where sets are made unique bychoosing the last value in the input for any given key.

func (*Set)Filter

func (l *Set) Filter(reFilter) (Set, []KeyValue)

Filter returns a filtered copy of this Set. See the documentation forNewSetWithSortableFiltered for more details.

func (*Set)Get

func (l *Set) Get(idxint) (KeyValue,bool)

Get returns the KeyValue at ordered position idx in this set.

func (*Set)HasValue

func (l *Set) HasValue(kKey)bool

HasValue reports whether a key is defined in this set.

func (*Set)Iter

func (l *Set) Iter()Iterator

Iter returns an iterator for visiting the attributes in this set.

func (*Set)Len

func (l *Set) Len()int

Len returns the number of attributes in this set.

func (*Set)MarshalJSON

func (l *Set) MarshalJSON() ([]byte,error)

MarshalJSON returns the JSON encoding of the Set.

func (Set)MarshalLogadded inv1.4.0

func (lSet) MarshalLog()any

MarshalLog is the marshaling function used by the logging system to represent this Set.

func (*Set)ToSlice

func (l *Set) ToSlice() []KeyValue

ToSlice returns the set of attributes belonging to this set, sorted, wherekeys appear no more than once.

func (*Set)Value

func (l *Set) Value(kKey) (Value,bool)

Value returns the value of a specified key in this set.

typeSortabledeprecated

type Sortable []KeyValue

Sortable implements sort.Interface, used for sorting KeyValue.

Deprecated: This type is no longer used. It was added as a performanceoptimization for Go < 1.21 that is no longer needed (Go < 1.21 is nolonger supported by the module).

func (*Sortable)Len

func (l *Sortable) Len()int

Len implements sort.Interface.

func (*Sortable)Less

func (l *Sortable) Less(i, jint)bool

Less implements sort.Interface.

func (*Sortable)Swap

func (l *Sortable) Swap(i, jint)

Swap implements sort.Interface.

typeType

type Typeint// nolint: revive  // redefines builtin Type.

Type describes the type of the data Value holds.

const (// INVALID is used for a Value with no value set.INVALIDType =iota// BOOL is a boolean Type Value.BOOL// INT64 is a 64-bit signed integral Type Value.INT64// FLOAT64 is a 64-bit floating point Type Value.FLOAT64// STRING is a string Type Value.STRING// BOOLSLICE is a slice of booleans Type Value.BOOLSLICE// INT64SLICE is a slice of 64-bit signed integral numbers Type Value.INT64SLICE// FLOAT64SLICE is a slice of 64-bit floating point numbers Type Value.FLOAT64SLICE// STRINGSLICE is a slice of strings Type Value.STRINGSLICE)

func (Type)String

func (iType) String()string

typeValue

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

Value represents the value part in key-value pairs.

funcBoolSliceValueadded inv1.0.0

func BoolSliceValue(v []bool)Value

BoolSliceValue creates a BOOLSLICE Value.

funcBoolValue

func BoolValue(vbool)Value

BoolValue creates a BOOL Value.

funcFloat64SliceValueadded inv1.0.0

func Float64SliceValue(v []float64)Value

Float64SliceValue creates a FLOAT64SLICE Value.

funcFloat64Value

func Float64Value(vfloat64)Value

Float64Value creates a FLOAT64 Value.

funcInt64SliceValueadded inv1.0.0

func Int64SliceValue(v []int64)Value

Int64SliceValue creates an INT64SLICE Value.

funcInt64Value

func Int64Value(vint64)Value

Int64Value creates an INT64 Value.

funcIntSliceValueadded inv1.0.0

func IntSliceValue(v []int)Value

IntSliceValue creates an INTSLICE Value.

funcIntValue

func IntValue(vint)Value

IntValue creates an INT64 Value.

funcStringSliceValueadded inv1.0.0

func StringSliceValue(v []string)Value

StringSliceValue creates a STRINGSLICE Value.

funcStringValue

func StringValue(vstring)Value

StringValue creates a STRING Value.

func (Value)AsBool

func (vValue) AsBool()bool

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

func (Value)AsBoolSliceadded inv1.0.0

func (vValue) AsBoolSlice() []bool

AsBoolSlice returns the []bool value. Make sure that the Value's type isBOOLSLICE.

func (Value)AsFloat64

func (vValue) AsFloat64()float64

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

func (Value)AsFloat64Sliceadded inv1.0.0

func (vValue) AsFloat64Slice() []float64

AsFloat64Slice returns the []float64 value. Make sure that the Value's type isFLOAT64SLICE.

func (Value)AsInt64

func (vValue) AsInt64()int64

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

func (Value)AsInt64Sliceadded inv1.0.0

func (vValue) AsInt64Slice() []int64

AsInt64Slice returns the []int64 value. Make sure that the Value's type isINT64SLICE.

func (Value)AsInterface

func (vValue) AsInterface()any

AsInterface returns Value's data as any.

func (Value)AsString

func (vValue) AsString()string

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

func (Value)AsStringSliceadded inv1.0.0

func (vValue) AsStringSlice() []string

AsStringSlice returns the []string value. Make sure that the Value's type isSTRINGSLICE.

func (Value)Emit

func (vValue) Emit()string

Emit returns a string representation of Value's data.

func (Value)MarshalJSON

func (vValue) MarshalJSON() ([]byte,error)

MarshalJSON returns the JSON encoding of the Value.

func (Value)Type

func (vValue) Type()Type

Type returns a type of the Value.

Source Files

View all Source files

Directories

PathSynopsis
Package attribute provide several helper functions for some commonly used logic of processing attributes.
Package attribute provide several helper functions for some commonly used logic of processing attributes.
xxhash
Package xxhash provides a wrapper around the xxhash library for attribute hashing.
Package xxhash provides a wrapper around the xxhash library for attribute hashing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp