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

Kotlin-specific Observation API #4823

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ilya40umov
Copy link

@ilya40umov ilya40umov commented Mar 2, 2024

This PR introduces a couple of extension functions on Observation to help using it from Kotlin code.
It's an alternative version of the following PR: #4772, which would introduce the same API, but on ObservationRegistry-level.

  • Observation.observeAndGet allows to observe a non-suspending block of code:
    • this method is analogous to Observation.observe, but accepts a block of code instead of expecting a Java Supplier
    • this method will work with both nullable and non-nullable generic type (while usage of Supplier makes Kotlin compiler think the result of the nested block is always nullable)
  • Observation.observeAndAwait allows to observe a suspending block of code:
    • this method is again similar to Observation.observe, but will accept a suspending block of code
    • by using openScope().use { observationRegistry.asContextElement() } it manages to create an instance of KotlinObservationContextElement with the new observation captured as "current"

gh-4754

@ilya40umov
Copy link
Author

Hm. Looks like some unrelated tests are failing MongoMetricsCommandListenerTest > shouldCreateFailedCommandMetricWithCustomSettings() . 🤔

@ilya40umov ilya40umov force-pushed the feature/observation-kotlin-api-v2 branch from d100773 to d9c279c Compare March 4, 2024 20:15
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.

None yet

1 participant