private void SetMetrics(ISupportMetrics telemetry, string key, double value)
 {
     key = _telemetryKeyCache.GetProcessedKey(key);
     if (!telemetry.Metrics.ContainsKey(key))
     {
         telemetry.Metrics.Add(key, value);
     }
 }
        private void SetCustomDimension(ISupportProperties telemetry, string key, string value, bool isValueOptional = false)
        {
            key = _telemetryKeyCache.GetProcessedKey(key);

            if (telemetry == null)
            {
                _logger.LogError("telemetry object is null in telemetry initializer.");
                return;
            }

            if (string.IsNullOrEmpty(key))
            {
                _logger.LogError("Key is required to set custom dimension.");
                return;
            }

            if (string.IsNullOrEmpty(value))
            {
                if (isValueOptional)
                {
                    _logger.LogTrace("Value is null or empty for key: {0}", key);
                }
                else
                {
                    _logger.LogError("Value is required to set custom dimension. Key: {0}", key);
                }
                return;
            }

            if (!telemetry.Properties.ContainsKey(key))
            {
                telemetry.Properties.Add(key, value);
            }
            else
            {
                string existingValue = telemetry.Properties[key];
                if (string.Equals(existingValue, value, System.StringComparison.OrdinalIgnoreCase))
                {
                    _logger.LogTrace("The telemetry already contains the property of {0} with the same value of {1}.", key, existingValue);
                }
                else
                {
                    telemetry.Properties[key] = value;
                    _logger.LogDebug("The telemetry already contains the property of {0} with value {1}. The new value is: {2}", key, existingValue, value);
                }
            }
        }