()
| 106 | } |
| 107 | |
| 108 | func (c *TraceByIDCombiner) HTTPFinal() (*http.Response, error) { |
| 109 | c.mu.Lock() |
| 110 | defer c.mu.Unlock() |
| 111 | |
| 112 | statusCode := c.code |
| 113 | traceResult, _ := c.c.Result() |
| 114 | |
| 115 | if statusCode != http.StatusOK { |
| 116 | return &http.Response{ |
| 117 | StatusCode: statusCode, |
| 118 | Body: io.NopCloser(strings.NewReader(c.statusMessage)), |
| 119 | Header: http.Header{}, |
| 120 | }, nil |
| 121 | } |
| 122 | |
| 123 | // if we have no trace result just substitute and return an empty trace |
| 124 | if traceResult == nil { |
| 125 | traceResult = &tempopb.Trace{} |
| 126 | } |
| 127 | |
| 128 | // dedupe duplicate span ids |
| 129 | deduper := newDeduper() |
| 130 | traceResult = deduper.dedupe(traceResult) |
| 131 | if c.traceRedactor != nil { |
| 132 | err := c.traceRedactor.RedactTraceAttributes(traceResult) |
| 133 | if err != nil { |
| 134 | if errors.Is(err, ErrTraceHidden) { |
| 135 | return &http.Response{ |
| 136 | StatusCode: http.StatusNotFound, |
| 137 | Body: http.NoBody, |
| 138 | Header: http.Header{}, |
| 139 | }, nil |
| 140 | } |
| 141 | return &http.Response{}, fmt.Errorf("trace redactor error: %w", err) |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | // marshal in the requested format |
| 146 | var buff []byte |
| 147 | var err error |
| 148 | |
| 149 | if c.contentType == api.MarshallingFormatProtobuf { |
| 150 | buff, err = proto.Marshal(traceResult) |
| 151 | } else { |
| 152 | buff, err = tempopb.MarshalToJSONV1(traceResult) |
| 153 | } |
| 154 | if err != nil { |
| 155 | return &http.Response{}, fmt.Errorf("error marshalling response: %w content type: %s", err, c.contentType) |
| 156 | } |
| 157 | |
| 158 | return &http.Response{ |
| 159 | StatusCode: http.StatusOK, |
| 160 | Header: http.Header{ |
| 161 | api.HeaderContentType: {string(c.contentType)}, |
| 162 | }, |
| 163 | Body: io.NopCloser(bytes.NewReader(buff)), |
| 164 | ContentLength: int64(len(buff)), |
| 165 | }, nil |
nothing calls this directly
no test coverage detected