internal

package
v2.10.0-dev Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Defs = [numAttrs]AttrDef{
	{AttrEnv, "env"},
	{AttrVersion, "version"},
	{AttrLanguage, "language"},
}

Defs enumerates all promoted attribute definitions.

Functions

func IsPromotedKeyLen

func IsPromotedKeyLen(n int) bool

IsPromotedKeyLen reports whether n matches the length of any promoted attribute name. Promoted keys: "env"(3), "version"(7), "language"(8). This must stay in sync with the Defs table; the init check below enforces this at program start.

Types

type AttrDef

type AttrDef struct {
	Key  AttrKey
	Name string
}

AttrDef maps an AttrKey to its canonical tag name.

type AttrKey

type AttrKey uint8

AttrKey is an integer index into a SpanAttributes value array. Use the pre-declared constants; do not construct AttrKey from arbitrary integers.

const (
	AttrEnv      AttrKey = 0
	AttrVersion  AttrKey = 1
	AttrLanguage AttrKey = 2

	// AttrUnknown is returned by AttrKeyForTag when no promoted tag matches.
	// Its value is intentionally out of range for vals[] so misuse panics immediately.
	AttrUnknown AttrKey = 0xFF
)

func AttrKeyForTag

func AttrKeyForTag(tag string) (AttrKey, bool)

AttrKeyForTag returns the AttrKey for a promoted tag name, if any. Returns (AttrUnknown, false) when the tag is not a promoted attribute.

type SpanAttributes

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

SpanAttributes holds the V1-protocol promoted span fields. Zero value = all fields absent. Set(key, "") is distinct from never-Set: the bit is set, the string is "".

Layout: 1-byte setMask + 1-byte readOnly + 6B padding + [3]string (48B) = 56 bytes.

When readOnly is true, the instance is owned by the tracer and must not be mutated. Callers must Clone before writing (copy-on-write).

func (*SpanAttributes) Clone

func (a *SpanAttributes) Clone() *SpanAttributes

Clone returns a mutable (non-readOnly) shallow copy.

func (*SpanAttributes) Count

func (a *SpanAttributes) Count() int

Count returns the number of promoted fields that have been set.

func (*SpanAttributes) Get

func (a *SpanAttributes) Get(key AttrKey) (string, bool)

func (*SpanAttributes) Has

func (a *SpanAttributes) Has(key AttrKey) bool

func (*SpanAttributes) IsReadOnly

func (a *SpanAttributes) IsReadOnly() bool

IsReadOnly reports whether this is a readOnly instance requiring COW.

func (*SpanAttributes) MarkReadOnly

func (a *SpanAttributes) MarkReadOnly()

MarkReadOnly marks this instance as readOnly (read-only). Clone before mutating. The receiver must be non-nil; marking a nil SpanAttributes read-only is a programming error and panics.

func (*SpanAttributes) Reset

func (a *SpanAttributes) Reset()

Reset clears all set attributes, returning the instance to its zero state. It is nil-safe and does not free the underlying memory, making it suitable for reuse (e.g. in a decode loop that reuses Span objects).

func (*SpanAttributes) Set

func (a *SpanAttributes) Set(key AttrKey, v string)

func (*SpanAttributes) Unset

func (a *SpanAttributes) Unset(key AttrKey)

Unset clears the attribute for key, making it absent (as if never set). nil-safe.

func (*SpanAttributes) Val

func (a *SpanAttributes) Val(key AttrKey) string

type SpanMeta

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

SpanMeta replaces a plain map[string]string for the Span.meta field. Promoted attributes (env, version, language) live in promotedAttrs and are excluded from the flat map m. The msgp codec and iterators merge both sources transparently so the wire format is unchanged.

Set routes promoted keys to promotedAttrs (with copy-on-write) and others to the flat map. Promoted keys never appear in sm.m.

func NewSpanMeta

func NewSpanMeta(promotedAttrs *SpanAttributes) SpanMeta

NewSpanMeta returns a SpanMeta initialized with shared promoted attrs (used during span creation).

func NewSpanMetaFromMap

func NewSpanMetaFromMap(m map[string]string) SpanMeta

NewSpanMetaFromMap returns a SpanMeta pre-loaded with a flat map. Intended for test helpers.

func (*SpanMeta) All

func (sm *SpanMeta) All() iter.Seq2[string, string]

All returns an iterator over all entries. Flat-map entries are yielded first (in unspecified order), followed by promoted attributes. Returning false from yield stops iteration.

