microsoft / ApplicationInsights-dotnet-server

Microsoft Application Insights for .NET Web Applications
https://azure.microsoft.com/services/application-insights/
133 stars 67 forks source link

AppInsight in Azure Fuctions app does not take Request-Id from client request's header #1163

Closed lap1817 closed 5 years ago

lap1817 commented 5 years ago

We created a Azure function app and enabled AppInsight with default setup. We have a client SDK that will send request to this function app, which also uses AppInsight. In order to correlate the client side events with the server side events, we set 'Request-Id' header in the client request. However, on server side, AppInsight seems to ignore it and generates a new operationId on each request event.

To simplify the repo, we create a brand new function App with its default sample codes.

#r "Newtonsoft.Json"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;

public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");

    string name = req.Query["name"];

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    name = name ?? data?.name;

    return name != null
        ? (ActionResult)new OkObjectResult($"Hello, {name}")
        : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}

Then in the Test panel, we run a test with the following headers image

Then we check the request event, and the operationId is a random one, instead of the root id from the test reuqest.

Repro Steps

  1. create a new Azure Func app and enable AppInsight
  2. Add a new function with Http trigger, and use ,
  3. In the Test panel of the function, run a test request with the headers Request-Id:|9e74f0e5-efc4-41b5-86d1-3524a43bd891.bcec871c_1. x-ms-request-id:|9e74f0e5-efc4-41b5-86d1-3524a43bd891.bcec871c_1.

Actual Behavior

When I checked the requests and traces events, they don't carry the root operaiton Id which is '9e74f0e5-efc4-41b5-86d1-3524a43bd891'. Instead, a random operation Id is used.

Expected Behavior

The requests/traces events should have operation_id='9e74f0e5-efc4-41b5-86d1-3524a43bd891'

Version Info

SDK Version : 2.7.2 .NET Version : default install by azure Function app
How Application was onboarded with SDK(VisualStudio/StatusMonitor/Azure Extension) : Azure Function App OS : Hosting Info (IIS/Azure WebApps/ etc) : Azure Function App

lmolkova commented 5 years ago

This is not supported yet and is tracked here: https://github.com/Azure/azure-functions-host/issues/2447. Will be rolled out with the next functions host deployment.