-
Notifications
You must be signed in to change notification settings - Fork 3
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
Improve/mdc #179
Improve/mdc #179
Conversation
I wonder if there's some sort of best practice for adding stuff to MDC from libraries. Maybe namespacing? |
One way to improve this is to add some lifecycle hooks or interceptors to the subscription, so that the application can make the MDC calls in stead of the library code. |
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.
Calling the updateInterceptor
in the update
method does not support the intended use case to have a the system_id logged in case of exceptions, as exception logging occurs after update()
was called and hence the externally set MDC is cleared already.
Possible solution could be to add beforeUpdate
/afterUpdate
as lifecycle methods to the GBFSSubscription classes and let them be called by the GBFSSubscriptionManager before/after calling update, e.g. like this
public void update() {
subscriptions
.values()
.parallelStream()
.forEach(subscription ->
Optional
.ofNullable(customThreadPool)
.orElse(ForkJoinPool.commonPool())
.execute(() -> this.update(subscription))
);
}
public void update(GbfsSubscription subscription) {
try {
subscription.beforeUpdate();
subscription.update();
} catch (RuntimeException e) {
LOG.error("Error updating subscription", e);
} finally {
subscription.afterUpdate();
}
}
fix: log possible exceptions before afterUpdate call
Quality Gate passedIssues Measures |
Related to entur/lamassu#250
This adds possibility to provide interceptor for subscription updates. Example implementation from application code:
Which in turn enables systemId to be logged from log statements within this library by configuring logback as this example shows: