@@ -68,6 +68,7 @@ public class JDBCDecorator extends DatabaseClientDecorator<DBInfo> {
6868 Config .get ().isDbMetadataFetchingOnQueryEnabled ();
6969
7070 private volatile boolean warnedAboutDBMPropagationMode = false ; // to log a warning only once
71+ private volatile boolean loggedInjectionError = false ;
7172
7273 public static void logMissingQueryInfo (Statement statement ) throws SQLException {
7374 if (log .isDebugEnabled ()) {
@@ -298,12 +299,7 @@ public void setAction(AgentSpan span, Connection connection) {
298299
299300 span .setTag ("_dd.dbm_trace_injected" , true );
300301 } catch (Throwable e ) {
301- log .debug (
302- "Failed to set extra DBM data in action 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 );
302+ logInjectionErrorOnce ("action" , e );
307303 DECORATE .onError (span , e );
308304 }
309305 }
@@ -358,12 +354,7 @@ public long setContextInfo(Connection connection, DBInfo dbInfo) {
358354 throw e ;
359355 }
360356 } 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 );
357+ logInjectionErrorOnce ("context_info" , e );
367358 DECORATE .onError (instrumentationSpan , e );
368359 } finally {
369360 instrumentationSpan .finish ();
@@ -393,14 +384,7 @@ public void setApplicationName(AgentSpan span, Connection connection) {
393384
394385 connection .setClientInfo ("ApplicationName" , traceContext );
395386 } 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- }
387+ logInjectionErrorOnce ("application_name" , e );
404388 DECORATE .onError (span , e );
405389 } finally {
406390 span .setTag (DBM_TRACE_INJECTED , true );
@@ -436,4 +420,17 @@ public boolean shouldInjectSQLComment() {
436420 return Config .get ().getDbmPropagationMode ().equals (DBM_PROPAGATION_MODE_FULL )
437421 || Config .get ().getDbmPropagationMode ().equals (DBM_PROPAGATION_MODE_STATIC );
438422 }
423+
424+ private void logInjectionErrorOnce (String vessel , Throwable t ) {
425+ if (!loggedInjectionError ) {
426+ loggedInjectionError = true ;
427+ log .warn (
428+ "Failed to set extra DBM data in {}. "
429+ + "To disable this behavior, set trace_prepared_statements to 'false'. "
430+ + "See https://docs.datadoghq.com/database_monitoring/connect_dbm_and_apm/ for more info. "
431+ + "Will not log again for this kind of error.\n {}" ,
432+ vessel ,
433+ t );
434+ }
435+ }
439436}
0 commit comments