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

Cannot set "isExpected" in the NoticeError method due to overload specificity #2787

Closed
mnbuhl opened this issue Oct 1, 2024 · 4 comments
Closed
Labels
bug Something isn't working community To tag external issues and PRs

Comments

@mnbuhl
Copy link

mnbuhl commented Oct 1, 2024

Description
NOTE: # ( Describe the problem you're encountering. )
[TIP]: # ( Do NOT share sensitive information, whether personal, proprietary, or otherwise! )

When calling NewRelic.Api.Agent.NewRelic.NoticeError, you are unable to set the isExpected parameter, no matter how you format the parameters parameter.

image

Expected Behavior
NOTE: # ( Tell us what you expected to happen. )

I expect to be able to set the "isExpected" property. The compiler will not accept it no matter how I define the parameters.

Troubleshooting or NR Diag results
NOTE: # ( Provide any other relevant log data such as the agent and/or profiler logs, preferably at DEBUG level or higher. )
[TIP]: # ( Scrub logs and diagnostic information for sensitive information )

Steps to Reproduce
NOTE: # ( Please be as specific as possible. )
[TIP]: # ( Link a sample application that demonstrates the issue. )

Try to call NoticeError with isExpected parameter

Your Environment
[TIP]: # ( Describe your environment, please include the running version of the agent, .NET Framework, .NET Core, or .NET versions, and any relevant configurations)

Tested on NewRelic.Agent.Api 10.29.0 and 10.31.0 using .NET 8

Additional context
[TIP]: # ( Add any other context about the problem here. For example, relevant community posts or support tickets. )

For Maintainers Only or Hero Triaging this bug
Suggested Priority (P1,P2,P3,P4,P5):
Suggested T-Shirt size (S, M, L, XL, Unknown):

@mnbuhl mnbuhl added the bug Something isn't working label Oct 1, 2024
@workato-integration
Copy link

@github-actions github-actions bot added the community To tag external issues and PRs label Oct 1, 2024
@nrcventura
Copy link
Member

@mnbuhl Thank you for reaching out to us. In this case you are attempting to use an overload that does not exist. See

