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

Method FindTraceIDs

cmd/tempo-query/tempo/plugin.go:403–472  ·  view source on GitHub ↗
(ctx context.Context, r *storage_v1.FindTraceIDsRequest)

Source from the content-addressed store, hash-verified

401}
402
403func (b *Backend) FindTraceIDs(ctx context.Context, r *storage_v1.FindTraceIDsRequest) (*storage_v1.FindTraceIDsResponse, error) {
404 ctx, span := tracer.Start(ctx, "tempo-query.FindTraceIDs")
405 defer span.End()
406
407 url := url.URL{
408 Scheme: b.apiSchema(),
409 Host: b.tempoBackend,
410 Path: "api/search",
411 }
412 urlQuery := url.Query()
413 urlQuery.Set(minDurationSearchTag, r.Query.DurationMin.String())
414 urlQuery.Set(maxDurationSearchTag, r.Query.DurationMax.String())
415 urlQuery.Set(numTracesSearchTag, strconv.Itoa(int(r.Query.GetNumTraces())))
416 urlQuery.Set(startTimeMaxTag, fmt.Sprintf("%d", r.Query.StartTimeMax.Unix()))
417 urlQuery.Set(startTimeMinTag, fmt.Sprintf("%d", r.Query.StartTimeMin.Unix()))
418
419 queryParam, err := createTagsQueryParam(
420 r.Query.ServiceName,
421 r.Query.OperationName,
422 r.Query.Tags,
423 )
424 if err != nil {
425 return nil, fmt.Errorf("failed to create tags query parameter: %w", err)
426 }
427 urlQuery.Set(tagsSearchTag, queryParam)
428
429 url.RawQuery = urlQuery.Encode()
430
431 req, err := b.newGetRequest(ctx, url.String())
432 if err != nil {
433 return nil, err
434 }
435
436 resp, err := b.httpClient.Do(req)
437 if err != nil {
438 return nil, fmt.Errorf("failed GET to tempo: %w", err)
439 }
440 defer resp.Body.Close()
441
442 // if search endpoint returns 404, search is most likely not enabled
443 if resp.StatusCode == http.StatusNotFound {
444 return nil, nil
445 }
446
447 if resp.StatusCode != http.StatusOK {
448 body, err := io.ReadAll(resp.Body)
449 if err != nil {
450 return nil, fmt.Errorf("error reading response from Tempo: got %s", resp.Status)
451 }
452 return nil, fmt.Errorf("%s", body)
453 }
454
455 var searchResponse tempopb.SearchResponse
456 err = jsonpb.Unmarshal(resp.Body, &searchResponse)
457 if err != nil {
458 return nil, fmt.Errorf("error unmarshaling Tempo response: %w", err)
459 }
460

Callers 1

FindTracesMethod · 0.95

Calls 13

apiSchemaMethod · 0.95
newGetRequestMethod · 0.95
createTagsQueryParamFunction · 0.85
QueryMethod · 0.80
GetNumTracesMethod · 0.80
StartMethod · 0.65
SetMethod · 0.65
EncodeMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
ReadAllMethod · 0.65
UnmarshalMethod · 0.65

Tested by

no test coverage detected