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

ApplicationInsightsPublisher: TelemetryClient from DI #186

Closed
espenrl opened this issue May 20, 2019 · 2 comments
Closed

ApplicationInsightsPublisher: TelemetryClient from DI #186

espenrl opened this issue May 20, 2019 · 2 comments

Comments

@espenrl
Copy link

espenrl commented May 20, 2019

Hi,

The ApplicationInsightsPublisher instantiates its own TelemetryClient. According to Microsoft documentation the best practice is to get it using the one in the DI container. And then it could me made a readonly field instead of static field with a lock.

https://github.com/Microsoft/ApplicationInsights-aspnetcore/wiki/Custom-Configuration

private static TelemetryClient _client;
private static readonly object sync_root = new object();

private TelemetryClient GetOrCreateTelemetryClient()
{
if (_client == null)
{
lock (sync_root)
{
if (_client == null)
{
//override instrumentation key or use default instrumentation
//key active on the project.
var configuration = string.IsNullOrWhiteSpace(_instrumentationKey)
? TelemetryConfiguration.Active
: new TelemetryConfiguration(_instrumentationKey);
_client = new TelemetryClient(configuration);
}
}
}
return _client;
}

@unaizorrilla
Copy link
Collaborator

Can you send a PR with this change?

@unaizorrilla unaizorrilla added the help wanted Extra attention is needed label May 28, 2019
CarlosLanderas added a commit to CarlosLanderas/AspNetCore.Diagnostics.HealthChecks that referenced this issue Jun 26, 2019
CarlosLanderas added a commit to CarlosLanderas/AspNetCore.Diagnostics.HealthChecks that referenced this issue Jun 26, 2019
CarlosLanderas added a commit to CarlosLanderas/AspNetCore.Diagnostics.HealthChecks that referenced this issue Jun 26, 2019
@CarlosLanderas
Copy link
Contributor

Hello @espenrl, I was preparing a PR for this but after talking with @unaizorrilla this behaviour is on purpose.

Users might want to use default telemetry client for application monitoring and a different client for health checks monitoring. If you don't provide a telemetry key the health check will use the active telemetry configuration.

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

No branches or pull requests

4 participants