-
Notifications
You must be signed in to change notification settings - Fork 790
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
SetErrorStatusOnException with async Exceptions works incorrectly #2753
Comments
I also hit this today. Are there eyes on this? |
Bump |
I spent some time looking at this today and was not able to reproduce the issue with the provided example. I tested a few other combinations inside nested activities:
I went looking for the specification on "otel.status_code" and found the definition of "ERROR":
Based on this, I think the current version of the SDK is working as intended. |
The reproduction in the original issue worked for me. Here's a variant of it:
Gives me these outputs:
I'd expect dotnet 7.0 with these OTEL versions:
|
Fairly sure I've just hit this problem in our code. Unfortunately this setting isn't useful to us without fixing this issue - if an exception is caught I don't want higher up activities being marked as errors. |
This issue was marked stale due to lack of activity and will be closed in 7 days. Commenting will instruct the bot to automatically remove the label. This bot runs once per day. |
Please do not close this. I believe it is still an issue. |
@BenHewins , I built upon the sample code you provided and added a Task.Delay of 1 millisecond in catch block to prevent all the outer activities from being marked as error state. The idea is that error status is dependent on the outcome of last asynchronous call. When Task.Delay finishes successfully after exception has been caught, it sets the status to non-error state. It would be similar to any other asynchronous actions that happened after exception is caught (not just Task.Delay). This is a temporary workaround but not a viable solution for larger code-bases because we'll need to exhaustively find all places where this scenario could occur. using System.Diagnostics;
using OpenTelemetry;
using OpenTelemetry.Trace;
public class Program
{
private static readonly ActivitySource MyActivitySource = new ActivitySource(
"MyCompany.MyProduct.MyLibrary");
public static async Task Main()
{
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource("MyCompany.MyProduct.MyLibrary")
.SetSampler(new AlwaysOnSampler())
.SetErrorStatusOnException()
.AddConsoleExporter()
.Build();
using (var activity1 = MyActivitySource.StartActivity("OutsideBar"))
{
await Bar();
// no exception here
}
}
private static async Task Bar()
{
await Task.Delay(100);
try
{
using (var activity2 = MyActivitySource.StartActivity("InsideBar"))
{
await Bar2();
}
}
catch
{
await Task.Delay(1); // successful completion of this task resets the status of the outer activitie
}
}
private static async Task Bar2()
{
await Task.Delay(100);
throw new Exception("Oops!");
}
} Here is the output with outer activity not marked as error anymore:
I used .net8.0
|
Wow nice workaround, that isn't at all how I would have expected the error identification to work! We worked around this by manually setting the status on the spans that we care about, had to do it twice though:
|
Bug Report
List of nugets
Runtime version:
Symptom
When
SetErrorStatusOnException
is enabled and exception occurred and was caught in nested async methed, the outer activities are incorrectly tagged ar Error.What is the expected behavior?
When all exceptions were caught in async methods, outer activities should not be tagged ar Error.
What is the actual behavior?
Currently when exception was thrown and caught in async method, outer activities are tagged as Error.
Reproduce
Code to reproduce the problem:
Current result:
Both activites are tagged with
otel.status_code: ERROR
The text was updated successfully, but these errors were encountered: