( _ context.Context, writtenTrace *util.TraceInfo, actualTrace *tempopb.Trace, httpClient httpclient.TempoHTTPClient, )
| 319 | } |
| 320 | |
| 321 | func (vs *ValidationService) validateTraceSearch( |
| 322 | _ context.Context, |
| 323 | writtenTrace *util.TraceInfo, |
| 324 | actualTrace *tempopb.Trace, |
| 325 | httpClient httpclient.TempoHTTPClient, |
| 326 | ) error { |
| 327 | vs.logTraceAttributes(actualTrace, writtenTrace.HexID()) |
| 328 | |
| 329 | // Get a random attribute from the expected trace |
| 330 | attr := util.RandomAttrFromTrace(actualTrace) |
| 331 | if attr == nil { |
| 332 | return fmt.Errorf("no searchable attribute found in trace") |
| 333 | } |
| 334 | |
| 335 | searchQuery := fmt.Sprintf(`{.%s = "%s"}`, attr.Key, util.StringifyAnyValue(attr.Value)) |
| 336 | vs.logger.Info("Searching for trace", |
| 337 | zap.String("traceID", writtenTrace.HexID()), |
| 338 | zap.String("searchQuery", searchQuery), |
| 339 | ) |
| 340 | |
| 341 | start := writtenTrace.Timestamp().Add(-30 * time.Minute).Unix() |
| 342 | end := writtenTrace.Timestamp().Add(30 * time.Minute).Unix() |
| 343 | |
| 344 | searchResp, searchErr := httpClient.SearchTraceQLWithRange(searchQuery, start, end) |
| 345 | if searchErr != nil { |
| 346 | return fmt.Errorf("search API failed: %w", searchErr) |
| 347 | } |
| 348 | |
| 349 | vs.logger.Info("Search response received", |
| 350 | zap.Int("traces_found", len(searchResp.Traces)), |
| 351 | ) |
| 352 | |
| 353 | // Check if our trace ID is in the search results |
| 354 | found := false |
| 355 | for _, trace := range searchResp.Traces { |
| 356 | vs.logger.Info("written trace", zap.String("trace_id", writtenTrace.HexID())) |
| 357 | vs.logger.Info("found trace", zap.String("trace_id", trace.TraceID)) |
| 358 | |
| 359 | equal, err := util.EqualHexStringTraceIDs(writtenTrace.HexID(), trace.TraceID) |
| 360 | if err != nil { |
| 361 | return fmt.Errorf("error comparing trace IDs: %w", err) |
| 362 | } |
| 363 | if !equal { |
| 364 | return fmt.Errorf("trace IDs do not match") |
| 365 | } |
| 366 | |
| 367 | if equal { |
| 368 | found = true |
| 369 | break |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | if found { |
| 374 | vs.logger.Info("Found trace via search") |
| 375 | } else { |
| 376 | return fmt.Errorf("trace not found in search results") |
| 377 | } |
| 378 | return nil |
no test coverage detected