question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom ITelemetryInitializer in azure function .Net Core 3.1 does not work

See original GitHub issue

Custom ITelemetryInitializer in azure function .Net Core 3.1 does not work.

I’ve implemented a custom ITelemetryInitializer and injected using Dependency injection as Singleton but Initialize method of ITelemetryInitializer of custom class is not hit.

Repro steps

  1. Created a new .Net core 3.1 Azure function with Http binding.
  2. Installed Microsoft.Azure.Functions.Extensions 1.0.0 package
  3. Installed Microsoft.ApplicatoinInsights 2.13.1 package

Created a new Custom ITelemetryInitializer class

public class MyCustomTelemetryInitializer : ITelemetryInitializer
{
    public MyCustomTelemetryInitializer()
    {
    }

    public void Initialize(ITelemetry telemetry)
    {
        if (telemetry == null)
        {
            return;
        }

        telemetry.Context.GlobalProperties["SomePropertyName"] = "SomePropertyValue";
    }
}

Added Startup implemenation


[assembly: FunctionsStartup(typeof(SomeNamespace.Startup))]

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

        }
    }
}

The configure method is hit (If I hit the breakpoint) but breakpoint at MyCustomTelemetryInitializer is never hit and due to that the custom telemetry properties are not injected.

Expected behavior

The custom properties injected by MyCustomTelemetryInitializer should be logged.

Actual behavior

The custom properties injected by MyCustomTelemetryInitializer are NOT being logged.

Known workarounds

NA

Related information

  1. .Net Core : 3.1
  2. Microsoft.NET.Sdk.Functions - 3.0.1
  3. Microsoft.Azure.Functions.Extensions 1.0.0
  4. Microsoft.ApplicatoinInsights 2.13.1

Tried downgrading the Microsoft.ApplicatoinInsights to 2.11.0 but still did not work.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
dongupcommented, Sep 30, 2022

I have the same issue, and I am using Microsoft.NET.Sdk.Functions 4.0.1. Please help me, thank you.

0reactions
KamranMammadovcommented, Dec 28, 2022

Any updates? .Net 6.0 isolated

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom ITelemetryInitializer in azure function .Net Core 3.1 ...
Net Core 3.1 does not work. I've implemented a custom ITelemetryInitializer and injected using Dependency injection as Singleton but Initialize ...
Read more >
ITelemetryInitializer not being called in Azure function V4
I have an V4 Azure function running .net6 as a isolated process. I want to set the Cloud role name in Application insights...
Read more >
Application Insights for ASP.NET Core applications
Open your project in Visual Studio. Go to Project > Add Application Insights Telemetry. Select Azure Application Insights > Next. Choose your ...
Read more >
How to use the WebJobs SDK - Azure App Service
Azure Functions lets you customize host behavior through settings in the host.json file. Those settings are strings, not code, and use of ...
Read more >
Filtering and preprocessing in the Application Insights SDK
Write telemetry processors and telemetry initializers for the SDK to filter or add properties to the data before the telemetry is sent to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found