r12
r12

Reputation: 1732

Azure Functions - How to change the Invocation ID within the function?

I have a series of Azure Functions, and I'd like to keep track of them by the InovcationId. In Application Insights, the InvocationId is called the operation_Id.

What I'm trying to do is set the operation_Id to be the same across several different Azure Functions.

I can read this property inside the Azure Function when I pass in ExecutionContext by following this answer, but I can't seem to alter it. Is there some way to change this value from inside the Azure Function?

public static class TestOperationId
{
    [FunctionName("TestOperationId")]
    public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, 
                                                        ILogger log,
                                                        ExecutionContext exeCtx
                                                        )
    {
        var input = await req.Content.ReadAsStringAsync();
        log.Info(input);
        exeCtx.InvocationId = Guid.Parse(input);
        return req.CreateResponse(HttpStatusCode.OK);
    }
}

Upvotes: 1

Views: 1557

Answers (1)

Connor McMahon
Connor McMahon

Reputation: 1358

The definition for the InvocationId field is defined as

Provides the invocation ID, uniquely identifying the current invocation

Azure Functions doesn't provide changing this, as it would mean that code could override the platform's methods to detect unique invocations of Functions, which would interfere with things like Billing and Metrics for the platform.

It sounds like what you really want is cross-function correlation. There is work being done with the Application Insights team to help support this, but in the meantime, you can see solutions that others are currently utilizing, like here.

Upvotes: 3

Related Questions