Reputation: 769
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);
Upvotes: 3
Views: 2533
Reputation: 769
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/
Upvotes: 2
Reputation: 30025
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:
Then go to azure portal -> application insights -> metrics, you can see your metric:
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:
Upvotes: 7