Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Files

Latest commit

 Cannot retrieve latest commit at this time.

History

History
69 lines (57 loc) · 4.64 KB

tip301.md

File metadata and controls

69 lines (57 loc) · 4.64 KB
type title excerpt tags share date
post
Tip 301 - How to log request/response payload in Application Insights for APIs frontend by API Management
Learn how to log request/response payload in Application Insights for APIs frontend by API Management
Management and Governance
true
2021-01-08 09:00:00 -0800

::: tip

🔥 Download the FREE Azure Developer Guide eBook here.

💡 Learn more : How to integrate Azure API Management with Application Insights.

💡 Learn more : Performance implications and log sampling.

:::

This post was brought to you by Abishek Narayan.

How to log request/response payload in Application Insights for APIs frontend by API Management

Need for debugging/troubleshooting request/response payloads

When fronting your APIs with an Azure API Management Gateway there is often a need to debug/troubleshoot issues by analysing the request or response payload. In such a scenario we use Application Insights to log and inspect the request/response payloads. To avoid performance issues at API Management level, the configuration to inspect payloads is not enabled by default.

Prerequisites

If you want to follow along, you'll need the following:

Steps

  1. Go to the Azure portal and navigate to the API Management resource
  2. Under Settings >> select API
  3. Select the sample API from the right pane
  4. Click the 'Settings' tab
  5. Scroll down to Diagnostics Logs
  6. Under Application Insights tab, tick the checkbox Enable
  7. Select the AppInsights resource under Destination dropdown
  8. Default sampling 100%
  9. Verbosity Information
  10. Correlation protocol W3C
  11. Under Additional settings click Advanced Options
  12. Tick to enable Frontend Request and Frontend Response
  13. Use these settings for Frontend Request and Frontend Response
    • Under Headers to log add the value X-Forwarded-For
    • Under Number of payload bytes to log (up to 8192) specify a value upto 8192 bytes
  14. Hit save
  15. Navigate to the application insights resource and open the 'Live Metrics' feature under Investigate.
  16. Once the metrics have been initialized, open Postman and trigger the POST operation for the API with a sample payload. You should see a spike in the 'request rate' graph
  17. Wait for a few minutes, under Application Insights>>Monitoring>>Logs run the following query
requests 
| where url == "http://apimanagementurl/apiname/resource"
| where timestamp >= ago(1h)
| order by timestamp desc

  1. In the results grid, expand the result row, expand the customDimensions node and then expand the Request-Body node.

Thanks to Todd Foust for sharing the header value.