|
9 | 9 | import datadog.trace.api.DDSpanId; |
10 | 10 | import datadog.trace.api.DDTraceId; |
11 | 11 | import datadog.trace.api.naming.SpanNaming; |
| 12 | +import datadog.trace.api.telemetry.LogCollector; |
12 | 13 | import datadog.trace.bootstrap.ContextStore; |
13 | 14 | import datadog.trace.bootstrap.instrumentation.api.AgentScope; |
14 | 15 | import datadog.trace.bootstrap.instrumentation.api.AgentSpan; |
@@ -68,6 +69,7 @@ public class JDBCDecorator extends DatabaseClientDecorator<DBInfo> { |
68 | 69 | Config.get().isDbMetadataFetchingOnQueryEnabled(); |
69 | 70 |
|
70 | 71 | private volatile boolean warnedAboutDBMPropagationMode = false; // to log a warning only once |
| 72 | + private volatile boolean loggedInjectionError = false; |
71 | 73 |
|
72 | 74 | public static void logMissingQueryInfo(Statement statement) throws SQLException { |
73 | 75 | if (log.isDebugEnabled()) { |
@@ -298,12 +300,7 @@ public void setAction(AgentSpan span, Connection connection) { |
298 | 300 |
|
299 | 301 | span.setTag("_dd.dbm_trace_injected", true); |
300 | 302 | } 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); |
307 | 304 | DECORATE.onError(span, e); |
308 | 305 | } |
309 | 306 | } |
@@ -358,12 +355,7 @@ public long setContextInfo(Connection connection, DBInfo dbInfo) { |
358 | 355 | throw e; |
359 | 356 | } |
360 | 357 | } 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); |
367 | 359 | DECORATE.onError(instrumentationSpan, e); |
368 | 360 | } finally { |
369 | 361 | instrumentationSpan.finish(); |
@@ -393,14 +385,7 @@ public void setApplicationName(AgentSpan span, Connection connection) { |
393 | 385 |
|
394 | 386 | connection.setClientInfo("ApplicationName", traceContext); |
395 | 387 | } 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); |
404 | 389 | DECORATE.onError(span, e); |
405 | 390 | } finally { |
406 | 391 | span.setTag(DBM_TRACE_INJECTED, true); |
@@ -436,4 +421,18 @@ public boolean shouldInjectSQLComment() { |
436 | 421 | return Config.get().getDbmPropagationMode().equals(DBM_PROPAGATION_MODE_FULL) |
437 | 422 | || Config.get().getDbmPropagationMode().equals(DBM_PROPAGATION_MODE_STATIC); |
438 | 423 | } |
| 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 | + } |
439 | 438 | } |
0 commit comments