2

The execution context that is injected to a function (https://github.com/Azure/azure-functions-host/wiki/Retrieving-information-about-the-currently-running-function), is it possible to get it in some other helper libraries.

I want to get the InvocationId of the current function in some other libraries. For e.g. let's say I have written a logger and I need to add the Invocation ID for every log. One trivial way to achieve this would be to pass the Invocation ID from the function to all the helpers, but it may not be possible especially if one is working with legacy code.

In App services we could solve this problem by getting access to the HttpContext via the IHttpContextAccessor.

Is there any alternative to this in Azure function?

Pratik Bhattacharya
  • 3,596
  • 2
  • 32
  • 60
  • Can we see the logger you have written? – Chris Jun 13 '19 at 14:56
  • Also could use FunctionFilterContext.FunctionInstanceId to get the InstanceId, they are the same value. Check if this what you want.https://github.com/Azure/azure-webjobs-sdk/blob/dev/src/Microsoft.Azure.WebJobs.Host/Filters/FunctionExceptionContext.cs#L19 – George Chen Jun 14 '19 at 02:19
  • @GeorgeChen, the example that you gave me will generate the ID only in the Function App. I want this context to be shared across other BL libraries as well – Pratik Bhattacharya Jun 17 '19 at 08:27

0 Answers0