Skip to content

Alternative solution for deprecated TelemetryConfiguration.Active on Azure Functions #2144

Closed

Description

Hi,

I am using TelemetryClient for adding correlation between 2 azure functions communicating with each other using Azure Event Grid. Unlike the Service Bus, the end-to-end transactions don't appear on the logs out of the box with the Event Grid, so I am using the telemetry client to create custom dependency and requests.

However, I am having a problem here.

  • When I am injecting the TelemetryConfiguration into my function, it is completely empty.
  • When I am injecting the IOptions<TelemetryConfiguration> to my function, the TelemetryConfiguration is there but missing the actual config, even the instrumentation key.
  • When I am injecting my customized TelemetryConfiguration as below, it works but the end-to-end transaction logs get weird and loses significant correlations in the logs:
return services
    .AddSingleton(sp =>
    {
        var telemetryConfiguration = TelemetryConfiguration.CreateDefault();
        telemetryConfiguration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
        var config = sp.GetService<IConfiguration>();
        var instrumentationKey = config.GetValue<string?>("APPINSIGHTS_INSTRUMENTATIONKEY");
        if (instrumentationKey != null)
            telemetryConfiguration.InstrumentationKey = instrumentationKey;
        return telemetryConfiguration;
    });

However, when using the deprecated TelemetryConfiguration.Active it works perfectly. I noticed the Active config has more initializers in addition to the OperationCorrelationTelemetryInitializer, namely speaking:

  • Microsoft.Azure.WebJobs.Logging.ApplicationInsights.WebJobsRoleEnvironmentTelemetryInitializer
  • Microsoft.Azure.WebJobs.Logging.ApplicationInsights.WebJobsTelemetryInitializer

Not sure if that is the reason, but I couldn't find any good documentation or solution for this! Is there an alternative solution to make this work like the TelemetryConfiguration.Active?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions