-
-
Notifications
You must be signed in to change notification settings - Fork 734
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
Added MDC #557
Added MDC #557
Conversation
contextMap.put("jda.shard.id", String.valueOf(shardInfo.getShardId())); | ||
contextMap.put("jda.shard.total", String.valueOf(shardInfo.getShardTotal())); | ||
} | ||
MDC.setContextMap(contextMap); |
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.
This nukes any MDC values that client code might have set 😢
In your own threads I don't mind manually managing the contextMap, but this is rather destructive
Since buildAsync isn't enough, you'd have to invoke buildAsync asynchronously and explain why that's done that way and hope no one refactors it away
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.
The client is able to control the map
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 understand your concern though. I could make use of MDC.MDCClosable and just put all the values in the existing context for the build process
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.
This seems like a fair alternative
// set MDC metadata for build thread
Map<String, String> previousContext = MDC.getCopyOfContextMap();
contextMap.forEach(MDC::put);
// init code
MDC.setContextMap(previousContext);
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.
As long as it's addressed I'm fine with it 👍
# Conflicts: # src/main/java/net/dv8tion/jda/core/JDABuilder.java # src/main/java/net/dv8tion/jda/core/entities/impl/JDAImpl.java
daedc93
to
c793ada
Compare
# Conflicts: # src/main/java/net/dv8tion/jda/bot/sharding/DefaultShardManager.java
8d21355
to
1cf8b40
Compare
Pull Request Etiquette
There are several guidelines you should follow in order for your
Pull Request to be merged.
Template
Pull Request
Using MDC we are able to categorize our logging events per shard/jda instance.
You can set a custom context map by using
JDABuilder.setContextMap(ConcurrentMap<String, String>)
which will be set in all JDA controlled threads.Additionally I added a new method to the IAudioSendSystem to set the context in custom implementations. This method is declared as default due to backward compatibility but is implemented in the DefaultSendSystem.
Using logback and log4j MDC can be used to filter by shard:
Logback
Log4j