Reputation: 1310
Is it possible to query app insights custom metrics and include the namespace in the result?
The Metrics Explorer provides a dropdown for namespace, but querying the customMetric table in the Log view doesn't seem to provide a column or other way of getting the namespace?
To clarify I am writing metrics to an app insights resource using
TelemetryClient.GetMetric(new MetricIdentifier("namespace","id","dimension")).TrackValue(1,"count");
In the portal, I select the app insights resource, the Monitoring "Blade"? then Metrics. This gives me a drop down selection of namespace with my name spaces listed.
If I select Monitoring, Logs instead I can write KQL against customMetrics table ie
customMetrics | summarize count() by name
What I want to do is (for example)
customMetrics | summarize count() by namespace
Obviously the actual query is more complex, I don't need a way of running that particular query but of accessing the namespace in the same KQL query as the other customMetrics data
Upvotes: 2
Views: 2403
Reputation: 1443
Currently namespace is not available as a column under customMetrics
in Application Insights Logs. Namespaces are just used as a way to organize metrics so that you can easily find them in Azure Monitor metrics explorer.
The namespace is sent and stored in Azure Monitor as part of Metric Definition object, but unfortunately metric definitions are not exposed in Application Insights Logs. If you are interested in getting the namespace directly from metric definition, then consider using REST API which returns all metric definition fields including namespace (API reference).
However, if you want to work with custom metrics as a log table and have a field for grouping metrics, filtering them or displaying this field in the results, I suggest sending it as custom dimension.
Here is an example of how custom dimensions can be tracked along metric values. I called the dimension metricCategory
in this example just to avoid confusion with the standard namespace field:
MetricIdentifier id = new MetricIdentifier("metricNamespace","metricId", "metricCategory");
Metric computersSold = _telemetryClient.GetMetric(id);
computersSold.TrackValue(1,"Namespace/category name");
Then this category can be used in KQL queries as any other custom metric field:
customMetrics | summarize count() by tostring(customDimensions.metricCategory)
Upvotes: 1
Reputation: 4786
You can get Filter out the namespace in an InsightsMetrics. which follows
If you want to add the custom metrics with namespace you have to add the custom metrics with the specific namespace to retrieve both metrics and namespaces.
Please check the blog to add custom metrics and namespace in application insights and retrieve those accordingly.
Refer here for more information
Upvotes: 0