Skip to content

Commit c34fdea

Browse files
authored
Do not send agent API errors to telemetry logs (#6605)
* Introduce a logging marker (EXCLUDE_TELEMETRY) to exclude a log message from telemetry even if other criteria is met. This is meant to be used for very frequent errors that are better handled by metrics or other reporting mechanisms. * Use it for agent API errors (which may use trace_api.responses/trace_api.errors telemetry metrics, eventually).
1 parent 00ed7e7 commit c34fdea

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import datadog.communication.monitor.DDAgentStatsDClientManager;
88
import datadog.communication.monitor.Monitoring;
99
import datadog.communication.monitor.Recording;
10+
import datadog.trace.api.telemetry.LogCollector;
1011
import datadog.trace.util.Strings;
1112
import java.io.IOException;
1213
import java.nio.ByteBuffer;
@@ -376,7 +377,7 @@ public String getVersion() {
376377
}
377378

378379
private void errorQueryingEndpoint(String endpoint, Throwable t) {
379-
log.debug("Error querying {} at {}", endpoint, agentBaseUrl, t);
380+
log.debug(LogCollector.EXCLUDE_TELEMETRY, "Error querying {} at {}", endpoint, agentBaseUrl, t);
380381
}
381382

382383
public String state() {

dd-java-agent/agent-logging/src/main/java/datadog/trace/logging/ddlogger/DDTelemetryLogger.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ protected void log(LogLevel level, Marker marker, String msg, Throwable t) {
3737
}
3838

3939
private void telemetryLog(LogLevel level, Marker marker, String msgOrgFormat, Throwable t) {
40+
if (marker == LogCollector.EXCLUDE_TELEMETRY) {
41+
return;
42+
}
4043
// Report only messages with Throwable or explicitly marked with SEND_TELEMETRY.
4144
// This might be extended to error level without throwable.
4245
if (t == null && marker != LogCollector.SEND_TELEMETRY) {

dd-java-agent/agent-logging/src/test/groovy/datadog/trace/logging/ddlogger/DDTelemetryLoggerTest.groovy

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,22 @@ class DDTelemetryLoggerTest extends LogValidatingSpecification {
140140
call << allLogLevels
141141
level << allLogLevels
142142
}
143+
144+
void 'do not log #call(EXCLUDE_TELEMETRY, msg, throwable) call with level #level'() {
145+
given:
146+
def format = "msg"
147+
def t = new Exception()
148+
def logger = createLogger(level)
149+
150+
when:
151+
logger."$call"(LogCollector.EXCLUDE_TELEMETRY, format, t)
152+
def collection = LogCollector.get().drain()
153+
154+
then:
155+
collection.isEmpty()
156+
157+
where:
158+
call << allLogLevels
159+
level << allLogLevels
160+
}
143161
}

internal-api/src/main/java/datadog/trace/api/telemetry/LogCollector.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
public class LogCollector {
1616
public static final Marker SEND_TELEMETRY = MarkerFactory.getMarker("SEND_TELEMETRY");
17+
public static final Marker EXCLUDE_TELEMETRY = MarkerFactory.getMarker("EXCLUDE_TELEMETRY");
1718
private static final int DEFAULT_MAX_CAPACITY = 1024;
1819
private static final LogCollector INSTANCE = new LogCollector();
1920
private final Map<RawLogMessage, AtomicInteger> rawLogMessages;

0 commit comments

Comments
 (0)