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 GetOTelAttrFromEitherMap(map1 pcommon.Map, map2 pcommon.Map, normalize bool, keys ...string) string
- func GetOTelAttrVal(attrs pcommon.Map, normalize bool, keys ...string) string
- func GetOTelAttrValInResAndSpanAttrs(span ptrace.Span, res pcommon.Resource, normalize bool, keys ...string) string
- func GetOTelContainerTags(rattrs pcommon.Map, tagKeys []string) []string
- func GetOTelOperationNameV1(span ptrace.Span, res pcommon.Resource, lib pcommon.InstrumentationScope, ...) string
- func GetOTelOperationNameV2(span ptrace.Span, res pcommon.Resource) string
- func GetOTelResourceV1(span ptrace.Span, res pcommon.Resource) (resName string)
- func GetOTelResourceV2(span ptrace.Span, res pcommon.Resource) (resName string)
- func GetOTelService(span ptrace.Span, res pcommon.Resource, normalize bool) string
- func GetOTelSpanType(span ptrace.Span, res pcommon.Resource) string
- func GetRoot(t pb.Trace) *pb.Span
- func GetRootV1(t *idx.InternalTraceChunk) *idx.InternalSpan
- func GetTopLevelOTelSpans(spanByID map[pcommon.SpanID]ptrace.Span, ...) map[pcommon.SpanID]struct{}
- func HasTopLevel(s *pb.Span) bool
- func HasTopLevelMetrics(metrics map[string]float64) bool
- func HasTopLevelMetricsV1(s *idx.InternalSpan) bool
- func IndexOTelSpans(traces ptrace.Traces) (map[pcommon.SpanID]ptrace.Span, map[pcommon.SpanID]pcommon.Resource, ...)
- func IsMeasured(s *pb.Span) bool
- func IsMeasuredMetrics(metrics map[string]float64) bool
- func IsMeasuredMetricsV1(s *idx.InternalSpan) bool
- func IsPartialSnapshot(s *pb.Span) bool
- func IsPartialSnapshotMetrics(metrics map[string]float64) bool
- func IsPartialSnapshotMetricsV1(s *idx.InternalSpan) bool
- func OTelSpanIDToUint64(b [8]byte) uint64
- func OTelSpanKindName(k ptrace.SpanKind) string
- func OTelTraceIDToUint64(b [16]byte) uint64
- 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 SpanKind2Type(span ptrace.Span, res pcommon.Resource) string
- func UpdateTracerTopLevel(s *pb.Span)
- func UpdateTracerTopLevelV1(s *idx.InternalSpan)
- type ProcessedTrace
- type ProcessedTraceV1
Constants ¶
const DefaultOTLPServiceName = "otlpresourcenoservicename"
DefaultOTLPServiceName is the default service name for OTel spans when no service name is found in the resource attributes.
const (
// TagStatusCode is the tag key for http status code.
TagStatusCode = "http.status_code"
)
Variables ¶
var ( // SignalTypeSet is the OTel attribute set for traces. SignalTypeSet = attribute.NewSet(attribute.String("signal", "traces")) )
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 GetOTelAttrFromEitherMap ¶ added in v0.68.0
func GetOTelAttrFromEitherMap(map1 pcommon.Map, map2 pcommon.Map, normalize bool, keys ...string) string
GetOTelAttrFromEitherMap returns the matched value as a string in either attribute map with the given keys. If there are multiple keys present, the first matched one is returned. If the key is present in both maps, map1 takes precedence. If normalize is true, normalize the return value with NormalizeTagValue.
func GetOTelAttrVal ¶ added in v0.54.0
GetOTelAttrVal returns the matched value as a string in the input map with the given keys. If there are multiple keys present, the first matched one is returned. If normalize is true, normalize the return value with NormalizeTagValue.
func GetOTelAttrValInResAndSpanAttrs ¶ added in v0.54.0
func GetOTelAttrValInResAndSpanAttrs(span ptrace.Span, res pcommon.Resource, normalize bool, keys ...string) string
GetOTelAttrValInResAndSpanAttrs returns the matched value as a string in the OTel resource attributes and span attributes with the given keys. If there are multiple keys present, the first matched one is returned. If the key is present in both resource attributes and span attributes, resource attributes take precedence. If normalize is true, normalize the return value with NormalizeTagValue.
func GetOTelContainerTags ¶ added in v0.54.0
GetOTelContainerTags returns a list of DD container tags in the OTel resource attributes. Tags are always normalized.
func GetOTelOperationNameV1 ¶ added in v0.61.0
func GetOTelOperationNameV1( span ptrace.Span, res pcommon.Resource, lib pcommon.InstrumentationScope, spanNameAsResourceName bool, spanNameRemappings map[string]string, normalize bool) string
GetOTelOperationNameV1 returns the DD operation name based on OTel span and resource attributes and given configs.
func GetOTelOperationNameV2 ¶ added in v0.61.0
GetOTelOperationNameV2 returns the DD operation name based on OTel span and resource attributes and given configs.
func GetOTelResourceV1 ¶ added in v0.61.0
GetOTelResourceV1 returns the DD resource name based on OTel span and resource attributes.
func GetOTelResourceV2 ¶ added in v0.61.0
GetOTelResourceV2 returns the DD resource name based on OTel span and resource attributes.
func GetOTelService ¶ added in v0.54.0
GetOTelService returns the DD service name based on OTel span and resource attributes.
func GetOTelSpanType ¶ added in v0.54.0
GetOTelSpanType returns the DD span type based on OTel span kind and attributes. This logic is used in ReceiveResourceSpansV2 logic
func GetRootV1 ¶ added in v0.73.0
func GetRootV1(t *idx.InternalTraceChunk) *idx.InternalSpan
GetRootV1 extracts the root span from a trace
func GetTopLevelOTelSpans ¶ added in v0.54.0
func GetTopLevelOTelSpans(spanByID map[pcommon.SpanID]ptrace.Span, resByID map[pcommon.SpanID]pcommon.Resource, topLevelByKind bool) map[pcommon.SpanID]struct{}
GetTopLevelOTelSpans returns the span IDs of the top level OTel spans.
func HasTopLevelMetrics ¶ added in v0.58.0
HasTopLevelMetrics returns true if the provided metrics map indicates the span is top-level.
func HasTopLevelMetricsV1 ¶ added in v0.73.0
func HasTopLevelMetricsV1(s *idx.InternalSpan) bool
HasTopLevelMetricsV1 returns true if the provided metrics map indicates the span is top-level.
func IndexOTelSpans ¶ added in v0.54.0
func IndexOTelSpans(traces ptrace.Traces) (map[pcommon.SpanID]ptrace.Span, map[pcommon.SpanID]pcommon.Resource, map[pcommon.SpanID]pcommon.InstrumentationScope)
IndexOTelSpans iterates over the input OTel spans and returns 3 maps: OTel spans indexed by span ID, OTel resources indexed by span ID, OTel instrumentation scopes indexed by span ID. Skips spans with invalid trace ID or span ID. If there are multiple spans with the same (non-zero) span ID, the last one wins.
func IsMeasured ¶
IsMeasured returns true if a span should be measured (i.e., it should get trace metrics calculated).
func IsMeasuredMetrics ¶ added in v0.58.0
IsMeasuredMetrics returns true if a span should be measured (i.e., it should get trace metrics calculated).
func IsMeasuredMetricsV1 ¶ added in v0.73.0
func IsMeasuredMetricsV1(s *idx.InternalSpan) bool
IsMeasuredMetricsV1 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 IsPartialSnapshotMetrics ¶ added in v0.58.0
IsPartialSnapshotMetrics returns true if the span is a partial snapshot. These kinds 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 IsPartialSnapshotMetricsV1 ¶ added in v0.73.0
func IsPartialSnapshotMetricsV1(s *idx.InternalSpan) bool
IsPartialSnapshotMetricsV1 returns true if the span is a partial snapshot. These kinds 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 OTelSpanIDToUint64 ¶ added in v0.55.0
OTelSpanIDToUint64 converts an OTel span ID to an uint64
func OTelSpanKindName ¶ added in v0.55.0
OTelSpanKindName converts the given SpanKind to a valid Datadog span kind name.
func OTelTraceIDToUint64 ¶ added in v0.55.0
OTelTraceIDToUint64 converts an OTel trace ID to an uint64
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 SpanKind2Type ¶ added in v0.63.0
SpanKind2Type returns a span's type based on the given kind and other present properties. This function is used in Resource V1 logic only. See GetOtelSpanType for Resource V2 logic.
func UpdateTracerTopLevel ¶
UpdateTracerTopLevel sets _top_level tag on spans flagged by the tracer
func UpdateTracerTopLevelV1 ¶ added in v0.73.0
func UpdateTracerTopLevelV1(s *idx.InternalSpan)
UpdateTracerTopLevelV1 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
Lang 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.
type ProcessedTraceV1 ¶ added in v0.73.0
type ProcessedTraceV1 struct {
TraceChunk *idx.InternalTraceChunk
Root *idx.InternalSpan
// We copy these fields from the tracer payload to enable processing each chunk independently
TracerEnv string
AppVersion string
TracerHostname string
ClientDroppedP0sWeight float64
GitCommitSha string
ImageTag string
}
ProcessedTraceV1 represents a trace being processed in the agent.
func (*ProcessedTraceV1) Clone ¶ added in v0.73.0
func (pt *ProcessedTraceV1) Clone() *ProcessedTraceV1
Clone creates a copy of ProcessedTraceV1, cloning p, p.TraceChunk, and p.Root. TODO: can we avoid needing this at all?