Saranyan
Saranyan

Reputation: 13

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

Upvotes: 0

Views: 2162

Answers (2)

Steve Johnson
Steve Johnson

Reputation: 8660

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

Upvotes: 3

Satya V
Satya V

Reputation: 4164

You can add the execution context to your function.

Something like this :

[FunctionName("HttpTriggerCSharp")]
public static async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
    HttpRequest req, ILogger log,ExecutionContext context)

You can access the Context.InvocationId which will be your requirement (operationid).

Upvotes: 0

Related Questions