In Application Insights, I am trying to use the Java SDK to send standard metrics by setting the namespace name to the standard one, but this doesn't appear to be working.

jgialis 0 Reputation points
2023-03-29T06:46:34.3+00:00

Using the following code:

TelemetryClient telemetryClient = new TelemetryClient();
MetricTelemetry metric = new MetricTelemetry("exceptions/browser", value);
TelemetryContext context = metric.getContext();
context.getProperties().put("metricNamespaceName", "microsoft.insights/components");
telemetryClient.trackMetric(metric);

I would expect that the metric with metric ID: "exceptions/browser" be sent and viewable in the metrics viewer under the "microsoft.insights.components" metric (which is a default standard one in my case) but it instead gets placed under "azure.applicationinsights" namespace (which is a custom one in my case).

My question: Is it possible to send standard metrics to Application Insights using the above approach? I am able to send custom metrics, but I am still not able to create my own custom namespaces.

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,211 questions
{count} votes

1 answer

Sort by: Most helpful
  1. AnuragSingh-MSFT 21,361 Reputation points
    2023-03-30T12:20:02.24+00:00

    @jgialis , thank you for the question.

    I see that you are trying to send metrics to STANDARD namespace. Note that the method being used - trackMetric() is used to send custom metric. When you use this method, irrespective of the metricNamespaceName you try to specify, they would always be placed under the CUSTOM category.

    There are 2 observations from your code above:

    1. The getProperties().put() method used adds these as custom dimensions. They are different from the namespce as you see in the metric explorer. When you use this getproperties().put() method, the key/value gets added to logs as below (as can be seen from customMetric table) User's image However, in metric explorer, you would not see this new namespace and it will be listed under the default custom namespace - azure.applicationinsights.
    2. If you would like to set namespace, which can be used in metric explorer, you should be using the setMetricNamespace() method of MetricTelemetry class, as shown below
       TelemetryClient telemetryClient = new TelemetryClient();
       MetricTelemetry metric = new MetricTelemetry("custom exception count", 4.0); //new metric name
       metric.setMetricNamespace("Application Insights standard metrics"); //the namespace being set
    

    Note that - even if I have used the exact namespace of the STANDARD category, the metric gets listed under CUSTOM category with this namespace:

    User's image

    Hope this helps.

    If the answer did not help, please add more context/follow-up question for it, and we will help you out. Else, if the answer helped, please click Accept answer so that it can help others in the community looking for help on similar topics.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.