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

SetErrorStatusOnException doesn't set Activity.Status #4333

Closed
MatisseHack opened this issue Mar 24, 2023 · 2 comments · Fixed by #4336
Closed

SetErrorStatusOnException doesn't set Activity.Status #4333

MatisseHack opened this issue Mar 24, 2023 · 2 comments · Fixed by #4336

Comments

@MatisseHack
Copy link

Bug Report

List of all OpenTelemetry NuGet packages and version that you are using (e.g. OpenTelemetry 1.0.2):

  • OpenTelemetry 1.4.0

Runtime version (e.g. net462, net48, netcoreapp3.1, net6.0 etc. You can find this information from the *.csproj file):

  • net7.0

Symptom

SetErrorStatusOnException doesn't set Activity.Status. If I'm reading correctly, it looks like the exception processor calls into an extension method that sets tags on the activity instead:

public static void SetStatus(this Activity activity, Status status)
{
Debug.Assert(activity != null, "Activity should not be null");
activity.SetTag(SpanAttributeConstants.StatusCodeKey, StatusHelper.GetTagValueForStatusCode(status.StatusCode));
activity.SetTag(SpanAttributeConstants.StatusDescriptionKey, status.Description);
}

What is the expected behavior?

Spans that contained an exception should be marked as failed.

What is the actual behavior?

Some exporters (e.g. Jaeger via OTLP) recognize these tags and properly display the spans as failed. However, some exporters (e.g. Azure.Monitor.OpenTelemetry.Exporter) only look at Activity.Status and don't display the spans as failed.

Reproduce

The following program exhibits this issue where failed spans do not show up as such in Azure:

public class Program
{
    private static readonly ActivitySource MyActivitySource = new("MyCompany.MyProduct.MyLibrary");

    public static void Main()
    {
        using var tracerProvider = Sdk.CreateTracerProviderBuilder()
            .AddSource("MyCompany.MyProduct.MyLibrary")
            .SetErrorStatusOnException()
            .AddAzureMonitorTraceExporter()
            .Build();

        try
        {
            using (MyActivitySource.StartActivity("Foo"))
            {
                throw new Exception("Oops!");
            }
        }
        catch (Exception)
        {
            // swallow the exception
        }
    }
}

Additional Context

Is there any reason to avoid setting Activity.Status for uncaught exceptions or is this implementation just a historical artifact from earlier versions of .NET?

@MatisseHack MatisseHack added the bug Something isn't working label Mar 24, 2023
@cijothomas
Copy link
Member

Thanks for reporting.
Storing status as tag was done as a workaround for the limitation that Activity did not support Status originally. We moved all components in this repo to switch to Status, but this was left out. This can be fixed easily though.

@cijothomas
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants