lib/elastic_apm/transport/serializers/metricset_serializer.rb in elastic-apm-3.1.0 vs lib/elastic_apm/transport/serializers/metricset_serializer.rb in elastic-apm-3.2.0

- old
+ new

@@ -3,18 +3,31 @@ module ElasticAPM module Transport module Serializers # @api private class MetricsetSerializer < Serializer + # rubocop:disable Metrics/MethodLength def build(metricset) - { - metricset: { - timestamp: metricset.timestamp.to_i, - tags: keyword_object(metricset.labels), - samples: build_samples(metricset.samples) - } + payload = { + timestamp: metricset.timestamp.to_i, + samples: build_samples(metricset.samples) } + + if metricset.tags? + payload[:tags] = mixed_object(metricset.tags) + end + + if metricset.transaction + payload[:transaction] = metricset.transaction + end + + if metricset.span + payload[:span] = metricset.span + end + + { metricset: payload } end + # rubocop:enable Metrics/MethodLength private def build_samples(samples) samples.each_with_object({}) do |(key, value), hsh|