Skip to content

Commit a07948d

Browse files
jpnurmiclaude
andcommitted
feat(curl): log upload progress and reduce debug noise
Show upload progress (MB uploaded, percentage, speed) via the progress callback. Suppress per-chunk "=> Send" noise for non-JSON data since the progress callback covers that. Keep recv logging for all responses. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8e3b656 commit a07948d

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

src/transports/sentry_http_transport_curl.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,21 @@ curl_client_shutdown(void *_client)
130130

131131
static int
132132
progress_callback(void *clientp, curl_off_t UNUSED(dltotal),
133-
curl_off_t UNUSED(dlnow), curl_off_t UNUSED(ultotal),
134-
curl_off_t UNUSED(ulnow))
133+
curl_off_t UNUSED(dlnow), curl_off_t ultotal, curl_off_t ulnow)
135134
{
136135
curl_client_t *client = clientp;
137-
return sentry__atomic_fetch(&client->shutdown) ? 1 : 0;
136+
if (sentry__atomic_fetch(&client->shutdown)) {
137+
return 1;
138+
}
139+
if (ultotal > 0) {
140+
double speed = 0;
141+
curl_easy_getinfo(client->curl_handle, CURLINFO_SPEED_UPLOAD, &speed);
142+
SENTRY_DEBUGF("upload progress: %.1f / %.1f MB (%.0f%%, %.1f MB/s)",
143+
(double)ulnow / (1024.0 * 1024.0),
144+
(double)ultotal / (1024.0 * 1024.0),
145+
(double)ulnow / (double)ultotal * 100.0, speed / (1024.0 * 1024.0));
146+
}
147+
return 0;
138148
}
139149

140150
static size_t
@@ -159,20 +169,27 @@ debug_function(CURL *UNUSED(handle), curl_infotype type, char *data,
159169
case CURLINFO_HEADER_IN:
160170
prefix = "< ";
161171
break;
162-
case CURLINFO_DATA_OUT:
172+
case CURLINFO_DATA_OUT: {
173+
size_t len = size;
174+
while (len > 0 && (data[len - 1] == '\n' || data[len - 1] == '\r')) {
175+
len--;
176+
}
177+
if (len >= 2 && data[0] == '{' && data[len - 1] == '}') {
178+
fprintf(
179+
stderr, "=> Send (%zu bytes): %.*s\n", size, (int)len, data);
180+
}
181+
return 0;
182+
}
163183
case CURLINFO_DATA_IN: {
164-
const char *dir = type == CURLINFO_DATA_OUT ? "Send" : "Recv";
165184
size_t len = size;
166185
while (len > 0 && (data[len - 1] == '\n' || data[len - 1] == '\r')) {
167186
len--;
168187
}
169188
if (len >= 2 && data[0] == '{' && data[len - 1] == '}') {
170-
fprintf(stderr, "%s %s (%zu bytes): %.*s\n",
171-
type == CURLINFO_DATA_OUT ? "=>" : "<=", dir, size, (int)len,
172-
data);
189+
fprintf(
190+
stderr, "<= Recv (%zu bytes): %.*s\n", size, (int)len, data);
173191
} else {
174-
fprintf(stderr, "%s %s (%zu bytes)\n",
175-
type == CURLINFO_DATA_OUT ? "=>" : "<=", dir, size);
192+
fprintf(stderr, "<= Recv (%zu bytes)\n", size);
176193
}
177194
return 0;
178195
}

0 commit comments

Comments
 (0)