MCPcopy
hub / github.com/grafana/tempo / asTraceSearchMetadata

Function asTraceSearchMetadata

pkg/traceql/engine.go:289–371  ·  view source on GitHub ↗
(spanset *Spanset)

Source from the content-addressed store, hash-verified

287}
288
289func asTraceSearchMetadata(spanset *Spanset) *tempopb.TraceSearchMetadata {
290 metadata := &tempopb.TraceSearchMetadata{
291 TraceID: util.TraceIDToHexString(spanset.TraceID),
292 RootServiceName: spanset.RootServiceName,
293 RootTraceName: spanset.RootSpanName,
294 StartTimeUnixNano: spanset.StartTimeUnixNanos,
295 DurationMs: uint32(spanset.DurationNanos / 1_000_000),
296 ServiceStats: make(map[string]*tempopb.ServiceStats, len(spanset.ServiceStats)),
297 SpanSet: &tempopb.SpanSet{},
298 }
299
300 for service, stats := range spanset.ServiceStats {
301 metadata.ServiceStats[service] = &tempopb.ServiceStats{
302 SpanCount: stats.SpanCount,
303 ErrorCount: stats.ErrorCount,
304 }
305 }
306
307 for _, span := range spanset.Spans {
308 tempopbSpan := &tempopb.Span{
309 SpanID: util.SpanIDToHexString(span.ID()),
310 StartTimeUnixNano: span.StartTimeUnixNanos(),
311 DurationNanos: span.DurationNanos(),
312 Attributes: nil,
313 }
314
315 atts := span.AllAttributes()
316
317 if name, ok := atts[NewIntrinsic(IntrinsicName)]; ok {
318 tempopbSpan.Name = name.EncodeToString(false)
319 }
320
321 for attribute, static := range atts {
322 if attribute.Intrinsic == IntrinsicName ||
323 attribute.Intrinsic == IntrinsicDuration ||
324 attribute.Intrinsic == IntrinsicTraceDuration ||
325 attribute.Intrinsic == IntrinsicTraceRootService ||
326 attribute.Intrinsic == IntrinsicTraceRootSpan ||
327 attribute.Intrinsic == IntrinsicTraceID ||
328 attribute.Intrinsic == IntrinsicSpanID {
329
330 continue
331 }
332
333 staticAnyValue := static.AsAnyValue()
334
335 keyValue := &common_v1.KeyValue{
336 Key: attribute.Name,
337 Value: staticAnyValue,
338 }
339
340 tempopbSpan.Attributes = append(tempopbSpan.Attributes, keyValue)
341 }
342
343 metadata.SpanSet.Spans = append(metadata.SpanSet.Spans, tempopbSpan)
344 }
345
346 // create a new slice and add the spanset to it. eventually we will deprecate

Callers 4

addSpansetMethod · 0.85
addSpansetMethod · 0.85

Calls 10

TraceIDToHexStringFunction · 0.92
SpanIDToHexStringFunction · 0.92
NewIntrinsicFunction · 0.85
EncodeToStringMethod · 0.80
AsAnyValueMethod · 0.80
IntMethod · 0.80
IDMethod · 0.65
StartTimeUnixNanosMethod · 0.65
DurationNanosMethod · 0.65
AllAttributesMethod · 0.65

Tested by 2