| 287 | } |
| 288 | |
| 289 | func 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 |