Documentation ¶
Overview ¶
Package traceutil contains functions for extracting and processing traces. It should only import payload and nothing else.
Index ¶
- Constants
- Variables
- func ChildrenMap(t pb.Trace) map[uint64][]*pb.Span
- func ComputeTopLevel(trace pb.Trace)
- func GetAppServicesTags() map[string]string
- func GetEnv(root *pb.Span, t *pb.TraceChunk) string
- func GetMeta(s *pb.Span, key string) (string, bool)
- func GetMetaDefault(s *pb.Span, key, fallback string) string
- func GetMetaStruct(s *pb.Span, key string) (interface{}, bool)
- func GetMetric(s *pb.Span, key string) (float64, bool)
- func GetRoot(t pb.Trace) *pb.Span
- func HasTopLevel(s *pb.Span) bool
- func IsMeasured(s *pb.Span) bool
- func IsPartialSnapshot(s *pb.Span) bool
- func NormalizeName(name string) (string, error)
- func NormalizePeerService(svc string) (string, error)
- func NormalizeService(svc string, lang string) (string, error)
- func NormalizeTag(v string) string
- func NormalizeTagValue(v string) string
- func SetMeasured(s *pb.Span, measured bool)
- func SetMeta(s *pb.Span, key, val string)
- func SetMetaStruct(s *pb.Span, key string, val interface{}) error
- func SetMetric(s *pb.Span, key string, val float64)
- func SetTopLevel(s *pb.Span, topLevel bool)
- func TruncateUTF8(s string, limit int) string
- func UpdateTracerTopLevel(s *pb.Span)
- type ProcessedTrace
Constants ¶
const ( // DefaultSpanName is the default name we assign a span if it's missing and we have no reasonable fallback DefaultSpanName = "unnamed_operation" // DefaultServiceName is the default name we assign a service if it's missing and we have no reasonable fallback DefaultServiceName = "unnamed-service" )
const ( // MaxNameLen the maximum length a name can have MaxNameLen = 100 // MaxServiceLen the maximum length a service can have MaxServiceLen = 100 )
Variables ¶
Functions ¶
func ChildrenMap ¶
ChildrenMap returns a map containing for each span id the list of its direct children.
func ComputeTopLevel ¶
ComputeTopLevel updates all the spans top-level attribute.
A span is considered top-level if:
- it's a root span
- OR its parent is unknown (other part of the code, distributed trace)
- OR its parent belongs to another service (in that case it's a "local root" being the highest ancestor of other spans belonging to this service and attached to it).
func GetAppServicesTags ¶ added in v0.42.0
GetAppServicesTags returns the env vars pulled from the Azure App Service instance. In some cases we will need to add extra tags for function apps.
func GetEnv ¶
func GetEnv(root *pb.Span, t *pb.TraceChunk) string
GetEnv returns the first "env" tag found in trace t. Search starts by root
func GetMetaDefault ¶
GetMetaDefault gets the metadata value in the span Meta map and fallbacks to fallback.
func GetMetaStruct ¶
GetMetaStruct gets the structured metadata value in the span MetaStruct map.
func IsMeasured ¶
IsMeasured returns true if a span should be measured (i.e., it should get trace metrics calculated).
func IsPartialSnapshot ¶
IsPartialSnapshot returns true if the span is a partial snapshot. This kind of spans are partial images of long-running spans. When incomplete, a partial snapshot has a metric _dd.partial_version which is a positive integer. The metric usually increases each time a new version of the same span is sent by the tracer
func NormalizeName ¶
NormalizeName normalizes a span name and returns an error describing the reason (if any) why the name was modified.
func NormalizePeerService ¶ added in v0.45.0
NormalizePeerService normalizes a span's peer.service and returns an error describing the reason (if any) why the name was modified.
func NormalizeService ¶
NormalizeService normalizes a span service and returns an error describing the reason (if any) why the name was modified.
func NormalizeTag ¶
NormalizeTag applies some normalization to ensure the full tag_key:tag_value string matches the backend requirements.
func NormalizeTagValue ¶ added in v0.47.0
NormalizeTagValue applies some normalization to ensure the tag value matches the backend requirements. It should be used for cases where we have just the tag_value as the input (instead of tag_key:tag_value).
func SetMeasured ¶ added in v0.53.0
SetMeasured sets the measured attribute of the span.
func SetMetaStruct ¶
SetMetaStruct sets the structured metadata at key to the val on the span s.
func SetTopLevel ¶
SetTopLevel sets the top-level attribute of the span.
func TruncateUTF8 ¶
TruncateUTF8 truncates the given string to make sure it uses less than limit bytes. If the last character is an utf8 character that would be splitten, it removes it entirely to make sure the resulting string is not broken.
func UpdateTracerTopLevel ¶
UpdateTracerTopLevel sets _top_level tag on spans flagged by the tracer
Types ¶
type ProcessedTrace ¶
type ProcessedTrace struct { TraceChunk *pb.TraceChunk Root *pb.Span TracerEnv string AppVersion string TracerHostname string ClientDroppedP0sWeight float64 GitCommitSha string ImageTag string }
ProcessedTrace represents a trace being processed in the agent.
func (*ProcessedTrace) Clone ¶ added in v0.45.0
func (pt *ProcessedTrace) Clone() *ProcessedTrace
Clone creates a copy of ProcessedTrace, cloning p, p.TraceChunk, and p.Root. This means it is safe to modify the returned ProcessedTrace's (pt's) fields along with fields in pt.TraceChunk and fields in pt.Root.
The most important consequence of this is that the TraceChunk's Spans field can be assigned, *BUT* the Spans value itself should not be modified. i.e. This is ok:
pt2 := pt.Clone() pt2.TraceChunk.Spans = make([]*pb.Span)
but this is NOT ok:
pt2 := pt.Clone() pt2.TraceChunk.Spans[0] = &pb.Span{} // This will be visible in pt.