/// <summary> /// Tracks a counter which is aggregated into a MetricTelemetry item. /// </summary> public static void TrackAggregateMetric(this TelemetryClient telemetryClient, string name, double value, string property1 = null, string property2 = null, string property3 = null) { if (telemetryClient == null) { AggregateMetricsEventSource.Log.TelemetryClientRequired(); return; } if (string.IsNullOrWhiteSpace(name)) { AggregateMetricsEventSource.Log.TrackAggregateMetricInvalidMetricName(); return; } if (aggregationSets == null) { Initialize(); } Debug.Assert(aggregationSets != null); name = GetAggregateMetricName(name); Debug.Assert(name.Length > 0 && name.Length <= Constants.NameMaxLength, "Invalid name."); int aggregationSetKey = AggregationSet.GetKey(telemetryClient, name); AggregationSet aggregationSet = aggregationSets.GetOrAdd(aggregationSetKey, (key) => { return(new AggregationSet(telemetryClient, name)); }); aggregationSet.AddAggregation(value, property1, property2, property3); }
/// <summary> /// Unregisters an aggregate metric. /// </summary> public static void UnregisterAggregateMetric(this TelemetryClient telemetryClient, string name) { if (string.IsNullOrWhiteSpace(name)) { AggregateMetricsEventSource.Log.UnregisterAggregateMetricInvalidMetricName(); return; } name = GetAggregateMetricName(name); int key = AggregationSet.GetKey(telemetryClient, name); AggregateMetricProperties properties; metricRegistrations.TryRemove(key, out properties); AggregationSet aggregationSet; aggregationSets.TryRemove(key, out aggregationSet); }
/// <summary> /// Optionally registers an aggregate metric to provide additional aggregation metadata. /// </summary> public static void RegisterAggregateMetric(this TelemetryClient telemetryClient, string name, string p1Name = null, string p2Name = null, string p3Name = null, PercentileCalculation percentileCalculation = PercentileCalculation.DoNotCalculate) { if (string.IsNullOrWhiteSpace(name)) { AggregateMetricsEventSource.Log.RegisterAggregateMetricInvalidMetricName(); return; } name = GetAggregateMetricName(name); int registrationKey = AggregationSet.GetKey(telemetryClient, name); if (!metricRegistrations.TryAdd(registrationKey, new AggregateMetricProperties() { P1Name = p1Name, P2Name = p2Name, P3Name = p3Name, PercentileCalculation = percentileCalculation })) { AggregateMetricsEventSource.Log.RegisterAggregateMetricDuplicateMetricName(name); } }