End-to-End Logging with Standard Logic Apps and Application Insights

Jonas Karlsson 6 Reputation points
2025-01-27T15:43:13.4733333+00:00

Having issues with end-to-end logging when using a Standard Logic App and Application Insights.

Application Insights logging has been activated, and the host file has been modified with the following settings in the Standard Logic App:

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle.Workflows",
    "version": "[1, 2.00)"
  },
  "extensions": {
    "workflow": {
      "Settings": {
        "Runtime.ApplicationInsightTelemetryVersion": "v2",
        "Runtime.ApplicationInsights.PreserveIncomingOperationId": "true"
      }
    }
  }
}

The logging is functioning as intended, allowing grouping of requests by operation_id when using a Logic App -> Service Bus -> Azure Function or HTTP requests between Logic App 1 and Logic App 2.

However, when using Logic App -> Service Bus -> Logic App, the operation_Id on the Logic App that triggers on new Service Bus messages appears to be replaced with a new one, making it impossible to follow the request chain in Application Insights.

Seeking guidance on how to resolve this issue.

Regards,
Jonas

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,542 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Loknathsatyasaivarma Mahali 2,740 Reputation points Microsoft External Staff Moderator
    2025-01-29T17:30:52.6633333+00:00

    Hello @Jonas Karlsson,

    Sure, I can provide you with an example of how to extract the OperationId from the AI context and set it as a custom property in the ingestion Logic App, as well as an example of how to retrieve the custom property in the consuming Logic App and set it as the OperationId in the AI telemetry.

    In the ingestion Logic App, you can use the "Parse JSON" action to parse the request body and extract the "operation_Id" property from the AI context. Here's an example of how you can do this:

    • Add a "Parse JSON" action to your ingestion Logic App.
    • Set the "Content" property to the body of the request.
    • Set the "Schema" property to the JSON schema of the request.
    • Add a "Set Variable" action to your ingestion Logic App.
    • Set the value of the variable to the "operation_Id" property of the parsed JSON. For example:
    {
      "name": "setOperationId",
      "type": "SetVariable",
      "inputs": {
        "name": "operationId",
        "value": "@{body('Parse_JSON')?['operation_Id']}"
      }
    }
    
    
    • Add a "Service Bus - Send Message" action to your ingestion Logic App.
    • Set the "User Properties" property to a JSON object that includes the operation_id. For example:
    {
      "name": "sendToServiceBus",
      "type": "ServiceBus",
      "inputs": {
        "body": "@{triggerBody()}",
        "userProperties": {
          "operation_id": "@{variables('operationId')}"
        }
      }
    }
    

    In the consuming Logic App, you can retrieve the custom property from the Service Bus message and set it as the OperationId in the AI telemetry. Here's an example of how you can do this:

    • Add a "Parse JSON" action to your consuming Logic App.
    • Set the "Content" property to the body of the Service Bus message.
    • Set the "Schema" property to the JSON schema of the message.
    • Add a "Set Variable" action to your consuming Logic App.
    • Set the value of the variable to the "operation_id" property of the parsed JSON. For example:

    {

    "name": "setOperationId",

    "type": "SetVariable",

    I hope the above provided information will helps you in understating better and solve your issue, if you have a further concern, please feel free to reach out.


  2. RithwikBojja 3,055 Reputation points Microsoft External Staff Moderator
    2025-02-10T03:37:07.2333333+00:00

    Hi @Jonas Karlsson,

    Thank you for reaching out to MS Q&A.

    To make sure, Logic App1 , Service Bus , Logic App2 are inter-related, I use below design:

    Here, I am using, http trigger's, correlation id and sending it to service bus message, later in Logic app 2, it gets triggered and correlation id is not changed:

    Logic App 1:

    triggerOutputs()?['headers']['x-ms-correlation-request-id']
    

    Logic App 2:

    enter image description here

    triggerBody()?['correlationId']
    

    Output:

    Logic App 1:

    enter image description here

    enter image description here

    Logic App 2:

    enter image description here

    As, you can clearly see, the id is not changed in second one too.

    Alternatively, you can also use below design:

    Here, I am setting header http call and making it use our id :

    While calling 2nd Logic app or Htpp Azure Function:

    Call : Post

    Header :

    {"x-ms-correlation-request-id": "xx"}
    

    xx is your id.

    Output:

    enter image description here

    If you are calling 2nd from 1st Logic app, in place of xx use the correlation id. By this way i set relations between logic apps.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.


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.