public static string BuildJson(MetricsData data, IEnumerable <EnvironmentEntry> environment, Clock clock, bool indented = DefaultIndented)
        {
            var version = Version.ToString(CultureInfo.InvariantCulture);

            return(JsonMetricsContext.FromContext(data, environment, version)
                   .ToJsonObject()
                   .AsJson(indented));
        }
        public static string BuildJson(MetricsData data, IEnumerable <EnvironmentEntry> environment, Clock clock, bool indented = DefaultIndented)
        {
            var version   = Version.ToString(CultureInfo.InvariantCulture);
            var timestamp = clock.UTCDateTime.ToString("yyyy-MM-dd HH:mm:ss.ffff", CultureInfo.InvariantCulture);

            return(JsonMetricsContext.FromContext(data, environment, version, timestamp)
                   .ToJsonObject()
                   .AsJson(indented));
        }
 public static JsonMetricsContext FromContext(MetricsData contextData, IEnumerable <EnvironmentEntry> environment, string version, string timestamp)
 {
     return(new JsonMetricsContext
     {
         Version = version,
         Timestamp = timestamp,
         Environment = contextData.Environment.Union(environment).ToDictionary(e => e.Name, e => e.Value),
         Context = contextData.Context,
         Gauges = contextData.Gauges.Select(g => JsonGauge.FromGauge(g)).ToArray(),
         Counters = contextData.Counters.Select(c => JsonCounter.FromCounter(c)).ToArray(),
         Meters = contextData.Meters.Select(m => JsonMeter.FromMeter(m)).ToArray(),
         Histograms = contextData.Histograms.Select(h => JsonHistogram.FromHistogram(h)).ToArray(),
         Timers = contextData.Timers.Select(t => JsonTimer.FromTimer(t)).ToArray(),
         ChildContexts = contextData.ChildMetrics.Select(c => JsonMetricsContext.FromContext(c)).ToArray()
     });
 }