newrelic / newrelic-java-agent

The New Relic Java agent
Apache License 2.0
202 stars 144 forks source link

Don't log full exception stack for expected NPE in noticeTracer #2143

Closed jasonjkeller closed 2 weeks ago

jasonjkeller commented 2 weeks ago

Resolves https://github.com/newrelic/newrelic-java-agent/issues/2141

There's a point early in the agent's lifecycle where the ProfilerService service is not yet initialized that can result in the agent logging the following exception stack:

2024-11-12T16:05:05,468-0800 [22649 36] com.newrelic.agent.instrumentation.ClassTransformerServiceImpl FINEST: exception in noticeTracer: null. This may affect thread profile v2.
java.lang.NullPointerException: Cannot invoke "com.newrelic.agent.profile.ProfilerService.getTransactionProfileService()" because the return value of "com.newrelic.agent.service.ServiceFactory.getProfilerService()" is null
    at com.newrelic.agent.instrumentation.InstrumentationImpl.noticeTracer(InstrumentationImpl.java:381) [newrelic-agent-8.15.0.jar:8.15.0]
    at com.newrelic.agent.instrumentation.InstrumentationImpl.createTracer(InstrumentationImpl.java:199) [newrelic-agent-8.15.0.jar:8.15.0]
    at java.lang.ProcessImpl.waitFor(ProcessImpl.java) [?:?]
    at com.newrelic.agent.utilization.DataFetcher.executeCommand(DataFetcher.java:241) [newrelic-agent-8.15.0.jar:8.15.0]
    at com.newrelic.agent.utilization.DataFetcher.access$000(DataFetcher.java:33) [newrelic-agent-8.15.0.jar:8.15.0]
    at com.newrelic.agent.utilization.DataFetcher$1.call(DataFetcher.java:65) [newrelic-agent-8.15.0.jar:8.15.0]
    at com.newrelic.agent.utilization.DataFetcher$1.call(DataFetcher.java:42) [newrelic-agent-8.15.0.jar:8.15.0]
    at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
    at java.lang.Thread.run(Thread.java:833) [?:?]

Since this is not indicative of a real problem it doesn't seem necessary to always log an exception stack that muddies up the agent logs. This PR changes the logging to just log the message so that it's less alarming:

2024-11-13T14:39:48,969-0800 [45830 44] com.newrelic.agent.instrumentation.ClassTransformerServiceImpl FINEST: Exception in noticeTracer. This may affect thread profile v2. Tracer: null. Error message: Cannot invoke "com.newrelic.agent.profile.ProfilerService.getTransactionProfileService()" because the return value of "com.newrelic.agent.service.ServiceFactory.getProfilerService()" is null
codecov-commenter commented 2 weeks ago

Codecov Report

Attention: Patch coverage is 16.66667% with 5 lines in your changes missing coverage. Please review.

Project coverage is 70.70%. Comparing base (305a4d9) to head (aa52824). Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...lic/agent/instrumentation/InstrumentationImpl.java 16.66% 5 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #2143 +/- ## ========================================= Coverage 70.69% 70.70% + Complexity 9985 9982 -3 ========================================= Files 841 841 Lines 40290 40291 +1 Branches 6107 6107 ========================================= + Hits 28485 28487 +2 + Misses 9062 9059 -3 - Partials 2743 2745 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.