public SerializedMetric Serialize <T>( MetricType metricType, string name, T value, double sampleRate = 1.0, string[] tags = null) { var serializedMetric = _serializerHelper.GetOptionalSerializedMetric(); if (serializedMetric == null) { return(null); } var builder = serializedMetric.Builder; var unit = _commandToUnit[metricType]; builder.Append(_prefix); builder.Append(name); builder.Append(':'); builder.AppendFormat(CultureInfo.InvariantCulture, "{0}", value); builder.Append('|'); builder.Append(unit); if (sampleRate != 1.0) { builder.AppendFormat(CultureInfo.InvariantCulture, "|@{0}", sampleRate); } _serializerHelper.AppendTags(builder, tags); return(serializedMetric); }
public void SendMetric <T>(MetricType metricType, string name, T value, double sampleRate = 1.0, string[] tags = null) { if (_randomGenerator.ShouldSend(sampleRate)) { var optionalSerializedMetric = _serializers.MetricSerializer.Serialize(metricType, name, value, sampleRate, tags); Send(optionalSerializedMetric, () => _optionalTelemetry?.OnMetricSent()); } }
public void SendMetric(MetricType metricType, string name, double value, double sampleRate = 1.0, string[] tags = null) { if (metricType == MetricType.Set) { throw new ArgumentException($"{nameof(SendMetric)} does not support `MetricType.Set`."); } if (_randomGenerator.ShouldSend(sampleRate)) { if (TryDequeueStats(out var stats)) { stats.Kind = StatsKind.Metric; stats.Metric.Tags = tags; stats.Metric.MetricType = metricType; stats.Metric.StatName = name; stats.Metric.SampleRate = sampleRate; stats.Metric.NumericValue = value; Send(stats, () => _optionalTelemetry?.OnMetricSent()); } } }
public void other_types_of_metric_are_not_supported(MetricType metricType) { Assert.Throws<NotSupportedException>(() => _statsdPublisher.Publish(new Metric(Some.String(), Some.Double(), metricType))); }