FindTraceByID implements tempopb.Querier.
(ctx context.Context, req *tempopb.TraceByIDRequest, timeStart int64, timeEnd int64)
| 178 | |
| 179 | // FindTraceByID implements tempopb.Querier. |
| 180 | func (q *Querier) FindTraceByID(ctx context.Context, req *tempopb.TraceByIDRequest, timeStart int64, timeEnd int64) (*tempopb.TraceByIDResponse, error) { |
| 181 | if !validation.ValidTraceID(req.TraceID) { |
| 182 | return nil, errors.New("invalid trace id") |
| 183 | } |
| 184 | |
| 185 | userID, err := validation.ExtractValidTenantID(ctx) |
| 186 | if err != nil { |
| 187 | return nil, fmt.Errorf("error extracting org id in Querier.FindTraceByID: %w", err) |
| 188 | } |
| 189 | |
| 190 | ctx, span := tracer.Start(ctx, "Querier.FindTraceByID") |
| 191 | defer span.End() |
| 192 | |
| 193 | span.SetAttributes(attribute.String("queryMode", req.QueryMode)) |
| 194 | |
| 195 | maxBytes := q.limits.MaxBytesPerTrace(userID) |
| 196 | combiner := trace.NewCombiner(maxBytes, req.AllowPartialTrace) |
| 197 | var inspectedBytes uint64 |
| 198 | |
| 199 | if req.QueryMode == QueryModeIngesters || req.QueryMode == QueryModeAll { |
| 200 | // Get responses from all live stores in parallel. |
| 201 | span.AddEvent("searching live-stores") |
| 202 | forEach := func(funcCtx context.Context, client tempopb.QuerierClient) (any, error) { |
| 203 | return client.FindTraceByID(funcCtx, req) |
| 204 | } |
| 205 | partialTraces, err := q.forLiveStoreRing(ctx, forEach) |
| 206 | if err != nil { |
| 207 | return nil, fmt.Errorf("error querying live-stores in Querier.FindTraceByID: %w", err) |
| 208 | } |
| 209 | |
| 210 | var spanCountTotal, traceCountTotal int64 |
| 211 | found := false |
| 212 | |
| 213 | for _, partialTrace := range partialTraces { |
| 214 | resp := partialTrace.(*tempopb.TraceByIDResponse) |
| 215 | if resp.Trace == nil { |
| 216 | continue |
| 217 | } |
| 218 | |
| 219 | found = true |
| 220 | |
| 221 | spanCount, err := combiner.Consume(resp.Trace) |
| 222 | if err != nil { |
| 223 | return nil, fmt.Errorf("error combining live-store results in Querier.FindTraceByID: %w", err) |
| 224 | } |
| 225 | |
| 226 | spanCountTotal += int64(spanCount) |
| 227 | traceCountTotal++ |
| 228 | if resp.Metrics != nil { |
| 229 | inspectedBytes += resp.Metrics.InspectedBytes |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | span.AddEvent("done searching live-stores", oteltrace.WithAttributes( |
| 234 | attribute.Bool("found", found), |
| 235 | attribute.Int64("combinedSpans", spanCountTotal), |
| 236 | attribute.Int64("combinedTraces", traceCountTotal), |
| 237 | )) |
no test coverage detected