private static Metric GetOrCreateMetric(
            TelemetryClient telemetryClient,
            MetricAggregationScope aggregationScope,
            MetricIdentifier metricIdentifier,
            MetricConfiguration metricConfiguration)
        {
            Util.ValidateNotNull(telemetryClient, nameof(telemetryClient));

            MetricManager metricManager = telemetryClient.GetMetricManager(aggregationScope);
            Metric        metric        = metricManager.Metrics.GetOrCreate(metricIdentifier, metricConfiguration);

            return(metric);
        }
예제 #2
0
        private static Metric GetOrCreateMetric(
            TelemetryClient telemetryClient,
            MetricAggregationScope aggregationScope,
            string metricId,
            string dimension1Name,
            string dimension2Name,
            IMetricConfiguration metricConfiguration)
        {
            Util.ValidateNotNull(telemetryClient, nameof(telemetryClient));

            MetricManager metricManager = telemetryClient.GetMetricManager(aggregationScope);
            MetricsCache  cache         = metricManager.GetOrCreateExtensionState(MetricsCache.CreateNewInstance);

            if (cache == null)
            {
                throw new InvalidOperationException($"telemetryConfiguration.GetMetricManager().GetOrCreateExtensionState(..) unexpectedly returned null."
                                                    + $" This indicates that multiple extensions attempt to use"
                                                    + $" the \"Cache\" extension point of the {nameof(MetricManager)} in a conflicting manner.");
            }

            Metric metric = cache.GetOrCreateMetric(metricId, dimension1Name, dimension2Name, metricConfiguration);

            return(metric);
        }