Skip to content

Commit c5a2b22

Browse files
authored
Log injection issues in JDBC only once + promote to WARN (#10214)
* fix log text * log injection error messages only once + raise level to warn * exclude from telemetry
1 parent 3101a85 commit c5a2b22

File tree

1 file changed

+19
-20
lines changed
  • dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc

1 file changed

+19
-20
lines changed

dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/JDBCDecorator.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import datadog.trace.api.DDSpanId;
1010
import datadog.trace.api.DDTraceId;
1111
import datadog.trace.api.naming.SpanNaming;
12+
import datadog.trace.api.telemetry.LogCollector;
1213
import datadog.trace.bootstrap.ContextStore;
1314
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
1415
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
@@ -68,6 +69,7 @@ public class JDBCDecorator extends DatabaseClientDecorator<DBInfo> {
6869
Config.get().isDbMetadataFetchingOnQueryEnabled();
6970

7071
private volatile boolean warnedAboutDBMPropagationMode = false; // to log a warning only once
72+
private volatile boolean loggedInjectionError = false;
7173

7274
public static void logMissingQueryInfo(Statement statement) throws SQLException {
7375
if (log.isDebugEnabled()) {
@@ -298,12 +300,7 @@ public void setAction(AgentSpan span, Connection connection) {
298300

299301
span.setTag("_dd.dbm_trace_injected", true);
300302
} catch (Throwable e) {
301-
log.debug(
302-
"Failed to set extra DBM data in application_name for trace {}. "
303-
+ "To disable this behavior, set trace_prepared_statements to 'false'. "
304-
+ "See https://docs.datadoghq.com/database_monitoring/connect_dbm_and_apm/ for more info. {}",
305-
span.getTraceId().toHexString(),
306-
e);
303+
logInjectionErrorOnce("action", e);
307304
DECORATE.onError(span, e);
308305
}
309306
}
@@ -358,12 +355,7 @@ public long setContextInfo(Connection connection, DBInfo dbInfo) {
358355
throw e;
359356
}
360357
} catch (Exception e) {
361-
log.debug(
362-
"Failed to set extra DBM data in context info for trace {}. "
363-
+ "To disable this behavior, set DBM_PROPAGATION_MODE to 'service' mode. "
364-
+ "See https://docs.datadoghq.com/database_monitoring/connect_dbm_and_apm/ for more info.{}",
365-
instrumentationSpan.getTraceId().toHexString(),
366-
e);
358+
logInjectionErrorOnce("context_info", e);
367359
DECORATE.onError(instrumentationSpan, e);
368360
} finally {
369361
instrumentationSpan.finish();
@@ -393,14 +385,7 @@ public void setApplicationName(AgentSpan span, Connection connection) {
393385

394386
connection.setClientInfo("ApplicationName", traceContext);
395387
} catch (Throwable e) {
396-
if (log.isDebugEnabled()) {
397-
log.debug(
398-
"Failed to set extra DBM data in application_name for trace {}. "
399-
+ "To disable this behavior, set trace_prepared_statements to 'false'. "
400-
+ "See https://docs.datadoghq.com/database_monitoring/connect_dbm_and_apm/ for more info.{}",
401-
span.getTraceId().toHexString(),
402-
e);
403-
}
388+
logInjectionErrorOnce("application_name", e);
404389
DECORATE.onError(span, e);
405390
} finally {
406391
span.setTag(DBM_TRACE_INJECTED, true);
@@ -436,4 +421,18 @@ public boolean shouldInjectSQLComment() {
436421
return Config.get().getDbmPropagationMode().equals(DBM_PROPAGATION_MODE_FULL)
437422
|| Config.get().getDbmPropagationMode().equals(DBM_PROPAGATION_MODE_STATIC);
438423
}
424+
425+
private void logInjectionErrorOnce(String vessel, Throwable t) {
426+
if (!loggedInjectionError) {
427+
loggedInjectionError = true;
428+
log.warn(
429+
LogCollector.EXCLUDE_TELEMETRY, // nothing we can do on our side about this
430+
"Failed to set extra DBM data in {}. "
431+
+ "To disable this behavior, set trace_prepared_statements to 'false'. "
432+
+ "See https://docs.datadoghq.com/database_monitoring/connect_dbm_and_apm/ for more info. "
433+
+ "Will not log again for this kind of error.\n{}",
434+
vessel,
435+
t);
436+
}
437+
}
439438
}

0 commit comments

Comments
 (0)