Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NewRelic.Api.Agent.NewRelic.RecordMetric() spams in program debug output #3018

Open
Qtax opened this issue Mar 4, 2025 · 5 comments · May be fixed by #3029
Open

NewRelic.Api.Agent.NewRelic.RecordMetric() spams in program debug output #3018

Qtax opened this issue Mar 4, 2025 · 5 comments · May be fixed by #3029
Labels
bug Something isn't working community To tag external issues and PRs

Comments

@Qtax
Copy link

Qtax commented Mar 4, 2025

Each time NewRelic.Api.Agent.NewRelic.RecordMetric() is called, we get a line in our programs output:

NewRelic.RecordMetric(name,value)

How do we get rid of this? It gets really spammy and our applications output is getting filled with these.

This is in a .NET Framework MVC app (IIS hosted), with NewRelic.Agent.Api version 10.37.0 via NuGet.

Below is a screenshot from a clean .NET Framework MVC project with an added RecordMetric call:

Image


The decompiled implementation of the called RecordMetric() is:

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void RecordMetric(string name, float value)
{
    try {
        Trace.WriteLine("NewRelic.RecordMetric(name,value)");
    }
    catch {
    }
}

Which clearly outputs NewRelic.RecordMetric(name,value).

We do not want any output when recording metrics.

@Qtax Qtax added the bug Something isn't working label Mar 4, 2025
@workato-integration
Copy link

@github-actions github-actions bot added the community To tag external issues and PRs label Mar 4, 2025
@nr-ahemsath
Copy link
Member

@Qtax Thank you for bringing this issue to our attention.

The decompiled code you found that makes the System.Diagnostics.Trace.WriteLine() call is stub code present in the agent API assembly. When the New Relic .NET agent is actually attached to your application, the agent rewires the stub calls to point to the actual API implementation code in the agent. If you're seeing those trace calls in your program's output, the agent must not be attached and enabled. Does that make sense?

By default, System.Diagnostics.Trace.WriteLine() calls don't result in any program output. Does your application create or enable any trace listeners?

@Qtax
Copy link
Author

Qtax commented Mar 5, 2025

Thanks for clearing up how it's supposed to work. In our case I assume that the agent is not attached. But for development I think this is how we'd want it if possible. (Since most of the work our developers do does not need or relate to New Relic.)

By default, System.Diagnostics.Trace.WriteLine() calls don't result in any program output. Does your application create or enable any trace listeners?

We have not defined any trace listeners. And there are none configured from what I can see in any Web.config. This is reproducible in a clean Visual Studio 2022 "ASP.NET Web Application (.NET Framework)" MVC project, with just New Relic calls added.

It seems that by default System.Diagnostics.Trace.WriteLine writes to standard output if the TRACE build time constant is defined. This constant is defined by default in such a project in both Debug and Release builds. Not defining the TRACE build constant results in Trace.WriteLine calls from my application not producing any output, but the Trace.WriteLine call made in NewRelic.Api.Agent.NewRelic.RecordMetric still produces output. Even in "Release" builds without TRACE defined.

My guess is that the published NewRelic.Api.Agent NuGet packaged was built with the TRACE constant defined (as seems to be the default), and that results in it writing to program output no matter how we build our application.

Default TRACE constant settings in clean test app:

Debug

Release


Here's example of the apps own Trace.WriteLine() calls not generating any output, but RecordMetric() call still does:

Output from RecordMetric

@nr-ahemsath
Copy link
Member

@Qtax Thanks for the additional info and the screenshots, they make it clear was the issue is. I am able to reproduce what you are seeing now (I was previously only looking at the actual console output from a test application run from the command line, not the "Debug" output window in Visual Studio when running the app from VS).

We'll try to come up with a workaround.

@nr-ahemsath
Copy link
Member

This is probably related somehow, if not the root cause of the issue (we can't see that we're setting TRACE enabled in the API assembly project, but it is probably turned on by default and we need to figure out how to disable it): dotnet/sdk#11530

@nr-ahemsath nr-ahemsath linked a pull request Mar 6, 2025 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working community To tag external issues and PRs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants