Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTel Metrics Micrometer MeterProvider #71

Closed

Conversation

HaloFour
Copy link
Contributor

First pass at implementing a MeterProvider that wraps Micrometer MeterRegistry.

@HaloFour HaloFour force-pushed the micrometer-metricsprovider branch from 229de3c to ad3fd2f Compare August 30, 2021 11:47
@HaloFour HaloFour force-pushed the micrometer-metricsprovider branch from ad3fd2f to f7ef8c9 Compare August 30, 2021 11:49
Copy link
Contributor

@jsuereth jsuereth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things come to mind looking at this:

  • It looks like the async instruments from OTEL may need more machinery to work correctly here.
  • 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.

@Override
public BoundDoubleCounter bind(Attributes attributes) {
Tags tags = TagUtils.attributesToTags(attributes);
Counter counter = factory.get().tags(tags).register(state.meterRegistry());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How expensive is it for OTEL's API to constantly register counters in the hot path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internally Micrometer keeps a map of every instrumented by Meter.Id which is comprised of the name and the tags. We could add a separate map here as I am doing with gauges. But without Attributes implementing hashcode/equals it seems that I can't avoid conversion to Tags prior to looking up the instrument from the map which I presume is probably the most expensive part of this operation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ArrayBackedAttributes looks like it does, but AttibutesMap does not. It seems the latter is only used by SpanBuilder so perhaps it's safe to assume that any attributes passed to these APIs can be used as a key.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AttributesMap is a HashMap so it should be fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but yes, these APIs won't get getting the attributes from the internals of the span, I don't think.

}

@Override
public void buildWithCallback(Consumer<ObservableDoubleMeasurement> callback) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation means the async measurements are recorded ONCE and then never again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads up, that's my misunderstanding of the OTel API. To confirm, callback is then called once per export?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. The idea is that anytime you export, this callback should be called and you synthesize your metrics from it right then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, ok, this might create an interesting chicken/egg scenario. Each invocation of that callback could potentially observe metrics for a different set of attributes/tags that might correspond to instruments that would have to be created in Micrometer.

@HaloFour
Copy link
Contributor Author

HaloFour commented Aug 30, 2021

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.

@jsuereth
Copy link
Contributor

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

@HaloFour
Copy link
Contributor Author

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.

@anuraaga
Copy link
Contributor

anuraaga commented Sep 2, 2021

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.

@HaloFour
Copy link
Contributor Author

HaloFour commented Sep 2, 2021

@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.

@anuraaga
Copy link
Contributor

@mateuszrzeszutek
Copy link
Member

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?

@kenfinnigan
Copy link
Member

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?

@HaloFour
Copy link
Contributor Author

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.

@jonatan-ivanov
Copy link
Member

@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).

@anuraaga
Copy link
Contributor

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.

@trask
Copy link
Member

trask commented Oct 11, 2022

@HaloFour
Copy link
Contributor Author

Already implemented via #328.

@HaloFour HaloFour closed this Oct 14, 2022
@HaloFour HaloFour deleted the micrometer-metricsprovider branch October 14, 2022 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants