Skip to content

Commit c77d024

Browse files
committed
Minimised logging for the retry handlers
1 parent 5104baa commit c77d024

File tree

1 file changed

+6
-73
lines changed

1 file changed

+6
-73
lines changed

csharp/src/Drivers/Databricks/RetryHttpHandler.cs

Lines changed: 6 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ protected override async Task<HttpResponseMessage> SendAsync(
6363

6464
HttpResponseMessage response;
6565
string? lastErrorMessage = null;
66-
DateTime startTime = DateTime.UtcNow;
6766
int attemptCount = 0;
6867
int currentBackoffSeconds = _initialBackoffSeconds;
6968
int totalRetrySeconds = 0;
@@ -85,34 +84,15 @@ protected override async Task<HttpResponseMessage> SendAsync(
8584
if (attemptCount > 0)
8685
{
8786
activity?.SetTag("http.retry.total_attempts", attemptCount);
88-
activity?.SetTag("http.retry.total_wait_seconds", totalRetrySeconds);
89-
activity?.SetTag("http.retry.total_elapsed_seconds",
90-
(DateTime.UtcNow - startTime).TotalSeconds);
9187
activity?.SetTag("http.response.status_code", (int)response.StatusCode);
9288
}
93-
return response; // Clean exit - no logging for normal success
94-
}
95-
96-
// Retry path - log details when we first enter retry path
97-
if (attemptCount == 0)
98-
{
99-
activity?.SetTag("http.retry.max_timeout_seconds", _retryTimeoutSeconds);
100-
activity?.SetTag("http.request.uri", SanitizeUri(request.RequestUri));
101-
activity?.AddEvent("http.retry.start", [
102-
new("status_code", (int)response.StatusCode)
103-
]);
89+
return response;
10490
}
10591

10692
attemptCount++;
10793

108-
activity?.AddEvent("http.retry.attempt_failed", [
109-
new("attempt_number", attemptCount),
110-
new("status_code", (int)response.StatusCode)
111-
]);
112-
113-
// Check if we've exceeded the timeout
114-
TimeSpan elapsedTime = DateTime.UtcNow - startTime;
115-
if (_retryTimeoutSeconds > 0 && elapsedTime.TotalSeconds > _retryTimeoutSeconds)
94+
// Check if we've exceeded the total wait time
95+
if (_retryTimeoutSeconds > 0 && totalRetrySeconds > _retryTimeoutSeconds)
11696
{
11797
// We've exceeded the timeout, so break out of the loop
11898
break;
@@ -129,39 +109,20 @@ protected override async Task<HttpResponseMessage> SendAsync(
129109
{
130110
// Use the Retry-After value
131111
waitSeconds = retryAfterSeconds;
132-
activity?.AddEvent("http.retry.using_server_retry_after", [
133-
new("wait_seconds", waitSeconds),
134-
new("attempt_number", attemptCount)
135-
]);
136-
activity?.SetTag("http.retry.backoff_strategy", "server_retry_after");
137-
lastErrorMessage = $"Service temporarily unavailable (HTTP {(int)response.StatusCode}). Using server-specified retry after {waitSeconds} seconds. Attempt {attemptCount}.";
112+
lastErrorMessage = $"Service temporarily unavailable (HTTP {(int)response.StatusCode}). Attempt {attemptCount}.";
138113
}
139114
else
140115
{
141116
// Invalid Retry-After value, use exponential backoff
142117
waitSeconds = CalculateBackoffWithJitter(currentBackoffSeconds);
143-
activity?.AddEvent("http.retry.invalid_retry_after_header", [
144-
new("retry_after_value", retryAfterValue),
145-
new("fallback_strategy", "exponential_backoff")
146-
]);
147-
activity?.AddEvent("http.retry.using_exponential_backoff", [
148-
new("wait_seconds", waitSeconds),
149-
new("attempt_number", attemptCount)
150-
]);
151-
activity?.SetTag("http.retry.backoff_strategy", "exponential");
152-
lastErrorMessage = $"Service temporarily unavailable (HTTP {(int)response.StatusCode}). Invalid Retry-After header, using exponential backoff of {waitSeconds} seconds. Attempt {attemptCount}.";
118+
lastErrorMessage = $"Service temporarily unavailable (HTTP {(int)response.StatusCode}). Attempt {attemptCount}.";
153119
}
154120
}
155121
else
156122
{
157123
// No Retry-After header, use exponential backoff
158124
waitSeconds = CalculateBackoffWithJitter(currentBackoffSeconds);
159-
activity?.AddEvent("http.retry.using_exponential_backoff", [
160-
new("wait_seconds", waitSeconds),
161-
new("attempt_number", attemptCount)
162-
]);
163-
activity?.SetTag("http.retry.backoff_strategy", "exponential");
164-
lastErrorMessage = $"Service temporarily unavailable (HTTP {(int)response.StatusCode}). Using exponential backoff of {waitSeconds} seconds. Attempt {attemptCount}.";
125+
lastErrorMessage = $"Service temporarily unavailable (HTTP {(int)response.StatusCode}). Attempt {attemptCount}.";
165126
}
166127

167128
// Dispose the response before retrying
@@ -178,43 +139,24 @@ protected override async Task<HttpResponseMessage> SendAsync(
178139
break;
179140
}
180141

181-
activity?.AddEvent("http.retry.waiting", [
182-
new("wait_seconds", waitSeconds),
183-
new("attempt_number", attemptCount)
184-
]);
185-
186142
// Wait for the calculated time
187143
await Task.Delay(TimeSpan.FromSeconds(waitSeconds), cancellationToken);
188144

189-
// Update metrics tags
190-
activity?.SetTag("http.retry.attempt_count", attemptCount);
191-
activity?.SetTag("http.retry.total_wait_seconds", totalRetrySeconds);
192-
193145
// Increase backoff for next attempt (exponential backoff)
194146
currentBackoffSeconds = Math.Min(currentBackoffSeconds * 2, _maxBackoffSeconds);
195147
} while (!cancellationToken.IsCancellationRequested);
196148

197-
// Set final summary tags (only reached if retries exhausted)
198149
activity?.SetTag("http.retry.total_attempts", attemptCount);
199-
activity?.SetTag("http.retry.total_elapsed_seconds",
200-
(DateTime.UtcNow - startTime).TotalSeconds);
201150
activity?.SetTag("http.response.status_code", (int)response.StatusCode);
202151

203152
// If we get here, we've either exceeded the timeout or been cancelled
204153
if (cancellationToken.IsCancellationRequested)
205154
{
206-
activity?.AddEvent("http.retry.cancelled", [
207-
new("total_attempts", attemptCount)
208-
]);
209155
activity?.SetTag("http.retry.outcome", "cancelled");
210156
throw new OperationCanceledException("Request cancelled during retry wait", cancellationToken);
211157
}
212158

213159
// Timeout exceeded
214-
activity?.AddEvent("http.retry.timeout_exceeded", [
215-
new("total_attempts", attemptCount),
216-
new("configured_timeout_seconds", _retryTimeoutSeconds)
217-
]);
218160
activity?.SetTag("http.retry.outcome", "timeout_exceeded");
219161
throw new DatabricksException(lastErrorMessage ?? "Service temporarily unavailable and retry timeout exceeded", AdbcStatusCode.IOError)
220162
.SetSqlState("08001");
@@ -264,14 +206,5 @@ private static async Task<HttpContent> CloneHttpContentAsync(HttpContent content
264206
return clone;
265207
}
266208

267-
/// <summary>
268-
/// Sanitizes a URI for logging by removing query parameters and sensitive information.
269-
/// </summary>
270-
private static string SanitizeUri(Uri? uri)
271-
{
272-
if (uri == null) return "(null)";
273-
// Return only scheme, host, port, and path
274-
return $"{uri.Scheme}://{uri.Host}{(uri.IsDefaultPort ? "" : $":{uri.Port}")}{uri.AbsolutePath}";
275-
}
276209
}
277210
}

0 commit comments

Comments
 (0)