opentelemetry-java-contrib icon indicating copy to clipboard operation
opentelemetry-java-contrib copied to clipboard

OTel Metrics Micrometer MeterProvider

Open HaloFour opened this issue 3 years ago • 11 comments

First pass at implementing a MeterProvider that wraps Micrometer MeterRegistry.

HaloFour avatar Aug 30 '21 11:08 HaloFour

It looks like the async instruments from OTEL may need more machinery to work correctly here.

I see, that was my misunderstanding. I assumed that the callback would hold onto the observer and would continually publish results.

What's the cost of registering counters + things w/ labels in micrometer? The current mechanism to allow Baggage labels in metric attributes may come with large performance costs.

Every permutation of tags is a separate instrument. As of today Micrometer has no concept of exemplars.

HaloFour avatar Aug 30 '21 13:08 HaloFour

Every permutation of tags is a separate instrument. As of today Micrometer has no concept of exemplars.

Baggage != exemplars. baggage is the ability to attach labels (dynamically) via distributed context propagation.

See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/baggage/api.md

jsuereth avatar Aug 30 '21 14:08 jsuereth

Baggage != exemplars. baggage is the ability to attach labels (dynamically) via distributed context propagation.

Right, in that case we can just treat them like Attributes and mix them in with the Tags used to create each instrument. Should be easy as I do have Context readily available. I'd be concerned that Baggage would contain keys with very high cardinality, though, but that's an issue that any metrics exporter will have to deal with.

HaloFour avatar Aug 30 '21 15:08 HaloFour

Just curious, is there a reason to have an SDK that implements the OTel metrics API using micrometer, instead of the other way around, a micrometer registry that writes to the OTel metrics API? Is it to allow OTel users to have access to all of micrometer registry implementations? If the collector can fill that gap, the reverse may be more valuable by opening up cool features like exemplars and baggage to micrometer users (at least I think it'd be possible).

Of course it could be good to have both, just wondering.

anuraaga avatar Sep 02 '21 06:09 anuraaga

@anuraaga

Just curious, is there a reason to have an SDK that implements the OTel metrics API using micrometer, instead of the other way around, a micrometer registry that writes to the OTel metrics API?

My use case is that we already have a series of Spring apps that make fairly extensive use of Micrometer and they report to a custom metrics exporter that only has Micrometer bindings. Having a binding from OTel to Micrometer would make it easier to adopt components that make use of OTel metrics (e.g. BatchSpanProcessor) without having to take on the risk of replacing the rest of the metrics config. That said, given that I'm finding it more difficult than I had anticipated to bridge between the facades in this direction I am questioning whether it will be easier or less risky. But I do think that having a bridge between Micrometer and OTel in both directions could be useful.

HaloFour avatar Sep 02 '21 13:09 HaloFour

Hi @HaloFour - I think this was implemented by @mateuszrzeszutek now

https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/micrometer/micrometer-1.5/library

Should we go ahead and close this PR?

anuraaga avatar Jan 25 '22 05:01 anuraaga

I think this was implemented by @mateuszrzeszutek now

https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/micrometer/micrometer-1.5/library

This PR seems to implement the reverse bridge: OTel -> Micrometer. Anyway -- is this still valid/needed?

mateuszrzeszutek avatar Jan 25 '22 09:01 mateuszrzeszutek

Personally, anyone using Micrometer today is more likely to want to stick with the Micrometer API, and would be more interested in a OTeL Registry for Micrometer as an alternative output mechanism.

What are your thoughts @jonatan-ivanov?

kenfinnigan avatar Jan 25 '22 13:01 kenfinnigan

I believe that the bridge is still needed as there will be projects that need to make use of both facades and Micrometer is already more established, especially in Spring Boot applications. But I think that this PR draft specifically took a naive approach which won't work for a proper bridge, so I'd be fine closing this PR as long as an issue remains open to explore this space.

HaloFour avatar Jan 25 '22 14:01 HaloFour

@kenfinnigan Since this is bridging the OTel Metrics API to the Micrometer API, I guess this would be useful for those users who want to use the OTel Metrics API but also want to use a backend that is not supported by OTel but supported by Micrometer.

The OTel registry/OTLP support in Micrometer I guess is the other way: people want to use the Micrometer API but they also want to use OTLP (fyi: we are planning to add OTLP support in our next feature release).

jonatan-ivanov avatar Jan 25 '22 18:01 jonatan-ivanov

Sorry I had forgotten that this is the reverse direction. Though I tend to agree with @kenfinnigan that there probably wouldn't be that much usage of this, and it is a fairly complex beast. If someone wants to continue with this PR we could still consider it but maybe it's ok to go ahead and close for now.

fyi: we are planning to add OTLP support in our next feature release

@jonatan-ivanov @shakuzen Just checking whether this is still needed given we have the OTel API MeterRegistry now? I guess the use cases are the same, but the OTel API version will have more features (e.g., integrate with other OTel instrumentation, especially tracing to get exemplars) and don't know of any drawback though there may be.

anuraaga avatar Jan 26 '22 05:01 anuraaga

@HaloFour is this replaced by https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/micrometer-meter-provider?

trask avatar Oct 11 '22 20:10 trask

Already implemented via #328.

HaloFour avatar Oct 14 '22 11:10 HaloFour