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

Make Initializing TelemetryClient more intuitive #826

Closed
TimothyMothra opened this issue Jun 1, 2018 · 12 comments
Closed

Make Initializing TelemetryClient more intuitive #826

TimothyMothra opened this issue Jun 1, 2018 · 12 comments
Labels
breaking-change Requires breaking change, only fits into a major version bump stale

Comments

@TimothyMothra
Copy link
Member

A customer found a combination of initializing the TelemetryConfiguration and TelemetryClient that results in no telemetry being sent to the Portal (see code sample 1 below).
It's not intuitive why this doesn't work. Telemetry is visible in the Debug window and the Visual Studio Search window.

This is not blocking because there are several other ways to successfully initialize the TelemetryClient.

  1. This does not work:
TelemetryConfiguration tcConfig = new TelemetryConfiguration();

TelemetryClient tc = new TelemetryClient(tcConfig)
{
    InstrumentationKey = ikey
};
  1. This works:
TelemetryConfiguration tcConfig = new TelemetryConfiguration
{
    InstrumentationKey = ikey
};

TelemetryClient tc = new TelemetryClient(tcConfig);
  1. This works:
TelemetryConfiguration tcConfig = new TelemetryConfiguration(instrumentationKey: ikey);

TelemetryClient tc = new TelemetryClient(tcConfig);
  1. This works: code sample from Microsoft Docs: console applications
TelemetryConfiguration.Active.InstrumentationKey = ikey;

TelemetryClient tc = new TelemetryClient();
  1. This works:
TelemetryConfiguration tcConfig = TelemetryConfiguration.Active;

TelemetryClient tc = new TelemetryClient(tcConfig)
{
    InstrumentationKey = ikey
};

In my opinion, It's confusing to have the InstrumentationKey in both places.
For 3.0, I propose that we make the TelemetryClient.InstrumentationKey readonly or remove it all together.
There may be a historical reason this exists, but I think we can make it better! :)

Version Info

Console App
SDK Version : 2.6.4
.NET Version : 4.7.1
How Application was onboarded with SDK: VisualStudio
OS : Windows 10

@lmolkova
Copy link
Member

lmolkova commented Jun 1, 2018

@TimothyMothra
Copy link
Member Author

Thanks for the context discussions!

If the TelemetryClient.InstrumentationKey is intended to be an override of the TelemetryConfiguration.InstrumentationKey I think we should detail that in our summary xml. We should make every effort to steer customers to the TelemetryConfiguration property and I think we could do better!

https://github.com/Microsoft/ApplicationInsights-dotnet/blob/b4495b340be2dfd46ffa6137a9a4ebf2f4035452/src/Microsoft.ApplicationInsights/TelemetryClient.cs#L67-L74

@TimothyMothra TimothyMothra added this to the 3.0 milestone Jun 1, 2018
@TimothyMothra TimothyMothra changed the title Problem Initializing TelemetryClient 3.0 Make Initializing TelemetryClient more intuitive Jun 1, 2018
@AC740
Copy link

AC740 commented Sep 12, 2018

Cool, thanks. Hope we only need to set instrumentationkey one time in future.

Mine is SDK 2.4 and ASP.NET 4.6.1 Web application.
Sample 1(of course), 2, 3 and 5 don't work. But fortunately 4 works.

@TimothyMothra
Copy link
Member Author

@NeilMacMullen
Copy link

Sigh.... Just wasted a couple of hours due to this issue (in combination with the telemetry stream not automatically flushing on disposal). The "obvious" route for anyone trying to trouble-shoot AppInsights issues is just to try to write...

void Main()
{
var key = "...." ;
var client = new TelemetryClient(key)
client.GetMetric("my metric").TrackValue(1);
Console.WriteLine("sent metric - now look in the portal"); 
}

It would be nice if this "just worked"....

@Dmitry-Matveev
Copy link
Member

@NeilMacMullen , the example with GetMetric().TrackValue() won't work even with the right Instrumentation Key setup because metrics on that API are aggregated over 1 minute and then sent. Console application will exit by then and no telemetry will be sent. Flush() won't help here either - there is not telemetry to Flush() yet - it will only appear in 1 minute. You can try Console.ReadKey() and wait for a minute (of course after you initialize Instrumentation Key in one of the working way @MS-TimothyMothra mentioned above).

@JohnTube
Copy link

Another way not mentioned in the original post can be found here:

telemetryClient.Context.InstrumentationKey = instrumentationKey;

which is the same as

telemetryClient.InstrumentationKey = instrumentationKey;

but more confusing!

@CharlieDigital
Copy link

This is a really, really time wasting issue, IMO.

I have also spent several hours on this issue only resolving it after stumbling on this issue on Stack:

https://stackoverflow.com/a/52717627/116051

Very confusing.

@sonic1981
Copy link

I don't understand why someone just hasn't add an [Obsolete()] attribute onto this. Surely that is a 30 second job and would save a lot of confusion. I'm realising that many of the Azure classes are poorly maintained...I wonder what the AWS ones are like 🙅

@CharlieDigital
Copy link

@sonic1981 "Grass is always greener on the other side". I've recently been working with AWS Amplify, AppSync, and CloudFormation.

The gaps in the documentation are just as bad once you get beyond basics.

That said, CloudWatch and X-Ray are leaps and bounds better than AppInsights from an ease of use perspective.

@reyang reyang added the breaking-change Requires breaking change, only fits into a major version bump label Mar 9, 2021
@reyang reyang changed the title 3.0 Make Initializing TelemetryClient more intuitive Make Initializing TelemetryClient more intuitive Mar 9, 2021
@reyang reyang removed this from the 3.0 milestone Mar 9, 2021
@github-actions
Copy link

github-actions bot commented Jan 4, 2022

This issue is stale because it has been open 300 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@ShiningMassXAcc
Copy link
Member

Not that I'm expecting a change of course, but just encountered this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Requires breaking change, only fits into a major version bump stale
Projects
None yet
Development

No branches or pull requests

10 participants