public static void NoticeError(Exception exception, IDictionary<string, string>? parameters)
{
try
{
System.Diagnostics.Trace.WriteLine($"NewRelic.NoticeError({nameof(exception)},{nameof(parameters)})");
}
catch
{
// Swallow any exception thrown from here
}
}
/// <summary>
/// Notice an error identified by an exception report it to the New Relic service.
/// If this method is called within a transaction,
/// the exception will be reported with the transaction when it finishes.
/// If it is invoked outside of a transaction, a traced error will be created and reported to the New Relic service.
/// Only the exception/parameter pair for the first call to NoticeError during the course of a transaction is retained.
/// Supports web applications only.
/// </summary>
/// <param name="exception">The exception to be reported.
/// Only part of the exception's information may be retained to prevent the report from being too large.
/// </param>
/// <param name="parameters">Custom parameters to include in the traced error.
/// May be null.
/// Only 10,000 characters of combined key/value data is retained.
/// </param>
/// <example>
/// <code>
/// try
/// {
/// var ImNotABool = "43";
/// bool.Parse(ImNotABool);
/// }
/// catch (Exception ex)
/// {
/// var quotes = new Dictionary&lt;string,string&gt;();
/// quotes.Add("1", "They had a large chunk of the garbage file? How much do they know?");
/// quotes.Add("2", "I'll hack the Gibson.");
/// quotes.Add("3", "Zero Cool? Crashed fifteen hundred and seven systems in one day?");
/// quotes.Add("4", "Turn on your laptop. Set it to receive a file.");
/// quotes.Add("5", "Listen you guys, help yourself to anything in the fridge. Cereal has.");
/// NewRelic.Api.Agent.NewRelic.NoticeError(ex, quotes);
/// }
/// </code>
/// </example>
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public static void NoticeError(Exception exception, IDictionary<string, object>? parameters)
{
try
{
System.Diagnostics.Trace.WriteLine($"NewRelic.NoticeError({nameof(exception)},{nameof(parameters)})");
}
catch
{
// Swallow any exception thrown from here
}
}
/// <summary>
/// Notice an error identified by an exception and report it to the New Relic service.
/// If this method is called within a transaction,
/// the exception will be reported with the transaction when it finishes.
/// If it is invoked outside of a transaction, a traced error will be created and reported to the New Relic service.
/// Only the exception/parameter pair for the first call to NoticeError during the course of a transaction is retained.
/// Supports web applications only.
/// </summary>
/// <param name="exception">The exception to be reported.
/// Only part of the exception's information may be retained to prevent the report from being too large.
/// </param>
/// <example>
/// <code>
/// try
/// {
/// var ImNotABool = "43";
/// bool.Parse(ImNotABool);
/// }
/// catch (Exception ex)
/// {
/// NewRelic.Api.Agent.NewRelic.NoticeError(ex);
/// }
/// </code>
/// </example>
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public static void NoticeError(Exception exception)
{
try
{
System.Diagnostics.Trace.WriteLine($"NewRelic.NoticeError({nameof(exception)})");
}
catch
{
// Swallow any exception thrown from here
}
}
/// <summary>
/// Notice an error identified by a simple message and report it to the New Relic service.
/// If this method is called within a transaction,
/// the exception will be reported with the transaction when it finishes.
/// If it is invoked outside of a transaction, a traced error will be created and reported to the New Relic service.
/// Only the string/parameter pair for the first call to NoticeError during the course of a transaction is retained.
/// Supports web applications only.
/// </summary>
/// <param name="message">The message to be displayed in the traced error.
/// This method creates both Error Events and Error Traces.
/// Only the first 255 characters are retained in Error Events while Error Traces will retain the full message.
/// </param>
/// <param name="parameters">Custom parameters to include in the traced error.
/// May be null.
/// Only 10,000 characters of combined key/value data is retained.
/// </param>
/// <example>
/// <code>
/// try
/// {
/// var ImNotABool = "43";
/// bool.Parse(ImNotABool);
/// }
/// catch (Exception ex)
/// {
/// var quotes = new Dictionary&lt;string,string&gt;();
/// quotes.Add("1", "They had a large chunk of the garbage file? How much do they know?");
/// quotes.Add("2", "I'll hack the Gibson.");
/// quotes.Add("3", "Zero Cool? Crashed fifteen hundred and seven systems in one day?");
/// quotes.Add("4", "Turn on your laptop. Set it to receive a file.");
/// quotes.Add("5", "Listen you guys, help yourself to anything in the fridge. Cereal has.");
/// NewRelic.Api.Agent.NewRelic.NoticeError(ex.Message, quotes);
/// }
/// </code>
/// </example>
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public static void NoticeError(string message, IDictionary<string, string>? parameters)
{
try
{
System.Diagnostics.Trace.WriteLine($"NewRelic.NoticeError({nameof(message)},{nameof(parameters)})");
}
catch
{
// Swallow any exception thrown from here
}
}
/// <summary>
/// Notice an error identified by a simple message and report it to the New Relic service.
/// If this method is called within a transaction,
/// the exception will be reported with the transaction when it finishes.
/// If it is invoked outside of a transaction, a traced error will be created and reported to the New Relic service.
/// Only the string/parameter pair for the first call to NoticeError during the course of a transaction is retained.
/// Supports web applications only.
/// </summary>
/// <param name="message">The message to be displayed in the traced error.
/// This method creates both Error Events and Error Traces.
/// Only the first 255 characters are retained in Error Events while Error Traces will retain the full message.
/// </param>
/// <param name="parameters">Custom parameters to include in the traced error.
/// May be null.
/// Only 10,000 characters of combined key/value data is retained.
/// </param>
/// <example>
/// <code>
/// try
/// {
/// var ImNotABool = "43";
/// bool.Parse(ImNotABool);
/// }
/// catch (Exception ex)
/// {
/// var quotes = new Dictionary&lt;string,string&gt;();
/// quotes.Add("1", "They had a large chunk of the garbage file? How much do they know?");
/// quotes.Add("2", "I'll hack the Gibson.");
/// quotes.Add("3", "Zero Cool? Crashed fifteen hundred and seven systems in one day?");
/// quotes.Add("4", "Turn on your laptop. Set it to receive a file.");
/// quotes.Add("5", "Listen you guys, help yourself to anything in the fridge. Cereal has.");
/// NewRelic.Api.Agent.NewRelic.NoticeError(ex.Message, quotes);
/// }
/// </code>
/// </example>
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public static void NoticeError(string message, IDictionary<string, object>? parameters)
{
try
{
System.Diagnostics.Trace.WriteLine($"NewRelic.NoticeError({nameof(message)},{nameof(parameters)})");
}
catch
{
// Swallow any exception thrown from here
}
}
/// <summary>
/// Notice an error identified by a simple message and report it to the New Relic service.
/// If this method is called within a transaction,
/// the exception will be reported with the transaction when it finishes.
/// If it is invoked outside of a transaction, a traced error will be created and reported to the New Relic service.
/// Only the string/parameter pair for the first call to NoticeError during the course of a transaction is retained.
/// Supports web applications only.
/// </summary>
/// <param name="message">The message to be displayed in the traced error.
/// This method creates both Error Events and Error Traces.
/// Only the first 255 characters are retained in Error Events while Error Traces will retain the full message.
/// </param>
/// <param name="parameters">Custom parameters to include in the traced error.
/// May be null.
/// Only 10,000 characters of combined key/value data is retained.
/// </param>
/// <param name="isExpected">
/// Mark an error as expected.
/// </param>>
/// <example>
/// <code>
/// try
/// {
/// var ImNotABool = "43";
/// bool.Parse(ImNotABool);
/// }
/// catch (Exception ex)
/// {
/// var quotes = new Dictionary&lt;string,string&gt;();
/// quotes.Add("1", "They had a large chunk of the garbage file? How much do they know?");
/// quotes.Add("2", "I'll hack the Gibson.");
/// quotes.Add("3", "Zero Cool? Crashed fifteen hundred and seven systems in one day?");
/// quotes.Add("4", "Turn on your laptop. Set it to receive a file.");
/// quotes.Add("5", "Listen you guys, help yourself to anything in the fridge. Cereal has.");
/// NewRelic.Api.Agent.NewRelic.NoticeError(ex.Message, quotes, true);
/// }
/// </code>
/// </example>
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public static void NoticeError(string message, IDictionary<string, string>? parameters, bool isExpected)
{
try
{
System.Diagnostics.Trace.WriteLine($"NewRelic.NoticeError({nameof(message)},{nameof(parameters)},{nameof(isExpected)})");
}
catch
{
// Swallow any exception thrown from here
}
}
/// <summary>
/// Notice an error identified by a simple message and report it to the New Relic service.
/// If this method is called within a transaction,
/// the exception will be reported with the transaction when it finishes.
/// If it is invoked outside of a transaction, a traced error will be created and reported to the New Relic service.
/// Only the string/parameter pair for the first call to NoticeError during the course of a transaction is retained.
/// Supports web applications only.
/// </summary>
/// <param name="message">The message to be displayed in the traced error.
/// This method creates both Error Events and Error Traces.
/// Only the first 255 characters are retained in Error Events while Error Traces will retain the full message.
/// </param>
/// <param name="parameters">Custom parameters to include in the traced error.
/// May be null.
/// Only 10,000 characters of combined key/value data is retained.
/// </param>
/// <param name="isExpected">
/// Mark an error as expected.
/// </param>>
/// <example>
/// <code>
/// try
/// {
/// var ImNotABool = "43";
/// bool.Parse(ImNotABool);
/// }
/// catch (Exception ex)
/// {
/// var quotes = new Dictionary&lt;string,string&gt;();
/// quotes.Add("1", "They had a large chunk of the garbage file? How much do they know?");
/// quotes.Add("2", "I'll hack the Gibson.");
/// quotes.Add("3", "Zero Cool? Crashed fifteen hundred and seven systems in one day?");
/// quotes.Add("4", "Turn on your laptop. Set it to receive a file.");
/// quotes.Add("5", "Listen you guys, help yourself to anything in the fridge. Cereal has.");
/// NewRelic.Api.Agent.NewRelic.NoticeError(ex.Message, quotes, true);
/// }
/// </code>
/// </example>
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public static void NoticeError(string message, IDictionary<string, object>? parameters, bool isExpected)
{
try
{
System.Diagnostics.Trace.WriteLine($"NewRelic.NoticeError({nameof(message)},{nameof(parameters)},{nameof(isExpected)})");
}
catch
{
// Swallow any exception thrown from here
}
}
for the available NoticeError overloads.

In order to prevent precedence confusion, only the "string error" overloads (not the "exception" overloads, include the boolean parameter to specify whether or not an error is expected. The expectation is that expected errors are controlled by agent configuration settings. Those configuration settings are applicable to exceptions, but not applicable to errors that come is as just strings. For the errors that come in as just strings, we provide overloads to allow those errors to be flagged as expected (because using the configuration settings will not work). For the exception-based overloads we do not provide that parameter, because it will cause confusion about which setting should be used, the parameter or the configuration settings. As a result, if you want to mark an exception as expected you need to use the agent configuration to control which exceptions are expected. If you just have an error string such as "My error string" and no exception, then you can use one of the string overloads to specify that the error is expected.

@mnbuhl
Copy link
Author

mnbuhl commented Oct 1, 2024

I am blind 🤦 Thank you for clarifying and sorry for taking some of your time @nrcventura. I'll use for agent configuration settings for this. Thanks for pointing me in the right direction, and have a nice day ⭐

@nrcventura
Copy link
Member

Not a problem. Questions similar to this have come up a few times in the last year, and this gave me an opportunity to document the current rationale for the differences between some of these overloads.

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

No branches or pull requests

2 participants