-
Notifications
You must be signed in to change notification settings - Fork 800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3.0.2] .AddApplicationInsightsPublisher without instrumentation key dies #372
Comments
Version 3.0.1 and previous versions were using TeletryConfiguration.Active that is a static that has been deprecated. Here is the PR with some instructions on how to use the new implementation: You need to register Applications Insights in the service collection by using: public void ConfigureServices(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry();
} You can also use the AspNetCore ApplicationInsights package and use: Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>()
.UseApplicationInsights();
}); But this option has already been deprecated in favour of the previous one. Or you can just configure IOptions as you can see in the following unit test link: The HealthCheck does not have a breaking change per se because you can provide the telemetry key on the parameter but it won't relay on the static field anymore, it will relay in dependency injection and the ApplicationInsights services being registered. That's why the constructor complains of AppInsights not being configured and the telemetrykey not being provided as well. So that means you can continue using .AddApplicationInsightsPublisher() without parameters but you need to register the Microsoft service as they guide. |
In a basic hello world app, the default asp.net core empty web template, add in
And you'll explode with:
|
Please, follow the Application Insights configuration guide here: https://docs.microsoft.com/es-es/azure/azure-monitor/app/asp-net-core If you use the parameterless version of AddApplicationInsightsTelemetry you should provide the configuration using an IConfiguration Provider as json file using appsettings.json: {
"ApplicationInsights": {
"InstrumentationKey": "yourkey"
}
} You can also use other overload and configure it directly: services.AddApplicationInsightsTelemetry(config => {
config.InstrumentationKey = "yourkey";
}); |
This would be an easy fix for you though: Line 40 in 6e7be01
All you need to do is call TelemetryConfiguration.CreateDefault(), which is the newer way of getting a TelemetryConfiguration if none was provided (after static was deprecated) |
Hello @joshlang, you are right but, the thing is I do not like the idea of internally creating the necessary components for a healthcheck to work , but just request them to the service provider. Doing this drove us to face this Deprecated static method. And TelemetryClient.CreateDefault() could be the next. To be honest, the Asp.Net Core team has removed all static methods that created so many problems in the past and I do not really know why App Insights use this static classes yet. |
@unaizorrilla what do you think about this? |
I'm actually confused as to why you don't just inject |
Remember that App Insights doesn't require an IKey to be configured to work for local development, and that is actually a useful feature. IMHO, components depending on App Insights should follow that principle. |
A breaking change in 3.0.2 (does not occur in 3.0.1).
In our local environment, we do not have an instrumentation key defined anywhere. We call .AddApplicationInsightsPublisher() as part of our setup. Since upgrading to 3.0.2, this now causes a crash complaining that a key was not defined in the constructor or options.
The text was updated successfully, but these errors were encountered: