Reputation: 1937
I would like to get the context id of current Azure Function execution to be included in the content of the response if there's any error during execution. My intention is to help me during troubleshooting by quickly find the traces of respective execution with its id. Here is what the code looks like:
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
try
{
// Some code...
}
catch (Exception ex)
{
return new HttpResponseMessage(HttpStatusCode.InternalServerError)
{
Content = new StringContent("Insert Azure Function Context Id here...");
};
}
}
And here is how the context id looks like in Azure Function monitor:
Is it possible to get the context id of the current Azure Function execution? If yes, how can I get it?
Upvotes: 0
Views: 2224
Reputation: 222720
This should give you,
public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log, ExecutionContext context)
{
return req.CreateResponse(System.Net.HttpStatusCode.OK, context.InvocationId);
}
Upvotes: 4