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

Abstraction for instrumentating with a Timer or Observation (optionally) #3357

Merged
merged 3 commits into from Aug 19, 2022

Conversation

shakuzen
Copy link
Member

We have a lot of existing instrumentations with Timer that are good candidates to be rewritten with the Observation API for added extensibility. However, we cannot break compatibility for existing users by requiring an ObservationRegistry for each instrumentation. We will want to add an option to configure an ObservationRegistry on the builder for the instrumentation or as an additional constructor if there isn't a builder. Instrumentation should still work as before without providing an ObservationRegistry. This can be handled in each instrumentation, but this added class ObservationOrTimerCompatibleInstrumentation is intended to make it easier to support this case where instrumentation may be done with a Timer or Observation depending on whether an ObservationRegistry is available. By having a common abstraction for this, we can hopefully make supporting Observation in our existing instrumentations easier, and also avoid adding overhead to instrumentation by avoiding instantiating things for Observation when a Timer is used (and the opposite situation).

…tion (optionally)

We have a lot of existing instrumentations with Timer that are good candidates to be rewritten with the Observation API for added extensibility. However, we cannot break compatibility for existing users by requiring an ObservationRegistry for each instrumentation. We will want to add an option to configure an ObservationRegistry on the builder for the instrumentation or as an additional constructor if there isn't a builder. Instrumentation should still work as before without providing an ObservationRegistry. This can be handled in each instrumentation, but this added class ObservationOrTimerCompatibleInstrumentation is intended to make it easier to support this case where instrumentation may be done with a Timer or Observation depending on whether an ObservationRegistry is available. By having a common abstraction for this, we can hopefully make supporting Observation in our existing instrumentations easier, and also avoid adding overhead to instrumentation by avoiding instantiating things for Observation when a Timer is used (and the opposite situation).
@shakuzen shakuzen added enhancement A general enhancement module: micrometer-core An issue that is related to our core module labels Aug 18, 2022
@shakuzen shakuzen added this to the 1.10.0-M5 milestone Aug 18, 2022
* @param <RES> type of the response
*/
public <RES> void setResponse(RES response) {
if (observationRegistry.isNoop() || !(context instanceof RequestReplySenderContext)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about RequestReplyReceiverContext ? We have the response there too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. I had only tried this with the Apache HTTP client instrumentation, which is why I probably only thought of this. I expect we'll catch other things and add to it as we use this in more places.
Do you think it makes sense to extract the response-related methods to an interface so we could check for that here and just cast to that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, that's a good idea

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll follow-up with this in a separate pull request. I've left a TODO comment for now.

@shakuzen shakuzen changed the title Abstraction for supporting instrumentation with a Timer or Observation (optionally) Abstraction for instrumentating with a Timer or Observation (optionally) Aug 19, 2022
@shakuzen shakuzen merged commit cfc886c into micrometer-metrics:main Aug 19, 2022
@shakuzen shakuzen deleted the ob-or-t branch August 19, 2022 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A general enhancement module: micrometer-core An issue that is related to our core module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants