I'm not able to see the HTTP ResponseBody after pubishing on Azure to the Microsoft Cloud.

BOIA Patricia-Daiana 61 Reputation points
2022-07-12T13:28:43.77+00:00

I was able to retrieve user information (email) using Application Insights Telemetry and by adding a custom middleware:

requestTelemetry.Context.User.AuthenticatedUserId = context.User.Identity.Name;

Everything was working perfectly when the application was running locally. After publishing it I cannot see anything anymore (not even the ResponseBody inside Properties).

What I did wrong? How can I make it work in production too?

Thanks.

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,798 questions
{count} votes

1 answer

Sort by: Most helpful
  1. AnuragSingh-MSFT 19,691 Reputation points
    2022-07-25T10:34:55.8+00:00

    @BOIA Patricia-Daiana , Thank you for sharing the details regarding this question.

    Based on the shared link below, the steps enables the request/response body to log content only in Development Environment.
    https://www.azureblue.io/how-to-log-http-request-body-with-asp-net-core-application-insights/

    Please refer to the section containing the following

    To ensure logging does not get enabled in production environments only enable the custom middleware components inside the condition that checks if we are running in a development environment.

    The code snippet uses if (env.IsDevelopment()) condition to enable logging inside the Configure(IApplicationBuilder app, IWebHostEnvironment env) method. Since your local environment runs as "Development Environment", the logging is available in AppInsights. If you want it to be configured for production as well, you will have to remove the if condition so that it gets enabled for all environments.

    "Note" - I am reiterating the word of caution from Author of this post:
    Writing the content of an HTTP body to Application Insight might reveal sensitive user information that otherwise would be hidden and protected in transfer via TLS. So use this with care and only during debugging or developing!

    Hope this helps. Please let me know if you have any questions.