[BUG] trackMetric does not track stdDev nor sum
See original GitHub issueWhen tracking a (custom) metric, the standard deviation is not tracked (as valueStdDev
) and valueSum
is identical to value
.
Additionally, when min
-value equals 1,
Steps to Reproduce
- OS/Browser: Google Chrome 93.0.4577.82 (64-bit), Windows 10
- SDK Version [e.g. 22]: javascript:2.7.0
- How you initialized the SDK:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="https://js.monitor.azure.com/scripts/b/ai.2.7.0.min.js"></script>
<script>
let msg = { config: {
"instrumentationKey": "<<>>",
"appId": "Debug Metrics"
}}
let init = new Microsoft.ApplicationInsights.ApplicationInsights(msg);
let appInsights = init.loadAppInsights();
</script>
</head>
<body>
<script>
appInsights.trackMetric({name: 'my_metric', average: 1, sampleCount: 2, min: 1, max: 2, stdDev: 1.0});
appInsights.flush();
</script>
</body>
</html>
When viewing the tracked metric in Application Insights on portal.azure.com, the values do not match what was provided.
Expected behavior
- It should be possible to track the
sum
. - When retrieving the metric in the Application Insights logs on portal.azure.com, the
value
,valueCount
,valueSum
,valueMin
,valueMax
, andvalueStdDev
should match (within some reasonable precision) to the values submitted from the JS script.
Additional context
The documentation on appInsights.trackMetric
is entirely missing (for the JS-part), and this is my best guess for actually getting something through. A lot of other attempts (e.g. trackMetric('name',value)
didn’t even raise an error – but nothing appeared to be sent).
I have further found, that the second argument to trackMetric
can be used to send additional properties (i.e. customDimensions
), such as appInsights.trackMetric({name: 'bacon', average: 5, sampleCount: 6, min: 1, max: 15}, {PageName: "foo", "PageUrl": "/", "questionable_field": "zap" });
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (9 by maintainers)
Top GitHub Comments
Ok, the issue with the average / sampleCount is because there is a different calculation between what the SDK takes and how the backend “processes” the values.
Simplistically, the backend expects the total “value” of the metric and the number of events “count” and from these it calculates the “average”
value / count
and if the min is smaller or the max is larger then the passed values are replaced with this calculation.So, the fix is problematic… As technically the SDK should pass the
value
as the (average * (sampleCount || 1)) instead of just the average. However, doing this will probably break someone as now the reportedvalue
won’t be the value of theaverage
passed (if thesampleCount
is > 1)… Will think about this overnight.Well crap!