Azure函数-如何从函数内部获取调用ID? [英] Azure Functions - how to obtain invocation ID from within the function?

查看:108
本文介绍了Azure函数-如何从函数内部获取调用ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图返回Azure函数的调用ID,类似于WebJob在HTTP Location标头中发送WebJob运行ID.这样,我的函数的调用者就可以定期检查状态,以了解何时完成.

I am trying to return the invocation ID of an Azure function, similar to WebJob's sending the WebJob run ID back in the HTTP Location header. This is so the invoker of my function can check the status periodically to know when it completes.

我看到必须将此ID添加到响应对象中,并且我想我需要从函数中的某些上下文对象中检索它.这是因为当我访问 https:上的Function UI时://functionapp.scm.azurewebsites.net/azurejobs/#/functions/invocations/a-long-guid 我看到一个带有调用ID的名为_context的变量.但是,我似乎无法在函数中访问名为context,_context等的变量.

I see that I must add this id into the response object, and I surmise I need to retrieve it from some context object in the function. This is because when I visit the Functions UI at https://functionapp.scm.azurewebsites.net/azurejobs/#/functions/invocations/a-long-guid I see a variable named _context with the invocation id. However, I can't seem to access a variable named context, _context, etc in my function.

推荐答案

您可以通过在函数的方法中添加该类型的参数(例如Run(..., ExecutionContext context))来绑定到ExecutionContext.

You can bind to the ExecutionContext by adding a parameter of that type to your function's method (e.g. Run(..., ExecutionContext context)).

该类型公开了InvocationId属性,该属性将为您提供所需的信息.

That type exposes an InvocationId property that will give you the information you're looking for.

这篇关于Azure函数-如何从函数内部获取调用ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