Skip to content

Commit faf544f

Browse files
committed
address some review comments
1 parent 53934e3 commit faf544f

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

reporters/kamon-opentelemetry/src/main/scala/kamon/otel/MetricsConverter.scala

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import io.opentelemetry.sdk.metrics.internal.data._
2121
import io.opentelemetry.sdk.resources.Resource
2222
import kamon.metric.Instrument.Snapshot
2323
import kamon.metric.{Distribution, MeasurementUnit, MetricSnapshot, PeriodSnapshot}
24-
import kamon.tag.Lookups
25-
import kamon.trace.Span.TagKeys
2624

2725
import java.lang.{Double => JDouble, Long => JLong}
2826
import java.time.Instant
@@ -34,16 +32,14 @@ class WithResourceMetricsConverter(resource: Resource, kamonVersion: String, fro
3432
private val fromNs = from.toEpochMilli * 1000000
3533
private val toNs = to.toEpochMilli * 1000000
3634

37-
private def instrumentationScopeInfo(snapshot: MetricSnapshot[_, _]): InstrumentationScopeInfo = {
38-
// 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
39-
InstrumentationScopeInfo.create(snapshot.instruments.headOption.flatMap(_.tags.get(Lookups.option(TagKeys.Component))) getOrElse "kamon-instrumentation", kamonVersion, null)
40-
}
35+
private def instrumentationScopeInfo(snapshot: MetricSnapshot[_, _]): InstrumentationScopeInfo =
36+
InstrumentationScopeInfo.create("kamon-metrics", kamonVersion, null)
4137

4238
private def toString(unit: MeasurementUnit): String = unit.magnitude.name
4339

44-
def toGaugeDatum(g: Snapshot[Double]): DoublePointData = ImmutableDoublePointData.create(fromNs, toNs, SpanConverter.toAttributes(g.tags), g.value)
40+
private def toGaugeDatum(g: Snapshot[Double]): DoublePointData = ImmutableDoublePointData.create(fromNs, toNs, SpanConverter.toAttributes(g.tags), g.value)
4541

46-
def toGaugeData(g: Seq[Snapshot[Double]]): GaugeData[DoublePointData] = ImmutableGaugeData.create(g.map(toGaugeDatum).asJava)
42+
private def toGaugeData(g: Seq[Snapshot[Double]]): GaugeData[DoublePointData] = ImmutableGaugeData.create(g.map(toGaugeDatum).asJava)
4743

4844
def convertGauge(gauge: MetricSnapshot.Values[Double]): MetricData =
4945
ImmutableMetricData.createDoubleGauge(
@@ -54,7 +50,7 @@ class WithResourceMetricsConverter(resource: Resource, kamonVersion: String, fro
5450
toString(gauge.settings.unit),
5551
toGaugeData(gauge.instruments))
5652

57-
def toHistogramDatum(s: Snapshot[Distribution]): HistogramPointData = {
53+
private def toHistogramDatum(s: Snapshot[Distribution]): HistogramPointData = {
5854
val boundaries = ArrayBuffer.newBuilder[JDouble]
5955
val counts = ArrayBuffer.newBuilder[JLong]
6056
for (el <- s.value.bucketsIterator) {
@@ -73,10 +69,10 @@ class WithResourceMetricsConverter(resource: Resource, kamonVersion: String, fro
7369
)
7470
}
7571

76-
def toHistogramData(distributions: Seq[Snapshot[Distribution]]): Option[HistogramData] =
72+
private def toHistogramData(distributions: Seq[Snapshot[Distribution]]): Option[HistogramData] =
7773
distributions.filter(_.value.buckets.nonEmpty) match {
7874
case Nil => None
79-
case nonEmpty => Some(ImmutableHistogramData.create(AggregationTemporality.CUMULATIVE, nonEmpty.map(toHistogramDatum).asJava))
75+
case nonEmpty => Some(ImmutableHistogramData.create(AggregationTemporality.DELTA, nonEmpty.map(toHistogramDatum).asJava))
8076
}
8177

8278
def convertHistogram(histogram: MetricSnapshot.Distributions): Option[MetricData] =
@@ -89,11 +85,11 @@ class WithResourceMetricsConverter(resource: Resource, kamonVersion: String, fro
8985
toString(histogram.settings.unit),
9086
d))
9187

92-
def toCounterDatum(g: Snapshot[Long]): LongPointData =
88+
private def toCounterDatum(g: Snapshot[Long]): LongPointData =
9389
ImmutableLongPointData.create(fromNs, toNs, SpanConverter.toAttributes(g.tags), g.value)
9490

95-
def toCounterData(g: Seq[Snapshot[Long]]): SumData[LongPointData] =
96-
ImmutableSumData.create(false, AggregationTemporality.CUMULATIVE, g.map(toCounterDatum).asJava)
91+
private def toCounterData(g: Seq[Snapshot[Long]]): SumData[LongPointData] =
92+
ImmutableSumData.create(false, AggregationTemporality.DELTA, g.map(toCounterDatum).asJava)
9793

9894
def convertCounter(counter: MetricSnapshot.Values[Long]): MetricData =
9995
ImmutableMetricData.createLongSum(

0 commit comments

Comments
 (0)