I’m looking to log the entire request payload and response body for APIM requests for auditing and debugging purposes. If we can store to Azure Blob Storage, it would be great!
As of now, we have this logic baked into application code(NodeJS App) with a middleware layer to capture request and response and write to a file(using winston logger), then later on, these files are copied to Azure Blob Storage from the VM using Azure CLI with a scheduled cron.
I’m looking to see if there is a way to decouple the same from application and handle this at the APIM level.
I see a few options:
- Use Azure Application Insights
- Use Azure Event Hubs logger
Option 1 – Azure Application Insights
Using application insights, I see this can be with the following settings, there is a limitation of 8192 bytes though.
With this my worry is that it might affect the performance of the API.
Option 2 – Azure Event Hubs logger
Using the below policy, and following this guide
<policies>
<inbound>
<base />
<set-header name="xrid" exists-action="override">
<value>@(context.RequestId.ToString())</value>
</set-header>
<log-to-eventhub logger-id="logger-id">
@{
return context.Request.Body.As<string>(preserveContent: true);
}
</log-to-eventhub>
</inbound>
<backend>
<base />
</backend>
<outbound>
<set-header name="xrid" exists-action="override">
<value>@(context.RequestId.ToString())</value>
</set-header>
<base />
<log-to-eventhub logger-id="logger-id">
@{
return context.Response.Body.As<string>(preserveContent: true);
}
</log-to-eventhub>
</outbound>
<on-error>
<base />
</on-error>
</policies>
Event Hubs has a limitation of 200 Kilobytes