2
votes

I have application insight running with a "pay as you go" model. Standard performance metrics show up in the portal. Custom metrics don't show up in the metrics section.

My Environment. A custom .NET core console app running plain TCP sockets. (no ASP.NET CORE) using

<PackageReference Include="Microsoft.ApplicationInsights" Version="2.7.2" />

The Telemetry class is constructed with the default constructor ( and no XML config file)

The custom metrics are created like

Telemetry.Client.GetMetric("number of clients").TrackValue(600.0);

Question: What do i miss or doing wrong, that the custom metrics don't show up? Is the "metrics" section in the azure portal the wrong place to look for custom metrics?

Update

The sample code also doesn't upload any custom metrics to azure.

        TelemetryClient client = new TelemetryClient();
        client.InstrumentationKey = "a valid key";
        client.GetMetric("test me").TrackValue(200);
        client.Flush();
        Thread.Sleep(5000);
2
What is key and val?Roman Marusyk
key = string, val = double, the string has space chars insideHenk
Ok, I know. I mean what is the value of that variablesRoman Marusyk
Umm, don't you normally use TelemetryClient.TrackMetric(string, double) for custom metrics? Or is this some other way I don't about? :Djuunas
The docs say TelemetryClient.TrackMetric(string, double) is debricated. docs.microsoft.com/en-us/azure/application-insights/…Henk

2 Answers

6
votes

This issue due to the instrumentation key is not configured correctly.

When use GetMetric().TrackValue(), we should use this way to configure instrumentation key:

TelemetryConfiguration.Active.InstrumentationKey = "your key";

My code as below:

  TelemetryClient client = new TelemetryClient();
  TelemetryConfiguration.Active.InstrumentationKey = "your key";  
  client.GetMetric("test33").TrackValue(100);  

  System.Threading.Thread.Sleep(1000*5);
  client.Flush();

  Console.WriteLine("Hello World!");
  Console.ReadLine();

Then in the visual studio output window, you can see the ikey is showing there: enter image description here

Then go to azure portal -> application insights -> metrics, you can see your metric: enter image description here

For comparison, when you use the following code:

client.InstrumentationKey = "a valid key";
client.GetMetric("test me").TrackValue(200);

after execution, in the visual studio, you can see there is no ikey in the output window, so no metric would be sent to azure portal: enter image description here

2
votes

Thanks to Ivan Yang i found a github issue which is discussing this problem in detail.

It looks like there are multiple cases to create invalid configurations.

For example this is currently also a INVALID configuration

TelemetryConfiguration tcConfig = new TelemetryConfiguration();

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

More details on https://github.com/Microsoft/ApplicationInsights-dotnet/issues/826 and on https://www.reddit.com/r/Unity3D/comments/8igabt/using_microsoft_azure_app_insights_and_unity/