Tips & tricks - finding invocation identifier in Azure Function

It's Friday so it's time for something easy and simple yet useful. You may wondering what is an iden

It's Friday so it's time for something easy and simple yet useful. You may wondering what is an identifier you often see when running a function:

Well, it's not a function instance identifier since it changes each time a function runs. In fact it's an invocation identifier and, while it's not so obvious initially, you can easy inject it into your function.

To do so you need a class, which is called ExecutionContext. Normally it's not available by default, but by injecting it you'll gain some information about a job function invocation like:

  • invocation identifier
  • function name
  • function directory

Now when you prepare a function similar to mine:

/
[FunctionName("TimerExample")]
public static void Run(
	[TimerTrigger("*/15 * * * * *")]TimerInfo timer,
	ExecutionContext context,
	TraceWriter log)
{
	log.Info($"Function called with `InvocationId` {context.InvocationId}");
	log.Info($"Function called with `FunctionName` {context.FunctionName}");
	log.Info($"Function called with `FunctionDirectory` {context.FunctionDirectory}");
}

You'll get following result:

Add comment