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

The request-scoped WebClient doesn't use the provided logger #1255

Open
dirleyrls-kake opened this issue Feb 28, 2025 · 2 comments
Open

The request-scoped WebClient doesn't use the provided logger #1255

dirleyrls-kake opened this issue Feb 28, 2025 · 2 comments

Comments

@dirleyrls-kake
Copy link

dirleyrls-kake commented Feb 28, 2025

Bolt is creating a WebClient instance for each request its handling here:

client_per_request: WebClient = WebClient(

It does not pass the logger param.

This means that all requests that are logged by that client won't use the logger provided to the App.

@WilliamBergamin
Copy link
Contributor

Hi @dirleyrls-kake thanks for bringing this up 💯

The line above the initialization of client_per_request we assign the Bolt app logger to the context of the request, from my perspective it makes sense to have a logger for Bolt and another for the WebClient since they are separate libraries 🤔 (slack-bolt, slack-sdk), what would be you expected behavior and why?

@dirleyrls-kake
Copy link
Author

dirleyrls-kake commented Mar 6, 2025

@WilliamBergamin , thanks for the reply.

You are right they are separate libraries, but this particular WebClient is an internal resource created & owned by Slack Bolt. If I configure a custom logger while setting up Slack Bolt, I expect this custom logger to be propagated to every resource that Slack Bolt creates internally.

In my particular use-case, I want to customize all Slack-related loggers to include a prefix ([slack]). This expectation extends to the logger used by the WebClient too, since its an internal resource.

I searched the docs for a way to achieve this but found none. I noticed in some places Bolt tries to propagate the logger, eg.:

self._client = create_web_client(logger=self.logger)
and
self._client = create_web_client(
.

Currently I had to overload some private method to customize this logger:

class LoggerRespectingBoltApp(App):
    def _init_context(self, req: BoltRequest):
        super()._init_context(req)
        req.context["client"]._logger = logger

If you don't want to propagate the logger by default could you at least provide a public API and some documentation about how to do it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants