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

Expected behavior of HttpClientInstrumentation RecordException=true #1788

Open
notcool11 opened this issue Jul 30, 2021 · 2 comments
Open

Expected behavior of HttpClientInstrumentation RecordException=true #1788

notcool11 opened this issue Jul 30, 2021 · 2 comments
Assignees
Labels
comp:instrumentation.http Things related to OpenTelemetry.Instrumentation.Http question Further information is requested

Comments

@notcool11
Copy link

When should HttpClientInstrumentation create an Activity Event when RecordException=true??

Describe your environment.
n/a

Describe any aspect of your environment relevant to the question.

What are you trying to achieve?
I'd like to get the exception details from outbound HttpClient requests added as Activity Events when RecordException=true

Here is my startup.cs configuration:

            service.AddOpenTelemetryTracing((builder) => builder
                .SetResourceBuilder(
                    ResourceBuilder.
                    CreateDefault().
                    AddService("myapp").
                    AddAttributes(infrastructureTags))                    
                .AddAspNetCoreInstrumentation((options) => 
                    {
                        options.RecordException = true;
                        options.Enrich = EnrichParentSpan;
                    })                    
                .AddHttpClientInstrumentation((options) =>
                    {
                        options.RecordException = true;
                        options.Enrich = EnrichChildSpan;
                    })
                .SetSampler(new AlwaysOnSampler())
                .AddOtlpExporter(options =>
                {
                    options.Endpoint = OtlpUri;
                })
            );

If the parent service fails I get an Activity Event with the Exception details. I can also see that the activityEventName in my EnrichParentSpan method is OnException and it gives me access to the Exception object.

If an outbound request fails (404) the client span does not have an Activity Event with the Exception details, but it will set the error tag to true and the status.code tag to 2. When debugging my EnrichChildSpan method the activityEventName is OnStopActivity and I'll get access to the HttpResponseMessage object.

What did you expect to see?
I expected the behavior for inbound and outbound Exception processing to be the same, namely that if an error is returned from an outbound call it would log the same as an inbound call.

Is the expectation that I would code the response processing myself in my EnrichChildSpan method and to something like this??

                try
                {
                    httpResponseMessage.EnsureSuccessStatusCode();
                }
                catch (Exception exception)
                {
                    activity.RecordException(exception);                    
                    throw;
                }

The HttpHandlerDiagnosticListener has an exception method that will record the exception, but it doesn't get hit. Not sure if this is intended, thanks for the clarification.

Additional Context

Add any other context about the problem here. If you followed an existing
documentation, please share the link to it.

@notcool11 notcool11 added the question Further information is requested label Jul 30, 2021
@cijothomas
Copy link
Member

@vishweshbankwar When you get a chance, can you check this?

@lhidalgo89
Copy link

@cijothomas @vishweshbankwar Any updates on this by chance?

@vishweshbankwar vishweshbankwar transferred this issue from open-telemetry/opentelemetry-dotnet May 14, 2024
@Kielek Kielek added the comp:instrumentation.http Things related to OpenTelemetry.Instrumentation.Http label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:instrumentation.http Things related to OpenTelemetry.Instrumentation.Http question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants