Skip to content
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

AspNetCore.HealthChecks.Publisher.ApplicationInsights - 3.0.2 doesn't handle missing telemetry key #380

Closed
ianjirka opened this issue Dec 21, 2019 · 6 comments

Comments

@ianjirka
Copy link

In my startup code, I don't provide a telemetry key to AI if the environment is Development. So far this has worked fine.

With AspNetCore.HealthChecks.Publisher.ApplicationInsights v 3.0.2, I get the below exception. 3.0.1 does not have this behavior.

Can you confirm if this is a bug or if I need to change how I do startup to not configure AI health checks in this case?

Thanks much.


Error Message:
System.AggregateException : One or more errors occurred. (Value cannot be null. (Parameter 'No instrumentation key was provided in options or constructor'))
---- System.ArgumentNullException : Value cannot be null. (Parameter 'No instrumentation key was provided in options or constructor')
Stack Trace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait(TimeSpan timeout)
at test.WebServerUnitTests.ConfigureWebSite() in C:\rep\uhe.infra.patterns\test\UnitTests\WebsiteUnitTests.cs:line 73
----- Inner Stack Trace -----
at HealthChecks.Publisher.ApplicationInsights.ApplicationInsightsPublisher..ctor(IOptions`1 telemetryConfiguration, String instrumentationKey, Boolean saveDetailedReport, Boolean excludeHealthyReports)

@sungam3r
Copy link
Collaborator

Relates to #372 and #373

@CarlosLanderas
Copy link
Contributor

CarlosLanderas commented Dec 22, 2019

@ianjirka, Microsoft now recommends relaying on Dependency injection to retrieve TelemetryConfiguration after TelemetryConfiguration.Active has been deprecated:

microsoft/ApplicationInsights-dotnet#1152

By using:

services.AddApplicationInsightsTelemetry();

This will automatically read your configuration from IConfiguration providers like appsettings or you can use the overload with a setup method to configure the Telemetry configuration.

Docs:

https://docs.microsoft.com/es-es/azure/azure-monitor/app/asp-net-core

@ianjirka
Copy link
Author

ianjirka commented Dec 22, 2019

@CarlosLanderas - I agree, and this is what I currently do. I just do not set the telemetry key in the Development environment to avoid the number of things that need to be set up during development. In this issue I'm noting that the behavior changed in 3.0.2 such that this setup no longer works. From reading the linked issues I infer that was not intended but I didn't receive confirmation from the engineering team yet.

@joshlang
Copy link

#373 will fix it if it's accepted

@CarlosLanderas
Copy link
Contributor

CarlosLanderas commented Dec 22, 2019

@joshlang, I am going to submit a new PR that will not have the throw exception, but we are going to relay on DI and not going to use TelemetryClient.CreateDefault static, as Microsoft good practice is usingOptions<TelemetryConfiguration>
They are right the Healthcheck should not throw when no key is not configured in development scenarios

If you want to edit yours is ok for me.

@joshlang
Copy link

Nope, it's okay. I'm not particularly attached to my solution, and I'm happy to see yours get preference - the important thing is that it's fixed. You're also more familiar with the preferences & styles of this repo!

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants