public MetricSnapshotDatadogJsonWriter(
            Stream stream,
            TimeSpan flushInterval,
            Func <IDatadogMetricJsonWriter> metricPointTextWriter = null)
        {
            _stream        = stream ?? throw new ArgumentNullException(nameof(stream));
            _flushInterval = flushInterval;
            _series        = new DatadogSeries();

            _metricMetricJsonWriter = metricPointTextWriter != null?metricPointTextWriter() : DatadogFormatterConstants.GraphiteDefaults.MetricPointTextWriter();
        }
Example #2
0
        public DatadogPoint(
            string context,
            string measurement,
            IReadOnlyDictionary <string, object> fields,
            MetricTags tags,
            IDatadogMetricJsonWriter metricJsonWriter,
            TimeSpan flushInterval,
            DateTime?utcTimestamp = null)
        {
            _metricJsonWriter = metricJsonWriter ?? throw new ArgumentNullException(nameof(metricJsonWriter));

            FlushInterval = flushInterval;

            if (string.IsNullOrEmpty(measurement))
            {
                throw new ArgumentException("A measurement must be specified", nameof(measurement));
            }

            if (fields == null || fields.Count == 0)
            {
                throw new ArgumentException("At least one field must be specified", nameof(fields));
            }

            if (fields.Any(f => string.IsNullOrEmpty(f.Key)))
            {
                throw new ArgumentException("Fields must have non-empty names", nameof(fields));
            }

            if (utcTimestamp != null && utcTimestamp.Value.Kind != DateTimeKind.Utc)
            {
                throw new ArgumentException("Timestamps must be specified as UTC", nameof(utcTimestamp));
            }

            Context      = context;
            Measurement  = measurement;
            Fields       = fields;
            Tags         = tags;
            UtcTimestamp = utcTimestamp ?? DateTime.UtcNow;
        }