简体   繁体   English

如何获取当前Azure函数执行的上下文ID?

[英]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.

相关问题 如何使用ADAL / OpenId在azure AAD中获取当前用户? - How can I get the current user in azure AAD, with ADAL/OpenId? 如何在执行C#Azure功能期间避免SqlClient超时错误? - How can I avoid a SqlClient timeout error during execution of a C# Azure Function? 如何使用 Azure 身份验证在 Azure Function 中获取当前用户身份? - How to get current user identity in Azure Function with Azure Authentication? 如何在一组线程之间共享执行上下文? - How can I shared a execution context between a group of threads? 如何从 Azure 函数中获取多个 blob? - How can I get multiple blobs out of an Azure Function? 如何在当前上下文中访问WCF服务实例? - How do I get access to the WCF service instance in the current context? 我该如何解决:名称“productQuantity”在当前上下文中不存在 - How can I fix: The name 'productQuantity' does not exit in the current context 当前上下文中不存在“会话”。 我该如何使用它? - 'Session' does not exist in the current context. How can I use it? 我可以回到线程执行上下文吗? - Can I go back to the thread execution context? 如何在WinForm C#中获取当前正在运行的应用程序名称和ID? - How can i get Current running Application name and ID in WinForm C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM