Add Custom Properties for RequestTelemetry of the Azure Function (v3) binding to BlobTrigger(将Azure函数(V3)绑定的请求遥测的自定义属性添加到BlobTrigger)
问题描述
我要向为用C#编写的Azure函数(V3)生成的RequestTelemeter添加自定义属性。
多亏了this StackOverflow post,我设法通过HttpTrigger绑定为函数实现了这一点。
var requestTelemetry = req.HttpContext?.Features.Get<RequestTelemetry>();
requestTelemetry.Properties.Add("MyProp", "Some value");
如何在正在使用的函数中获取当前 B触发器绑定?
在具有HttpTrigger绑定的函数中,该函数注入了HttpRequest参数
public async Task<IActionResult> Upload(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "upload/{name}")] HttpRequest req,
            string name,
            ILogger log,
            ExecutionContext context)
        {  
  ...
}
这样我们就可以使用HttpRequest获取当前的请求遥测。但是,使用BlobTrigger:
    [FunctionName("Create-Thumbnail")]
            public async Task CreateThumbnail([BlobTrigger("input/{name}",  Source = BlobTriggerSource.EventGrid, Connection = "AzureWebJobsStorage")] Stream image,
                IDictionary<string,string> metadata,
                string name,
                ExecutionContext context)
            { 
  ...
}
我已尝试注入HttpRequest,并使用与HttpTrigger函数相同的方式。但没有奏效。
经过几个小时的广泛研究,我找不到任何与此问题相关的文档或帖子。
有人能为此提供一些提示吗?
推荐答案
AFAIK使用Blob触发器时没有http请求。您仍然可以通过如下设置属性来向执行期间生成的遥测添加自定义属性:
// The current telemetry item gets a property. 
// Useful if the function is not triggered by an http request
Activity.Current.AddTag("setUsingTag", "setUsingTag");
// Subsequent telemetry gets this property attached
Activity.Current.AddBaggage("setUsingActivityBaggage", "setUsingActivityBaggage"); 
使用行李而不是标签时,自定义属性将添加到执行期间生成的所有遥测中,如依赖项调用等。
另请参阅this github thread。它还mentions在较高版本的AI中可能引入了一个错误,可能会迫使您降级AI以使其正常工作。多亏了这一点GitHub issue,在将System.Diagnotics.Diagnostis.DiagnoticSource降级到版本4.6之后,终于可以正常工作了
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0" />
这篇关于将Azure函数(V3)绑定的请求遥测的自定义属性添加到BlobTrigger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将Azure函数(V3)绑定的请求遥测的自定义属性添加到BlobTrigger
 
				
         
 
            
        - C# 中多线程网络服务器的模式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
 
						 
						 
						 
						 
						 
				 
				 
				 
				