| 147 | } |
| 148 | |
| 149 | func (e *OTLPHTTPExporter) post(endpoint string, payload map[string]any) error { |
| 150 | raw, err := json.Marshal(payload) |
| 151 | if err != nil { |
| 152 | return err |
| 153 | } |
| 154 | |
| 155 | var lastErr error |
| 156 | for attempt := 0; attempt <= e.retries; attempt++ { |
| 157 | req, reqErr := http.NewRequest(http.MethodPost, endpoint, bytes.NewReader(raw)) |
| 158 | if reqErr != nil { |
| 159 | return reqErr |
| 160 | } |
| 161 | req.Header.Set("Content-Type", "application/json") |
| 162 | resp, doErr := e.httpClient.Do(req) |
| 163 | if doErr != nil { |
| 164 | lastErr = doErr |
| 165 | continue |
| 166 | } |
| 167 | _ = resp.Body.Close() |
| 168 | e.mu.Lock() |
| 169 | e.lastStatusCode = resp.StatusCode |
| 170 | e.mu.Unlock() |
| 171 | if resp.StatusCode >= 200 && resp.StatusCode < 300 { |
| 172 | return nil |
| 173 | } |
| 174 | lastErr = fmt.Errorf("otlp http exporter got status %d", resp.StatusCode) |
| 175 | } |
| 176 | return lastErr |
| 177 | } |
| 178 | |
| 179 | func endpointForKind(base, kind string) string { |
| 180 | base = strings.TrimRight(base, "/") |