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

[BUG] ArgumentNullException when calling CreateIfNotExistsAsync with OpenTelemetry populating a tag with the response message #41463

Closed
saasen opened this issue Jan 22, 2024 · 6 comments · Fixed by #41536
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Tables

Comments

@saasen
Copy link

saasen commented Jan 22, 2024

Library name and version

Azure.Data.Tables v12.8.0

Describe the bug

After adding OpenTelemetry to our app, we are getting the following exception and stack trace when calling CreateIfNotExistsAsync:

System.ArgumentNullException: Value cannot be null. (Parameter 'value')

Stack trace:

System.ArgumentNullException:
   at Azure.Data.Tables.Models.TableErrorCode..ctor (Azure.Data.Tables, Version=12.8.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
   at Azure.Data.Tables.Models.TableErrorCode.op_Implicit (Azure.Data.Tables, Version=12.8.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
   at Azure.Data.Tables.TableClient+<CreateIfNotExistsAsync>d__39.MoveNext (Azure.Data.Tables, Version=12.8.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   <client code omitted>

We have the following OpenTelemetry setup in Program.cs:

builder.Services.AddOpenTelemetry()
       .UseAzureMonitor()
       .WithTracing(traceBuilder =>
           traceBuilder
               .AddHttpClientInstrumentation(c =>
                {
                    c.EnrichWithHttpResponseMessage = (ac, res) =>
                    {
                        var statusCode = (int)res.StatusCode;
                        if (statusCode is >= (int)HttpStatusCode.BadRequest and < (int)HttpStatusCode.InternalServerError)
                        {
                            var body = res.Content.ReadAsStringAsync().Result;
                            if (!string.IsNullOrWhiteSpace(body))
                            {
                                ac.SetTag("http.response.body", body);
                            }
                        }
                    };
                })
               .AddAspNetCoreInstrumentation(config =>
               {
                   config.Filter = httpContext =>
                   {
                       var unwantedSegments = new[] { "/v1/healthchecks", "/metrics" };
                       foreach (var unwantedSegment in unwantedSegments)
                       {
                           if (httpContext.Request.Path.Value.StartsWith(unwantedSegment))
                           {
                               return false;
                           }
                       }

                       return true;
                   };
               })
       );

Versions:

Azure.Data.Tables v12.8.0
OpenTelemetry.Extensions.Hosting v1.6.0
OpenTelemetry.Instrumentation.AspNetCore v1.6.0-beta.3
OpenTelemetry.Instrumentation.Http v1.6.0-beta.3
Azure.Monitor.OpenTelemetry.AspNetCore v1.0.0

Expected behavior

An exception to not be thrown.

Actual behavior

An ArgumentNullException is getting thrown.

Reproduction Steps

Clone the following repo.

Environment

We are running this in Azure, but it is reproducible on a Windows 11 machine.

6.0.417 [/usr/local/share/dotnet/sdk]
Microsoft.AspNetCore.App 6.0.25 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
@saasen saasen changed the title [BUG] ArgumentNullException when calling CreateIfNotExistsAsync [BUG] ArgumentNullException when calling CreateIfNotExistsAsync with OpenTelemetry Jan 22, 2024
@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jan 22, 2024
@jsquire jsquire added Client This issue points to a problem in the data-plane of the library. Tables needs-team-attention This issue needs attention from Azure service team or SDK team and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Jan 22, 2024
@jsquire
Copy link
Member

jsquire commented Jan 22, 2024

Thank you for your feedback. Tagging and routing to the team member best able to assist.

@saasen saasen changed the title [BUG] ArgumentNullException when calling CreateIfNotExistsAsync with OpenTelemetry [BUG] ArgumentNullException when calling CreateIfNotExistsAsync with OpenTelemetry populating a tag with the response message Jan 23, 2024
@saasen
Copy link
Author

saasen commented Jan 23, 2024

Thanks!

I know that one shouldn't really call the .Result on an async method, but the EnrichWithHttpResponseMessage action in OpenTelemetry doesn't contain an async overload.

I don't understand why it would throw an exception by reading the response body.

@saasen
Copy link
Author

saasen commented Jan 23, 2024

As an FYI, this works fine against Azurite, but I guess that is not identical as going against the real storage tables.

@christothes
Copy link
Member

Does it still throw if you change .Result to GetAwaiter().GetResult() ?

@christothes christothes added the needs-author-feedback More information is needed from author to address the issue. label Jan 23, 2024
@github-actions github-actions bot removed the needs-team-attention This issue needs attention from Azure service team or SDK team label Jan 23, 2024
Copy link

Hi @saasen. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

@saasen
Copy link
Author

saasen commented Jan 24, 2024

Does it still throw if you change .Result to GetAwaiter().GetResult() ?

Yes.

@github-actions github-actions bot added needs-team-attention This issue needs attention from Azure service team or SDK team and removed needs-author-feedback More information is needed from author to address the issue. labels Jan 24, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Apr 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Tables
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants