apitoolkit / apitoolkit-dotnet

APItoolkit's .Net client SDK.
https://apitoolkit.io/docs/sdks/dotnet/dotnetcore/
MIT License
7 stars 1 forks source link

RequestBody is Empty in Logged Request #35

Open craigeddy opened 2 months ago

craigeddy commented 2 months ago

Describe the bug

Using the following to configure APItoolkit in my .Net 8 ASP.NET Core API, I do not get anything in the endpoint logs' RequestBody. ResponseBody has expected values:

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
...
...
            // Initialize the APItoolkit client
            var config = new Config
            {
                ApiKey = "<API KEY>",
                Debug = false,
                Tags = ["external_api"],
                ServiceVersion = "v2.0",
                RedactResponseBody = ["$.ownerEmail"],
                RedactRequestBody =  ["$.ownerEmail"]
            };

            var client = APIToolkit.NewClientAsync(config).Result;
            // END Initialize the APItoolkit client

            // Register the middleware to use the initialized client
            app.Use(async (context, next) =>
            {
                // added this line based on searching for issue, didn't help:
                context.Request.EnableBuffering();

                var apiToolkit = new APIToolkit(next, client);
                await apiToolkit.InvokeAsync(context);
            });           

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
...

To Reproduce

No response

System

Windows 11 (have not tried deployed to Azure App Service yet)

Additional context

No response

dawkaka commented 2 months ago

@craigeddy Thank you for taking the time to open this issue and providing detailed information. I'm looking into the problem you're experiencing with the RequestBody and I'll notify you when a new version is released.

dawkaka commented 2 months ago

@craigeddy A new version has been released (1.0.7) that addresses the missing request body issue, thank you.

craigeddy commented 2 months ago

@dawkaka Unfortunately, I am still experiencing this issue, even with 1.0.7.

dawkaka commented 2 months ago

@craigeddy So sorry about that, there was an issue with the build, version 1.0.8 has been released which should address the problem, let me know if you run into any issues.

craigeddy commented 2 months ago

@dawkaka still not working.

For reference, my controller method is defined with

        [HttpPost]
        [SwaggerOperation("Create a new subject")]
        [Authorize(Policy = Policies.ManageSubjects)]
        // ReSharper disable once CognitiveComplexity
        public async Task<IActionResult> AddSubject([FromBody] NewSubject newSubject)
tonyalaribe commented 2 months ago

Hi Craig,

I'm unable to reproduce the issue any longer with the latest release. Did you give it a try?

craigeddy commented 2 months ago

@tonyalaribe @dawkaka It is working now (I swear I tried after putting 1.0.8 in place and it was not, but who knows).

I have noticed another issue, though:

Every Boolean property in both the request body and the response body shows as true regardless of the value in either the request or the response. Would you like me to open another issue with details?