-
Notifications
You must be signed in to change notification settings - Fork 311
Provide smoother usage of Observabilty. #1322
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
Conversation
| CommandLineRunner initData(EmployeeRepository repository, ObservationRegistry registry) { // <1> | ||
| Observation observation = Observation.start("init-database", registry); // <2> | ||
| try (Observation.Scope scope = observation.openScope()) { // <3> | ||
| return args -> { | ||
| repository.save(new Employee("1", "Frodo", "ring bearer")); | ||
| repository.save(new Employee("2", "Bilbo", "burglar")); | ||
| }; | ||
| } catch (Exception e) { | ||
| observation.error(e); // <4> | ||
| throw e; | ||
| } finally { | ||
| observation.stop(); // <5> | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think wrapping inside of the lambda is more appropriate to capture the observation for this operations.
CommandLineRunner initData(EmployeeRepository repository, ObservationRegistry registry) { // <1>
return args -> {
Observation observation = Observation.start("init-database", registry); // <2>
try (Observation.Scope scope = observation.openScope()) { // <3>
repository.save(new Employee("1", "Frodo", "ring bearer"));
repository.save(new Employee("2", "Bilbo", "burglar"));
} catch (Exception e) {
observation.error(e); // <4>
throw e;
} finally {
observation.stop(); // <5>
}
};There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW why not just call Observation.createNotStarted("init-database"), registry).observe(() -> { repository.save(.....); } ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
…Cassandra. Resolves #1321.
333fdab to
ae6303f
Compare
|
That's merged and polished now. |
CC @marcingrzejszczak
This one is MUCH easier to use. I also updated the documentation to illustrate its usage.