| 13 | } |
| 14 | |
| 15 | func NewTraceByIDV2(maxBytes int, marshalingFormat api.MarshallingFormat, traceRedactor TraceRedactor) Combiner { |
| 16 | combiner := trace.NewCombiner(maxBytes, true) |
| 17 | var partialTrace bool |
| 18 | metricsCombiner := NewTraceByIDMetricsCombiner() |
| 19 | gc := &genericCombiner[*tempopb.TraceByIDResponse]{ |
| 20 | combine: func(partial *tempopb.TraceByIDResponse, _ *tempopb.TraceByIDResponse, pipelineResp PipelineResponse) error { |
| 21 | if partial.Status == tempopb.PartialStatus_PARTIAL { |
| 22 | partialTrace = true |
| 23 | } |
| 24 | |
| 25 | metricsCombiner.Combine(partial.Metrics, pipelineResp) |
| 26 | |
| 27 | _, err := combiner.Consume(partial.Trace) |
| 28 | return err |
| 29 | }, |
| 30 | finalize: func(resp *tempopb.TraceByIDResponse) (*tempopb.TraceByIDResponse, error) { |
| 31 | traceResult, _ := combiner.Result() |
| 32 | if traceResult == nil { |
| 33 | traceResult = &tempopb.Trace{} |
| 34 | } |
| 35 | |
| 36 | // dedupe duplicate span ids |
| 37 | deduper := newDeduper() |
| 38 | traceResult = deduper.dedupe(traceResult) |
| 39 | if traceRedactor != nil { |
| 40 | err := traceRedactor.RedactTraceAttributes(traceResult) |
| 41 | if err != nil { |
| 42 | return nil, err |
| 43 | } |
| 44 | } |
| 45 | resp.Trace = traceResult |
| 46 | resp.Metrics = metricsCombiner.Metrics |
| 47 | |
| 48 | if partialTrace || combiner.IsPartialTrace() { |
| 49 | resp.Status = tempopb.PartialStatus_PARTIAL |
| 50 | resp.Message = fmt.Sprintf("Trace exceeds maximum size of %d bytes, a partial trace is returned", maxBytes) |
| 51 | } |
| 52 | |
| 53 | return resp, nil |
| 54 | }, |
| 55 | new: func() *tempopb.TraceByIDResponse { return &tempopb.TraceByIDResponse{} }, |
| 56 | current: &tempopb.TraceByIDResponse{}, |
| 57 | } |
| 58 | initHTTPCombiner(gc, marshalingFormat) |
| 59 | return gc |
| 60 | } |