| 138 | } |
| 139 | |
| 140 | func (r *remoteReporter) reportSync(snapshot *Snapshot) { |
| 141 | snapshot.DeploymentID = r.options.DeploymentID |
| 142 | data, err := json.Marshal(snapshot) |
| 143 | if err != nil { |
| 144 | r.options.Logger.Error(r.ctx, "marshal snapshot: %w", slog.Error(err)) |
| 145 | return |
| 146 | } |
| 147 | req, err := http.NewRequestWithContext(r.ctx, "POST", r.snapshotURL.String(), bytes.NewReader(data)) |
| 148 | if err != nil { |
| 149 | r.options.Logger.Error(r.ctx, "unable to create snapshot request", slog.Error(err)) |
| 150 | return |
| 151 | } |
| 152 | req.Header.Set(VersionHeader, buildinfo.Version()) |
| 153 | resp, err := r.client.Do(req) |
| 154 | if err != nil { |
| 155 | // If the request fails it's not necessarily an error. |
| 156 | // In an airgapped environment, it's fine if this fails! |
| 157 | r.options.Logger.Debug(r.ctx, "submit", slog.Error(err)) |
| 158 | return |
| 159 | } |
| 160 | defer resp.Body.Close() |
| 161 | if resp.StatusCode != http.StatusAccepted { |
| 162 | r.options.Logger.Debug(r.ctx, "bad response from telemetry server", slog.F("status", resp.StatusCode)) |
| 163 | return |
| 164 | } |
| 165 | r.options.Logger.Debug(r.ctx, "submitted snapshot") |
| 166 | } |
| 167 | |
| 168 | func (r *remoteReporter) Close() { |
| 169 | r.closeMutex.Lock() |