如果执行期间出现任何错误,我希望将当前Azure Function执行的上下文ID包含在响应内容中。我的目的是在故障排除过程中帮助我快速找到其ID的相应执行痕迹。这是代码的样子:
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...");
};
}
}
是否可以获取当前Azure Function执行的上下文ID?如果是,我怎么能得到它?
答案 0 :(得分:1)
这应该给你,
public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log, ExecutionContext context)
{
return req.CreateResponse(System.Net.HttpStatusCode.OK, context.InvocationId);
}