func (*SpanMeta) Attr

func (sm *SpanMeta) Attr(key AttrKey) (string, bool)

Attr returns a promoted attribute value by AttrKey. O(1) array index + bitmask.

func (*SpanMeta) AttrCount

func (sm *SpanMeta) AttrCount() int

AttrCount returns the number of promoted attrs currently set.

func (*SpanMeta) Count

func (sm *SpanMeta) Count() int

Count returns the total number of distinct entries (flat map + promoted attrs).

func (*SpanMeta) DecodeMsg

func (sm *SpanMeta) DecodeMsg(dc *msgp.Reader) error

DecodeMsg reads a msgp map into m. All keys — including promoted ones — go into the flat map so that no SpanAttributes allocation is needed on the decode path. attrs is only populated on the encode (span-creation) path.

func (*SpanMeta) Delete

func (sm *SpanMeta) Delete(key string)

Delete removes key from both the flat map and (for promoted keys) attrs. +checklocksignore — called both at init time (no lock) and under lock.

The length switch is intentionally duplicated from IsPromotedKeyLen rather than calling it. Inlining IsPromotedKeyLen (cost 11) into Delete raises Delete's budget from 73 to 81, crossing the 80-unit limit and preventing callers from inlining Delete. The direct switch keeps Delete at cost 73.

func (*SpanMeta) EncodeMsg

func (sm *SpanMeta) EncodeMsg(en *msgp.Writer) error

EncodeMsg writes the map header and entries, combining the flat map and promoted attrs.

func (*SpanMeta) Env

func (sm *SpanMeta) Env() (string, bool)

Env returns the value of the "env" promoted attribute.

func (*SpanMeta) Get

func (sm *SpanMeta) Get(key string) (string, bool)

Get returns the value for key. Promoted keys are checked in attrs first (fast array+bitmask path), then the flat map. Non-promoted keys go directly to the flat map.

func (*SpanMeta) Has

func (sm *SpanMeta) Has(key string) bool

Has reports whether key is present.

func (*SpanMeta) IsZero

func (sm *SpanMeta) IsZero() bool

IsZero reports whether the SpanMeta contains no entries (map or promoted). The msgp generator emits z.meta.IsZero() for the omitempty check.

func (*SpanMeta) Language

func (sm *SpanMeta) Language() (string, bool)

Language returns the value of the "language" promoted attribute.

func (*SpanMeta) Map

func (sm *SpanMeta) Map(full bool) map[string]string

Map returns a map containing meta entries.

When full is true, promoted attrs (env, version, language) are merged into a new map (one allocation). Use this when the caller needs the complete view, e.g. CI visibility or test helpers.

When full is false, the underlying flat map is returned directly (zero allocation). Promoted keys are excluded. Use this when the caller is known to not need promoted keys, e.g. the stats path reads span.kind, _dd.svc_src, HTTP/gRPC status codes, and peer tags — none of which are promoted attributes.

func (*SpanMeta) Msgsize

func (sm *SpanMeta) Msgsize() int

Msgsize returns an upper bound estimate of the serialized size, combining the flat map and promoted attrs.

func (*SpanMeta) Normalize

func (sm *SpanMeta) Normalize()

Normalize sets m and attrs to nil when they are empty so that a zero-length SpanMeta compares equal to a freshly-zeroed one. Intended for test helpers.

func (*SpanMeta) Range

func (sm *SpanMeta) Range(fn func(k, v string) bool)

Range calls fn for each flat-map entry. Promoted attrs are not in sm.m and are not yielded. Iteration stops if fn returns false.

func (*SpanMeta) ReplaceSharedAttrs

func (sm *SpanMeta) ReplaceSharedAttrs(prev, next *SpanAttributes)

ReplaceSharedAttrs replaces the current attrs pointer with next if it currently equals prev. Used by the tracer to upgrade a newly-created span from the base shared attrs to the main-service shared attrs.

func (*SpanMeta) Set

func (sm *SpanMeta) Set(key, value string)

Set sets key→value, routing promoted keys to attrs (with copy-on-write) and others to the flat map. +checklocksignore — called both at init time (no lock) and under lock.

func (*SpanMeta) String

func (sm *SpanMeta) String() string

String returns a merged map representation (m + promoted attrs) for debug logging.

func (*SpanMeta) Version

func (sm *SpanMeta) Version() (string, bool)

Version returns the value of the "version" promoted attribute.

Jump to

Keyboard shortcuts

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