<small id='uESIc'></small><noframes id='uESIc'>

  1. <legend id='uESIc'><style id='uESIc'><dir id='uESIc'><q id='uESIc'></q></dir></style></legend><tfoot id='uESIc'></tfoot>
      <bdo id='uESIc'></bdo><ul id='uESIc'></ul>

      <i id='uESIc'><tr id='uESIc'><dt id='uESIc'><q id='uESIc'><span id='uESIc'><b id='uESIc'><form id='uESIc'><ins id='uESIc'></ins><ul id='uESIc'></ul><sub id='uESIc'></sub></form><legend id='uESIc'></legend><bdo id='uESIc'><pre id='uESIc'><center id='uESIc'></center></pre></bdo></b><th id='uESIc'></th></span></q></dt></tr></i><div id='uESIc'><tfoot id='uESIc'></tfoot><dl id='uESIc'><fieldset id='uESIc'></fieldset></dl></div>

      使用 Azure Function v2 自定义 Application Insight TelemetryInitia

      Custom Application Insight TelemetryInitializer using Azure Function v2(使用 Azure Function v2 自定义 Application Insight TelemetryInitializer)
      <i id='qVObZ'><tr id='qVObZ'><dt id='qVObZ'><q id='qVObZ'><span id='qVObZ'><b id='qVObZ'><form id='qVObZ'><ins id='qVObZ'></ins><ul id='qVObZ'></ul><sub id='qVObZ'></sub></form><legend id='qVObZ'></legend><bdo id='qVObZ'><pre id='qVObZ'><center id='qVObZ'></center></pre></bdo></b><th id='qVObZ'></th></span></q></dt></tr></i><div id='qVObZ'><tfoot id='qVObZ'></tfoot><dl id='qVObZ'><fieldset id='qVObZ'></fieldset></dl></div>

      <legend id='qVObZ'><style id='qVObZ'><dir id='qVObZ'><q id='qVObZ'></q></dir></style></legend>

        <tbody id='qVObZ'></tbody>

          <bdo id='qVObZ'></bdo><ul id='qVObZ'></ul>
        • <small id='qVObZ'></small><noframes id='qVObZ'>

            <tfoot id='qVObZ'></tfoot>
                本文介绍了使用 Azure Function v2 自定义 Application Insight TelemetryInitializer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在 Azure 函数中,我们使用 .NET HttpClient 类、Azure Servicebus SDK 和 Azure Storage SDK 发出大量请求 - 所有内容都通过 Application Insight 日志记录中的构建精美地记录下来,显示依赖关系和所有内容!

                In a Azure Function we make a number of request using the .NET HttpClient class, the Azure Servicebus SDK and the Azure Storage SDK - everything is beautifully logged via the build in Application Insight logging, showing dependencies and all!

                现在我们想添加一个 ITelemetryInitializer 的实现,为上面提到的 SDK 编写的 EventTelemetry 添加一些维度.

                Now we however like to add an implementation of ITelemetryInitializer to add a few dimensions to the EventTelemetry being written by the SDKs mentioned above.

                我们首先创建一个实现 ITelemetryInitializer 接口的类.

                We start by creating a class implementing the ITelemetryInitializer interface.

                public class ReferrerTelemetryInitializer : ITelemetryInitializer
                {
                    public void Initialize(ITelemetry telemetry)
                    {
                        if (telemetry is EventTelemetry)
                        {
                            // Add some code
                        }
                    }
                }
                

                然后我创建一个实现 IWebJobsStartup 接口的类,以 DI 注入我的初始化程序.

                I then create a class implementing the IWebJobsStartup interface to DI inject my initializer.

                [assembly: WebJobsStartup(typeof(Startup))]
                
                namespace LoggingTest
                {
                    public class Startup : IWebJobsStartup
                    {
                        public void Configure(IWebJobsBuilder builder)
                        {
                            builder.Services.AddSingleton<ITelemetryInitializer, ReferrerTelemetryInitializer>();
                        }
                    }
                }
                

                注意:我只在 .NET Core 2.0(而不是 2.1)中触发了 Startup 类 - 这似乎是一个已知的开放issue 虽然?

                Note: I only got the Startup class to fire in .NET Core 2.0 (and not in 2.1) - this seems to be an open an known issue though?

                但是,初始化程序类中的 Initialize 方法却永远不会触发(在核心 2.0 中,在我看到 Startup 类已注册 DI ReferrerTelemetryInitializer 实现之后)?

                BUT, the Initialize method in the initializer class does however never fires (in core 2.0, after I've seen that the Startup class has registered the DI ReferrerTelemetryInitializer implementation)?

                我们缺少什么?

                推荐答案

                Azure Function v3

                对于那些在 2021 年在 Azure Function v3 中进行这项工作的人来说,这现在可以工作了.

                For those that work on this in 2021 in Azure Function v3 this does work now.

                TelemetryClient 由 Azure Function 主机/运行时配置.它将通过依赖注入从服务集合中获取注册的 ITelemetryInitializer.

                The TelemetryClient is configured by the Azure Function host/runtime. It will pick up the registered ITelemetryInitializer via dependency injection from the service collection.

                项目文件

                <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
                <PackageReference Include="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" Version="3.0.27" />
                <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
                

                启动

                public class Startup : FunctionsStartup
                {
                    public override void Configure(IFunctionsHostBuilder builder)
                    {
                        builder.Services.AddSingleton<ITelemetryInitializer, TheCustomTelemetryInitializer>();            
                    }
                }
                

                对本地发展很重要!

                然后您需要在 local.settings.json 中为您的 APPINSIGHTS_INSTRUMENTATIONKEY 添加一些值.这是它与常规控制台应用程序不同的地方,即使检测密钥为空,它也可以在本地工作.在功能应用程序中,您显然需要在那里添加一些价值.它可以是任何东西,我已经做到了,而且效果很好:

                Then you need to add some value to your APPINSIGHTS_INSTRUMENTATIONKEY in local.settings.json. This is where it differs from regular console apps, where even if the instrumentation key is empty it will work locally. In function apps apparently you need to add some value there. It can be anything, I've done this and it worked fine:

                来源

                "APPINSIGHTS_INSTRUMENTATIONKEY": "you-need-to-have-anything-at-all-here-so-it-will-work-locally"
                

                这篇关于使用 Azure Function v2 自定义 Application Insight TelemetryInitializer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Adding and removing users from Active Directory groups in .NET(在 .NET 中的 Active Directory 组中添加和删除用户)
                set equality in linq(在 linq 中设置相等)
                HashSet conversion to List(HashSet 转换为 List)
                How to set timeout for webBrowser navigate event(如何为 webBrowser 导航事件设置超时)
                Test whether two IEnumerablelt;Tgt; have the same values with the same frequencies(测试两个IEnumerablelt;Tgt;具有相同频率的相同值)
                How do you determine if two HashSets are equal (by value, not by reference)?(您如何确定两个 HashSet 是否相等(按值,而不是按引用)?)

                • <small id='UH6zl'></small><noframes id='UH6zl'>

                  <i id='UH6zl'><tr id='UH6zl'><dt id='UH6zl'><q id='UH6zl'><span id='UH6zl'><b id='UH6zl'><form id='UH6zl'><ins id='UH6zl'></ins><ul id='UH6zl'></ul><sub id='UH6zl'></sub></form><legend id='UH6zl'></legend><bdo id='UH6zl'><pre id='UH6zl'><center id='UH6zl'></center></pre></bdo></b><th id='UH6zl'></th></span></q></dt></tr></i><div id='UH6zl'><tfoot id='UH6zl'></tfoot><dl id='UH6zl'><fieldset id='UH6zl'></fieldset></dl></div>
                    <tbody id='UH6zl'></tbody>

                      <tfoot id='UH6zl'></tfoot>

                      • <bdo id='UH6zl'></bdo><ul id='UH6zl'></ul>
                          <legend id='UH6zl'><style id='UH6zl'><dir id='UH6zl'><q id='UH6zl'></q></dir></style></legend>