// GetAnalyzedSpans finds all the analyzed spans in a trace, including top level spans
// and spans marked as anaylzed by the tracer.
// A span is considered top-level if:
// - it's a root span
// - its parent is unknown (other part of the code, distributed trace)
// - 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).
GetAnalyzedSpans finds all the analyzed spans in a trace, including top level spans
and spans marked as anaylzed by the tracer.
A span is considered top-level if:
- it's a root span
- its parent is unknown (other part of the code, distributed trace)
- 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).
// GetAnalyzedSpans finds all the analyzed spans in a trace including top level spans // and spans marked as anaylzed by the tracer . // A span is considered top - level if : // - it ' s a root span // - its parent is unknown ( other part of the code distributed trace ) // - 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 GetAnalyzedSpans(sps []*pb.Span) []*pb.Span {
	spanIDToIdx := make(map[uint64]int, len(sps))
	for i, span := range sps {
		spanIDToIdx[span.SpanID] = i
	}
	top := []*pb.Span{}
	extractor := event.NewMetricBasedExtractor()
	for _, span := range sps {
		priority, extracted := extractor.Extract(span, sampler.PriorityUserKeep)
		shouldExtract := priority > 0 && extracted
		if span.ParentID != 0 {
			if parentIdx, ok := spanIDToIdx[span.ParentID]; ok && sps[parentIdx].Service == span.Service && !shouldExtract {
				continue
			}
		}
		top = append(top, span)
	}
	return top
}
func GetAnalyzedSpans ( sps [ ] * pb . Span ) [ ] * pb . Span { spanIDToIdx := make ( map [ uint64 ] int , len ( sps ) ) for i , span := range sps { spanIDToIdx [ span . SpanID ] = i } top := [ ] * pb . Span { } extractor := event . NewMetricBasedExtractor ( ) for _ , span := range sps { priority , extracted := extractor . Extract ( span , sampler . PriorityUserKeep ) shouldExtract := priority > 0 && extracted if span . ParentID != 0 { if parentIdx , ok := spanIDToIdx [ span . ParentID ] ; ok && sps [ parentIdx ] . Service == span . Service && ! shouldExtract { continue } } top = append ( top , span ) } return top }
GetAnalyzedSpans finds all the analyzed spans in a trace, including top level spans
and spans marked as anaylzed by the tracer.
GetAnalyzedSpans finds all the analyzed spans in a trace including top level spans and spans marked as anaylzed by the tracer .
// build a lookup map // iterate on each span and mark them as top-level if relevant // The tracer can mark a span to be analysed, with a value 0-1, where 1 is always keep, and 0 is always reject. // Values between 0-1 are used by the agent to prioritise which spans are sampled or not. Since we can't // reliably apply sampling decisions in a serverless environment, we keep any analyzed span with a priority // greater than 0, and let the backend make the sampling decision instead.