1

"Microsoft.ApplicationInsights" Version="2.10.0"

 public void GetAppMetric(string metricId, double metricValue)
    {
        string source = string.IsNullOrWhiteSpace(this.Store[Logging.Constants.Key]) ?
                                           "NA" : this.Store[Logging.Constants.Key];
        string correlationId = string.IsNullOrWhiteSpace(this.Store[Logging.Constants.CorrelationId]) ?
                                 "NA" : this.Store[Logging.Constants.CorrelationId];
        MetricIdentifier metricIdentifier = new MetricIdentifier("OutboundConnection", metricId, "source", "correlationId");
        Metric metric = this.TelemetryClient.GetMetric(metricIdentifier);
        if (metric.TryGetDataSeries(out MetricSeries series, source, correlationId))
        {
            series.TrackValue(metricValue);
        }
        else
        {
            this.TelemetryClient.TrackTrace($"No series is present, metricId: {metricId}, source: {source}, correlationId : {correlationId}");
        }
    }

It does track the value but very often it's adding the trace "No series present" messages.
If all the dimensions are passed correctly, In what case the series return can be false? I tried debugging, it never goes into else block but on the server, it logs "No series present message" with correct metricId, source, and correlationId.

enter image description here

n1k1
  • 51
  • 6
  • 1
    the docs at https://docs.microsoft.com/en-us/dotnet/api/microsoft.applicationinsights.metric.trygetdataseries?view=azure-dotnet say: "False if the indicated series could not be retrieved or created because a dimension cap or a metric series cap was reached." so maybe you're hitting a cap?unrelated but fishy: you shouldn't use repeated `this.store[x]` lookups, if possible. you're possibly wasting a lot of time on repeated dictionary operations which could be really bad if this dictionary has any kind of locking on it. prefer something like `this.Store.TryGetValue(x, out source)` if you can. – John Gardner Jan 19 '22 at 01:20

0 Answers0