Skip to content

Commit

Permalink
removed decrement and added attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
José Carlos Montañez authored and José Carlos Montañez committed Sep 4, 2024
1 parent e908824 commit 22bc441
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package com.xebia.functional.xef.metrics
interface CounterMetric {
fun increment(n: Long)

fun decrement(n: Long)
fun increment(n: Long, attributes: Map<String, String>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class InMemoryCounterMetric(val name: String, val logger: KLogger) : CounterMetr
logger.info { "Counter $name incremented to ${count.get()}" }
}

override fun decrement(n: Long) {
count.decrementAndGet()
logger.info { "Counter $name decremented to ${count.get()}" }
override fun increment(n: Long, attributes: Map<String, String>) {
count.addAndGet(n)
logger.info { "Counter $name incremented to ${count.get()} with those attributes: ${attributes.entries.joinToString( ",")}" }
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.xebia.functional.xef.opentelemetry

import com.xebia.functional.xef.metrics.CounterMetric
import io.opentelemetry.api.common.Attributes

class OpenTelemetryCounter(private val longCounter: io.opentelemetry.api.metrics.LongCounter) :
CounterMetric {
override fun increment(n: Long) {
longCounter.add(n)
}

override fun decrement(n: Long) {
longCounter.add(n)
override fun increment(n: Long, attributes: Map<String, String>) {
val attributesBuilder = Attributes.builder()
attributes.forEach { (k, v) -> attributesBuilder.put(k, v) }
longCounter.add(n, attributesBuilder.build())
}
}

0 comments on commit 22bc441

Please sign in to comment.