Skip to content

Commit 3ee21aa

Browse files
Reduce verbosity of StatsD connection errors (#10618)
fix(metrics): Reduce verbosity of StatsD connection errors in non-debug mode fix(metrics): Prevent infinite loop when traversing exception causes in StatsD connection error logging Co-authored-by: bruce.bujon <bruce.bujon@datadoghq.com>
1 parent 0ce9153 commit 3ee21aa

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

products/metrics/metrics-lib/src/main/java/datadog/metrics/impl/statsd/DDAgentStatsDConnection.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,22 @@ private void doConnect() {
174174
log.debug("Max retries have been reached. Will not attempt again.");
175175
}
176176
} catch (Throwable t) {
177-
log.error("Unable to create StatsD client - {} - Will not retry", statsDAddress(), t);
177+
if (log.isDebugEnabled()) {
178+
// Display full stack traces on debug logs
179+
log.warn("Unable to create StatsD client - {} - Will not retry", statsDAddress(), t);
180+
} else {
181+
Throwable rootCause = t;
182+
int i = 100; // arbitrary limit to avoid infinite loops with cycling causes
183+
do {
184+
rootCause = rootCause.getCause();
185+
i--;
186+
} while (rootCause.getCause() != null && i > 0);
187+
log.warn(
188+
"Unable to create StatsD client - {} - Will not retry: {}, {}",
189+
statsDAddress(),
190+
t.getMessage(),
191+
rootCause.getMessage());
192+
}
178193
}
179194
}
180195
}

0 commit comments

Comments
 (0)