Documentation
¶
Index ¶
- Variables
- func IsPromotedKeyLen(n int) bool
- type AttrDef
- type AttrKey
- type SpanAttributes
- func (a *SpanAttributes) Clone() *SpanAttributes
- func (a *SpanAttributes) Count() int
- func (a *SpanAttributes) Get(key AttrKey) (string, bool)
- func (a *SpanAttributes) Has(key AttrKey) bool
- func (a *SpanAttributes) IsReadOnly() bool
- func (a *SpanAttributes) MarkReadOnly()
- func (a *SpanAttributes) Reset()
- func (a *SpanAttributes) Set(key AttrKey, v string)
- func (a *SpanAttributes) Unset(key AttrKey)
- func (a *SpanAttributes) Val(key AttrKey) string
- type SpanMeta
- func (sm *SpanMeta) All() iter.Seq2[string, string]
- func (sm *SpanMeta) Attr(key AttrKey) (string, bool)
- func (sm *SpanMeta) AttrCount() int
- func (sm *SpanMeta) Count() int
- func (sm *SpanMeta) DecodeMsg(dc *msgp.Reader) error
- func (sm *SpanMeta) Delete(key string)
- func (sm *SpanMeta) EncodeMsg(en *msgp.Writer) error
- func (sm *SpanMeta) Env() (string, bool)
- func (sm *SpanMeta) Get(key string) (string, bool)
- func (sm *SpanMeta) Has(key string) bool
- func (sm *SpanMeta) IsZero() bool
- func (sm *SpanMeta) Language() (string, bool)
- func (sm *SpanMeta) Map(full bool) map[string]string
- func (sm *SpanMeta) Msgsize() int
- func (sm *SpanMeta) Normalize()
- func (sm *SpanMeta) Range(fn func(k, v string) bool)
- func (sm *SpanMeta) ReplaceSharedAttrs(prev, next *SpanAttributes)
- func (sm *SpanMeta) Set(key, value string)
- func (sm *SpanMeta) String() string
- func (sm *SpanMeta) Version() (string, bool)
Constants ¶
This section is empty.
Variables ¶
var Defs = [numAttrs]AttrDef{ {AttrEnv, "env"}, {AttrVersion, "version"}, {AttrLanguage, "language"}, }
Defs enumerates all promoted attribute definitions.
Functions ¶
func IsPromotedKeyLen ¶
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 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.
func AttrKeyForTag ¶
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) 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 ¶
NewSpanMetaFromMap returns a SpanMeta pre-loaded with a flat map. Intended for test helpers.
func (*SpanMeta) All ¶
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 ¶
Attr returns a promoted attribute value by AttrKey. O(1) array index + bitmask.
func (*SpanMeta) Count ¶
Count returns the total number of distinct entries (flat map + promoted attrs).
func (*SpanMeta) DecodeMsg ¶
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 ¶
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 ¶
EncodeMsg writes the map header and entries, combining the flat map and promoted attrs.
func (*SpanMeta) Get ¶
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) IsZero ¶
IsZero reports whether the SpanMeta contains no entries (map or promoted). The msgp generator emits z.meta.IsZero() for the omitempty check.
func (*SpanMeta) Map ¶
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 ¶
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 ¶
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 ¶
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.