-
Hello 👋 I've yet another question about Opentelemetry Java SDK, specifically about it's exporter part. We have a bunch of gauge metrics with the same Mar. 02, 2022 9:40:28 P.M. io.opentelemetry.sdk.metrics.internal.state.MeterSharedState register
WARNING: Found duplicate metric definition: TestMetric
at unknown source
To enable better debugging, run your JVM with -Dotel.experimental.sdk.metrics.debug=true
Causes
- InstrumentType [OBSERVABLE_GAUGE] is async and already registered
Original instrument registered with same name but is incompatible.
at unknown source
To enable better debugging, run your JVM with -Dotel.experimental.sdk.metrics.debug=true
io.opentelemetry.sdk.metrics.internal.state.DuplicateMetricStorageException: Async metric with same name has already been created. Found previous metric: MetricDescriptor{name=TestMetric, description=, unit=1.0, sourceView=...etc} The question is this: does SDK contain any tools for deduplication or do we need to perform this before offering metrics to the exporter? JIC this is our setup for private val serviceName = config.getString("observability.service-name")
private val metricReaderFactory =
PeriodicMetricReader
.builder(OtlpGrpcMetricExporter.getDefault)
// 10 seconds
.setInterval(Duration.of(config.getInt("observability.read-metrics.interval-seconds"), ChronoUnit.SECONDS))
.newMetricReaderFactory()
private val metricResource = Resource.create(Attributes.of(SERVICE_NAME, serviceName))
private val meterProvider = SdkMeterProvider
.builder()
.registerMetricReader(metricReaderFactory)
.setResource(metricResource)
.build()
private val meter = meterProvider
.meterBuilder(serviceName)
.setInstrumentationVersion(config.getString("observability.instrumentation-version"))
.build()
// example how metrics are consumed
override def recordOurMetric(ourMetric: OurMetric): Unit = ourMetric match {
case LongGaugeMetric(metricName, labels, value) =>
meter
.gaugeBuilder(metricName.value)
.setUnit("1.0")
.ofLongs()
.buildWithCallback(measurement => {
measurement.record(value, toOtelAttributes(labels))
}) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Hi @vasigorc - the spec recently got updated to allow requesting metrics multiple time, I believe #4222 implements the change. That being said for performance reasons and just general idiomatic usage of our API, we'd expect you to keep a reference to any created instruments. So in the subclass with that Some general points
The instruments created from a |
Beta Was this translation helpful? Give feedback.
-
Asynchronous instrument callbacks are invoked here: https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/AsynchronousMetricStorage.java#L116-L119 |
Beta Was this translation helpful? Give feedback.
Asynchronous instrument callbacks are invoked here: https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/AsynchronousMetricStorage.java#L116-L119