Search code examples
c#azureappinsights

How to get the Operation ID in a HTTPTrigger Azure Function 3.x. Image attached


We need OperationId value inside a HTTP Trigger Azure Function. How can we get it. Highlighted OperationID in the image

Fetching OperationId.png


Solution

  • You can use Activity.Current.RootId to get Operation Id inside a HTTP Trigger in portal.

    Code:

    #r "Newtonsoft.Json"
    
    using System.Net;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Extensions.Primitives;
    using Newtonsoft.Json;
    using System.Diagnostics;
    
    public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");
        log.LogInformation($"Activity Current RootId:{Activity.Current.RootId}");
    
        string operationId = Activity.Current.RootId;
        return new OkObjectResult("success");
    }
    

    enter image description here