diff --git a/reporters/kamon-opentelemetry/src/main/scala/kamon/otel/MetricsConverter.scala b/reporters/kamon-opentelemetry/src/main/scala/kamon/otel/MetricsConverter.scala index 21abb4aa2..7f5f78a2d 100644 --- a/reporters/kamon-opentelemetry/src/main/scala/kamon/otel/MetricsConverter.scala +++ b/reporters/kamon-opentelemetry/src/main/scala/kamon/otel/MetricsConverter.scala @@ -21,8 +21,6 @@ import io.opentelemetry.sdk.metrics.internal.data._ import io.opentelemetry.sdk.resources.Resource import kamon.metric.Instrument.Snapshot import kamon.metric.{Distribution, MeasurementUnit, MetricSnapshot, PeriodSnapshot} -import kamon.tag.Lookups -import kamon.trace.Span.TagKeys import java.lang.{Double => JDouble, Long => JLong} import java.time.Instant @@ -34,16 +32,14 @@ class WithResourceMetricsConverter(resource: Resource, kamonVersion: String, fro private val fromNs = from.toEpochMilli * 1000000 private val toNs = to.toEpochMilli * 1000000 - private def instrumentationScopeInfo(snapshot: MetricSnapshot[_, _]): InstrumentationScopeInfo = { - // logic for looking up the component doesn't really seem to make sense - to be compliant we should probably be grouping the metrics by component before calling this - InstrumentationScopeInfo.create(snapshot.instruments.headOption.flatMap(_.tags.get(Lookups.option(TagKeys.Component))) getOrElse "kamon-instrumentation", kamonVersion, null) - } + private def instrumentationScopeInfo(snapshot: MetricSnapshot[_, _]): InstrumentationScopeInfo = + InstrumentationScopeInfo.create("kamon-metrics", kamonVersion, null) private def toString(unit: MeasurementUnit): String = unit.magnitude.name - def toGaugeDatum(g: Snapshot[Double]): DoublePointData = ImmutableDoublePointData.create(fromNs, toNs, SpanConverter.toAttributes(g.tags), g.value) + private def toGaugeDatum(g: Snapshot[Double]): DoublePointData = ImmutableDoublePointData.create(fromNs, toNs, SpanConverter.toAttributes(g.tags), g.value) - def toGaugeData(g: Seq[Snapshot[Double]]): GaugeData[DoublePointData] = ImmutableGaugeData.create(g.map(toGaugeDatum).asJava) + private def toGaugeData(g: Seq[Snapshot[Double]]): GaugeData[DoublePointData] = ImmutableGaugeData.create(g.map(toGaugeDatum).asJava) def convertGauge(gauge: MetricSnapshot.Values[Double]): MetricData = ImmutableMetricData.createDoubleGauge( @@ -54,7 +50,7 @@ class WithResourceMetricsConverter(resource: Resource, kamonVersion: String, fro toString(gauge.settings.unit), toGaugeData(gauge.instruments)) - def toHistogramDatum(s: Snapshot[Distribution]): HistogramPointData = { + private def toHistogramDatum(s: Snapshot[Distribution]): HistogramPointData = { val boundaries = ArrayBuffer.newBuilder[JDouble] val counts = ArrayBuffer.newBuilder[JLong] for (el <- s.value.bucketsIterator) { @@ -73,10 +69,10 @@ class WithResourceMetricsConverter(resource: Resource, kamonVersion: String, fro ) } - def toHistogramData(distributions: Seq[Snapshot[Distribution]]): Option[HistogramData] = + private def toHistogramData(distributions: Seq[Snapshot[Distribution]]): Option[HistogramData] = distributions.filter(_.value.buckets.nonEmpty) match { case Nil => None - case nonEmpty => Some(ImmutableHistogramData.create(AggregationTemporality.CUMULATIVE, nonEmpty.map(toHistogramDatum).asJava)) + case nonEmpty => Some(ImmutableHistogramData.create(AggregationTemporality.DELTA, nonEmpty.map(toHistogramDatum).asJava)) } def convertHistogram(histogram: MetricSnapshot.Distributions): Option[MetricData] = @@ -89,11 +85,11 @@ class WithResourceMetricsConverter(resource: Resource, kamonVersion: String, fro toString(histogram.settings.unit), d)) - def toCounterDatum(g: Snapshot[Long]): LongPointData = + private def toCounterDatum(g: Snapshot[Long]): LongPointData = ImmutableLongPointData.create(fromNs, toNs, SpanConverter.toAttributes(g.tags), g.value) - def toCounterData(g: Seq[Snapshot[Long]]): SumData[LongPointData] = - ImmutableSumData.create(false, AggregationTemporality.CUMULATIVE, g.map(toCounterDatum).asJava) + private def toCounterData(g: Seq[Snapshot[Long]]): SumData[LongPointData] = + ImmutableSumData.create(false, AggregationTemporality.DELTA, g.map(toCounterDatum).asJava) def convertCounter(counter: MetricSnapshot.Values[Long]): MetricData = ImmutableMetricData.createLongSum(