[GH-ISSUE #1931] Curl error when leaving webhookurl empty #831

Closed
opened 2026-03-04 03:01:09 +03:00 by kerem · 2 comments
Owner

Originally created by @Jalliuz on GitHub (Dec 20, 2024).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1931

We have a Monolog/Slack "webhook" implementation in our project. It works fine except when you don't have a webhook url

In my local environment I don't immediately have a Slack webhookurl. These are managed by Slack admins of our company so I can't just create one myself.

But the project requires one in the monolog config.

monolog:
    channels:
        - slack_error
    handlers:
        slack_error:
            type: slackwebhook
            webhook_url: '%env(SLACK_ERROR_WEBHOOK_URL)%'
            channel: '%env(SLACK_ERROR_CHANNEL)%'
            bot_name: '%env(SLACK_BOT_NAME)%'
            icon_emoji: '%env(SLACK_EMOJI)%'
            level: '%env(SLACK_ERROR_LEVEL)%'
            include_extra: true

If I leave it empty, my whole project crashes with a curl error in Handler/SlackWebhookHandler.php line 110

Is there an option to disable it?

What I currently did is setting the level
level: emergency
This is the highest level and I guess it currently never gets thrown.

Solution:
A solution for this bundle can be that if the webhookurl is left empty, no curl will get called

Another solution is adding an option
enabled: false

So te developer can decide if its enabled in his environment or not

Originally created by @Jalliuz on GitHub (Dec 20, 2024). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1931 We have a Monolog/Slack "webhook" implementation in our project. It works fine except when you don't have a webhook url In my local environment I don't immediately have a Slack webhookurl. These are managed by Slack admins of our company so I can't just create one myself. But the project requires one in the monolog config. ```` monolog: channels: - slack_error handlers: slack_error: type: slackwebhook webhook_url: '%env(SLACK_ERROR_WEBHOOK_URL)%' channel: '%env(SLACK_ERROR_CHANNEL)%' bot_name: '%env(SLACK_BOT_NAME)%' icon_emoji: '%env(SLACK_EMOJI)%' level: '%env(SLACK_ERROR_LEVEL)%' include_extra: true ```` If I leave it empty, my whole project crashes with a curl error in Handler/SlackWebhookHandler.php line 110 Is there an option to disable it? What I currently did is setting the level `level: emergency` This is the highest level and I guess it currently never gets thrown. Solution: A solution for this bundle can be that if the webhookurl is left empty, no curl will get called Another solution is adding an option `enabled: false` So te developer can decide if its enabled in his environment or not
kerem 2026-03-04 03:01:09 +03:00
  • closed this issue
  • added the
    Bug
    label
Author
Owner

@davidheunis commented on GitHub (Dec 20, 2024):

To address your issue, you're correct that the root cause of the crash stems from the fact that the webhook_url is required by the SlackWebhookHandler in Monolog. If it's left empty or not properly configured in your environment, the handler attempts to send a request, leading to a curl error. There are a few potential solutions to make this more flexible and avoid crashes in environments where a valid Slack webhook URL is not available.

Posible Solution:
Use Environment Variable Default Value. If the environment variable is not set or left empty, you could set a default value to prevent Monolog from trying to send data. You could modify the webhook_url in the Monolog configuration file to check if the environment variable exists and fallback to a default empty value or null.

monolog:
    channels:
        - slack_error
    handlers:
        slack_error:
            type: slackwebhook
            webhook_url: '%env(SLACK_ERROR_WEBHOOK_URL)%' # Ensure this is set or falls back to a blank URL.
            channel: '%env(SLACK_ERROR_CHANNEL)%'
            bot_name: '%env(SLACK_BOT_NAME)%'
            icon_emoji: '%env(SLACK_EMOJI)%'
            level: '%env(SLACK_ERROR_LEVEL)%'
            include_extra: true
<!-- gh-comment-id:2556821664 --> @davidheunis commented on GitHub (Dec 20, 2024): To address your issue, you're correct that the root cause of the crash stems from the fact that the webhook_url is required by the SlackWebhookHandler in Monolog. If it's left empty or not properly configured in your environment, the handler attempts to send a request, leading to a curl error. There are a few potential solutions to make this more flexible and avoid crashes in environments where a valid Slack webhook URL is not available. Posible Solution: Use Environment Variable Default Value. If the environment variable is not set or left empty, you could set a default value to prevent Monolog from trying to send data. You could modify the webhook_url in the Monolog configuration file to check if the environment variable exists and fallback to a default empty value or null. ``` monolog: channels: - slack_error handlers: slack_error: type: slackwebhook webhook_url: '%env(SLACK_ERROR_WEBHOOK_URL)%' # Ensure this is set or falls back to a blank URL. channel: '%env(SLACK_ERROR_CHANNEL)%' bot_name: '%env(SLACK_BOT_NAME)%' icon_emoji: '%env(SLACK_EMOJI)%' level: '%env(SLACK_ERROR_LEVEL)%' include_extra: true ```
Author
Owner

@Seldaek commented on GitHub (Mar 16, 2025):

Sorry but I don't really think this is a use case that is broad enough to justify adding here. You could extend the class and override write() to just return early like if ($this->getWebhookUrl() === '') { return; } parent::write($record); for example.

Adding an enabled flag makes no sense to me to just add it for slack, and I don't really want to add this all over the place, the way to not enable something is to not configure it in theory.

And silently not sending if the webhook url is empty sets a bad precedent too that misconfigured handlers will just silently appear to work but won't actually log anything. Currently we have the exact opposite approach whereas misconfigurations fail loudly to ensure that logging works.

<!-- gh-comment-id:2727393753 --> @Seldaek commented on GitHub (Mar 16, 2025): Sorry but I don't really think this is a use case that is broad enough to justify adding here. You could extend the class and override `write()` to just return early like `if ($this->getWebhookUrl() === '') { return; } parent::write($record);` for example. Adding an enabled flag makes no sense to me to just add it for slack, and I don't really want to add this all over the place, the way to not enable something is to not configure it in theory. And silently not sending if the webhook url is empty sets a bad precedent too that misconfigured handlers will just silently appear to work but won't actually log anything. Currently we have the exact opposite approach whereas misconfigurations fail loudly to ensure that logging works.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#831
No description provided.