DataDog / dd-trace-java

Datadog APM client for Java
https://docs.datadoghq.com/tracing/languages/java
Apache License 2.0
583 stars 290 forks source link

JMXFetch does not set up proper log level #4993

Open stol002 opened 1 year ago

stol002 commented 1 year ago

In JMXFetch class when an instance of jmx collector is created the log level is not passed to it and jmx collector has it's own log level and it's not possible to set it up. You could simply do it by passing to jmx collector's configBuilder the value of JMXFetch.getLogLevel() like this:

final AppConfig.AppConfigBuilder configBuilder =
    AppConfig.builder()
        .action(Collections.singletonList(ACTION_COLLECT))
        // App should be run as daemon otherwise CLI apps would not exit once main method exits.
        .daemon(true)
        .embedded(true)
        .logLevel(getLogLevel())
        .confdDirectory(jmxFetchConfigDir)
        .yamlFileList(jmxFetchConfigs)
        .targetDirectInstances(true)
        .instanceConfigResources(DEFAULT_CONFIGS)
        .metricConfigResources(internalMetricsConfigs)
        .metricConfigFiles(metricsConfigs)
        .initialRefreshBeansPeriod(initialRefreshBeansPeriod)
        .refreshBeansPeriod(refreshBeansPeriod)
        .globalTags(globalTags)
        .reporter(new AgentStatsdReporter(statsd));
mcculls commented 1 year ago

Hi @stol002 - that was removed in v0.41.0 under PR https://github.com/DataDog/dd-trace-java/pull/1167

The reasoning was that because JMXFetch uses the same SLF4J runtime as the tracer it's embedded in, there is no need to explicitly set the logger level because it will be picked up from SLF4J. Those particular config methods are also only used in org.datadog.jmxfetchJmxFetch.main when JMXFetch is launched separately in its own process.

natterd commented 1 year ago

Could you explain that a bit further? I'd like to suppress INFO level log msgs from JMXFetch (org.datadog.jmxfetch.App, Instance, reporter.Reporter). Setting the level to WARN in log4j has no effect. How exactly do I set the log level for JMXFetch? Thank you

stol002 commented 1 year ago

I was trying to suppress JMXFetch logs by passing command line parameters -Ddatadog.slf4j.simpleLogger.defaultLogLevel=ERROR -Dorg.slf4j.simpleLogger.log.org.datadog.jmxfetch=ERROR. But this does not work for me. I have tones of WARNS which spoil my nice logs :)

mcculls commented 1 year ago

Could you share an example of those warnings?

Also the property to adjust the JMXFetch logging level would be:

-Ddatadog.slf4j.simpleLogger.log.org.datadog.jmxfetch=ERROR

In other words you can control the log level for any package in dd-java-agent with:

-Ddatadog.slf4j.simpleLogger.log.<package>=<level>
stol002 commented 1 year ago

Warnings look like this:

'[dd.trace 2023-10-07 11:08:35:643 +0200] [dd-jmx-collector] WARN org.datadog.jmxfetch.JmxAttribute - Unable to get metrics from java.lang:name=Eden Space,type=MemoryPool - UsageThreshold: javax.management.RuntimeMBeanException: java.lang.UnsupportedOperationException: Usage threshold is not supported [dd.trace 2023-10-07 11:08:35:644 +0200] [dd-jmx-collector] WARN org.datadog.jmxfetch.JmxAttribute - Unable to get metrics from java.lang:name=Eden Space,type=MemoryPool - UsageThresholdExceeded: javax.management.RuntimeMBeanException: java.lang.UnsupportedOperationException: Usage threshold is not supported [dd.trace 2023-10-07 11:08:35:645 +0200] [dd-jmx-collector] WARN org.datadog.jmxfetch.JmxAttribute - Unable to get metrics from java.lang:name=Eden Space,type=MemoryPool - UsageThresholdCount: javax.management.RuntimeMBeanException: java.lang.UnsupportedOperationException: Usage threshold is not supported [dd.trace 2023-10-07 11:08:35:649 +0200] [dd-jmx-collector] WARN org.datadog.jmxfetch.JmxAttribute - Unable to get metrics from java.lang:name=Eden Space,type=MemoryPool - Name: java.lang.NumberFormatException: For input string: "Eden Space" [dd.trace 2023-10-07 11:08:35:649 +0200] [dd-jmx-collector] WARN org.datadog.jmxfetch.JmxAttribute - Unable to get metrics from java.lang:name=Eden Space,type=MemoryPool - Type: java.lang.NumberFormatException: For input string: "HEAP" [dd.trace 2023-10-07 11:08:35:652 +0200] [dd-jmx-collector] WARN org.datadog.jmxfetch.JmxAttribute - Unable to get metrics from java.lang:name=CodeHeap 'profiled nmethods',type=MemoryPool - CollectionUsageThreshold: javax.management.RuntimeMBeanException: java.lang.UnsupportedOperationException: CollectionUsage threshold is not supported`

And I have really a lot of them

stol002 commented 1 year ago

@mcculls Thank you. Your advice helped me. -Ddatadog.slf4j.simpleLogger.log.org.datadog.jmxfetch=ERROR worked

natterd commented 1 year ago

Worked for me too. thx