[英]How can I get the context id of current Azure Function execution?
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. 如果执行期间发生任何错误,我想将当前Azure函数执行的上下文ID包含在响应的内容中。 My intention is to help me during troubleshooting by quickly find the traces of respective execution with its id. 我的目的是通过快速查找带有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: 这是Azure函数监视器中上下文ID的外观:
Is it possible to get the context id of the current Azure Function execution? 是否可以获取当前Azure函数执行的上下文ID? If yes, how can I get it? 如果是,我该怎么办?
This should give you, 这应该给你,
public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log, ExecutionContext context)
{
return req.CreateResponse(System.Net.HttpStatusCode.OK, context.InvocationId);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.