How to correlate logs from LogManagement/ApiManagementGatewayLogs with Application Insights/requests or tracec

Marta Dubas 40 Reputation points
2024-12-12T15:24:32.96+00:00

Hi

I will try to explain my case as well as I can but I understand it might be confusing.

I would like to write a query which shows information from LogManagement -> ApiManagementGatewayLogs table and Application Insights -> requests and traces.

The flow in my application is:

  1. incoming request -> API Management (APIm)
  2. APIm-> APIm policy <send-request /> to Azure function app (FA)
  3. FA -> return respons to APIm
  4. APIm -> backend service
  • APIm sends metrics to both Log Analytics (ApiManagementGatewayLogs table) and to Application Insights instance, let's call it APIm-appi
  • AF logs to another Application Insights instance, let's call it FA-appi

I allow x-correlation-id header on all the incoming requests to APIm, it is something API clients send in.

There is a column in ApiManagementGatewayLogs called CorrelationId. As far as I understood it cannnot be overriten and equals RequestId (not visible in the table ApiManagementGatewayLogs ).

  • x-correlation-id defined by the API client is not shown in ApiManagementGatewayLogs.
  • CorrelationId is logged in APIm-appi as requests/CustomProperties.RequestId.
  • x-correlation-id is logged in APIm-appi and AF-appi as requests/Request-x-correlation-id.

I would like to be able to write one Kusto query where I can join on correlationId, soemthing like:

ApiManagementGatewayLogs.CorrelationId = ApplicationInsightsApim.CustomProperties[RequestId]

and then on

ApplicationInsightsApim.Request-x-correlation-id = ApplicationInsightsFunctionApp.Request-x-correlation-id

(without going into the details of the query itself)

I am not able to use both Log Analytics and Application Insights as sources in the same scope (error in LogAnalytics GUI in Azure Portal).

AppTraces and AppRequests tables in log analytics do not contain the same CustomProperties[RequestId] which I can find in Application Insights/requests.

Is it possible to use both this tables as data sources in the same query?

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

1 answer

Sort by: Most helpful
  1. Pranay Reddy Madireddy 1,310 Reputation points Microsoft Vendor
    2024-12-13T21:31:47.94+00:00

    Hi Marta Dubas

    Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.

    First, collect the relevant data from the ApiManagementGatewayLogs, focusing on the CorrelationId.

    let apimLogs = ApiManagementGatewayLogs

    | project TimeGenerated, CorrelationId, ApiName, RequestUri;

    Next, collect data from Application Insights requests, where the CustomProperties.RequestId is located.

    let apimInsightsRequests =

    requests

    | extend RequestId = tostring(customDimensions.RequestId), RequestCorrelationId = tostring(customDimensions["Request-x-correlation-id"])
    
    | project TimeGenerated, RequestId, RequestCorrelationId;
    

    For reference, please review this documentation :-

    https://yourazurecoach.com/2021/01/22/optimizing-api-traceability-in-azure-api-management/
    https://learn.microsoft.com/en-us/azure/azure-monitor/reference/queries/apimanagementgatewaylogs

    you have any further queries, do let us know.


    If the answer is helpful, please click "Upvote it".


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.