TelemetryClient.TelemetryClient() is obsolete.
This warnings come up for C# TelemetryClient c = new TelemetryClient();
This documentation needs to be updated on how to initialize the client correctly.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@NorthHighlandNicole Thanks for the feedback! We are currently investigating and will update you shortly.
@NorthHighlandNicole This should still be correct. I'm not seeing any warnings in my project. @lgayhardt Can you confirm if there have been any recent changes?
@NorthHighlandNicole It appears that this is a somewhat complicated subject.
The short version is that the default constructor for .NET and .NET Core has been marked obsolete, however TelemetryClient should still work for everything else.
There is a link to other documentation for these scenarios, however it's understandable that someone might miss them:
For ASP.NET Core apps and Non HTTP/Worker for .NET/.NET Core apps, it is recommended to get an instance of TelemetryClient from the dependency injection container as explained in their respective documentation.
You can get additional information about this here:
https://github.com/microsoft/ApplicationInsights-dotnet/issues/1152
@NorthHighlandNicole Reviewing your feedback, I believe there's an opportunity to make this more clear for other readers. I'm going to assign this to the document author so that we can improve our documentation here.
This doc already recommends to use TelemetryClient from DI.
https://docs.microsoft.com/en-us/azure/azure-monitor/app/api-custom-events-metrics#get-a-telemetryclient-instance
@cijothomas I'm not working in .net core
If not on .net core, the doc suggest using new TelemetryClient().
@cijothomas Which is why I opened this, it has been marked obsolete.
Its obsolete only for .NET Core. .NET Framework continues to use it, along with TC.Active as well.
@NorthHighlandNicole Thank you for calling attention to this. I made some changes to the doc to hopefully help further clarify things. The change are merged internally but they will go-live tomorrow.
There were breaking changes in V2 of the Application Insights SDK. In particular, the signature changed for some JavaScript calls like trackPageView and trackException. The examples on this page are still showing the old way of calling. For example this page shows the following example, which will not work with V2:
appInsights.trackPageView("tab1");
It should be something like:
appInsights.trackPageView({ name: "tab1" });
Thanks!
Most helpful comment
@NorthHighlandNicole Thanks for the feedback! We are currently investigating and will update you shortly.