[GH-ISSUE #909] New SlackWebookHandler and long context/extras problem #363

Closed
opened 2026-03-04 02:14:25 +03:00 by kerem · 6 comments
Owner

Originally created by @mirfilip on GitHub (Jan 5, 2017).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/909

Hi,
I just got around to test the new cool SlackWebhookHandler. It works nice and fixes problems I had before, there is however one annoyance I found. @an1zhegorodov I didn't want to continue discussion in your original PR though.

I use attachments and include context and extra data. Depending on the length of the context, it's either formatted well or cut:

Looking good:

$nestedArray = [];
for ($i = 0; $i < 27; $i++) {
    $nestedArray["foo $i"] = str_repeat($i, $i * 2);
}
$context = ['nested' => $nestedArray];
$this->logger->warning('Warning test', $context);

the whole nested array is displayed in code block (using "```").

If I, however, make it bigger:

$nestedArray = [];
for ($i = 0; $i < 30; $i++) {
    $nestedArray["foo $i"] = str_repeat($i, $i * 2);
}
$context = ['nested' => $nestedArray];
$this->logger->warning('Warning test', $context);

The context output is truncated and the whole code block is broken. Below, it's how it looks like at the beginning of the msg (I don't include full msg cause it's big):
slack_monolog_handler_big_context

You can see at the beginning that there is no closing "```" of code block (probably because truncation). I don't have time to debug this now, it could be as well a limitation of Slack Webhook formatting.

What I'm trying to do:
I want to include a stacktrace (not based on exception) in a context so that it's prettified and displayed in code block on Slack. The NormalizerFormatter and "stringification" get the job done, but only for small contexts.

Originally created by @mirfilip on GitHub (Jan 5, 2017). Original GitHub issue: https://github.com/Seldaek/monolog/issues/909 Hi, I just got around to test the [new cool SlackWebhookHandler](https://github.com/Seldaek/monolog/pull/894). It works nice and fixes problems I had before, there is however one annoyance I found. @an1zhegorodov I didn't want to continue discussion in your original PR though. I use attachments and include context and extra data. Depending on the length of the context, it's either formatted well or cut: ### Looking good: ```php $nestedArray = []; for ($i = 0; $i < 27; $i++) { $nestedArray["foo $i"] = str_repeat($i, $i * 2); } $context = ['nested' => $nestedArray]; $this->logger->warning('Warning test', $context); ``` the whole nested array is displayed in code block (using "```"). ### If I, however, make it bigger: ```php $nestedArray = []; for ($i = 0; $i < 30; $i++) { $nestedArray["foo $i"] = str_repeat($i, $i * 2); } $context = ['nested' => $nestedArray]; $this->logger->warning('Warning test', $context); ``` The context output is truncated and the whole code block is broken. Below, it's how it looks like at the beginning of the msg (I don't include full msg cause it's big): ![slack_monolog_handler_big_context](https://cloud.githubusercontent.com/assets/1812341/21681208/8d493788-d34e-11e6-8d2a-192a89bc27dd.png) You can see at the beginning that there is no closing "```" of code block (probably because truncation). I don't have time to debug this now, it could be as well a limitation of Slack Webhook formatting. What I'm trying to do: I want to include a stacktrace (not based on exception) in a context so that it's prettified and displayed in code block on Slack. The `NormalizerFormatter` and "stringification" get the job done, but only for small contexts.
kerem 2026-03-04 02:14:25 +03:00
  • closed this issue
  • added the
    Bug
    label
Author
Owner

@mintobit commented on GitHub (Jan 7, 2017):

After debugging this, I can tell there is limitation somewhere around 2000 symbols for each attachment imposed by slack itself. Any ideas how to handle this?

<!-- gh-comment-id:271090032 --> @mintobit commented on GitHub (Jan 7, 2017): After debugging this, I can tell there is limitation somewhere around 2000 symbols for each attachment imposed by slack itself. Any ideas how to handle this?
Author
Owner

@acasademont commented on GitHub (Jan 23, 2017):

AFAIK there are no limits when using the normal message field instead of attachments, which is the weirdest thing ever...

<!-- gh-comment-id:274549943 --> @acasademont commented on GitHub (Jan 23, 2017): AFAIK there are no limits when using the normal `message` field instead of attachments, which is the weirdest thing ever...
Author
Owner

@Seldaek commented on GitHub (Mar 12, 2017):

Maybe you could truncate the output by hand to make sure the backticks is present at the end, or at least report it to slack so that they fix their truncation to not rip apart a code block..

<!-- gh-comment-id:285954665 --> @Seldaek commented on GitHub (Mar 12, 2017): Maybe you could truncate the output by hand to make sure the backticks is present at the end, or at least report it to slack so that they fix their truncation to not rip apart a code block..
Author
Owner

@mirfilip commented on GitHub (Mar 12, 2017):

@Seldaek I hope by you, you mean me - the user of the library. Then - yes, I could, I already do that since I found out about the limitation.

I didn't have time to look into it but I'll get around to reporting it someday ;)

<!-- gh-comment-id:285980848 --> @mirfilip commented on GitHub (Mar 12, 2017): @Seldaek I hope by you, you mean me - the user of the library. Then - yes, I could, I already do that since I found out about the limitation. I didn't have time to look into it but I'll get around to reporting it someday ;)
Author
Owner

@Seldaek commented on GitHub (Mar 13, 2017):

@mirfilip By you I mean anyone running into this issue that feels like fixing it in monolog, or in slack :)

<!-- gh-comment-id:286029054 --> @Seldaek commented on GitHub (Mar 13, 2017): @mirfilip By you I mean anyone running into this issue that feels like fixing it in monolog, or in slack :)
Author
Owner

@gmponos commented on GitHub (Nov 29, 2018):

Because I had to deal with the same issue I have created this package. You can find it also in wiki of monolog.

<!-- gh-comment-id:443015243 --> @gmponos commented on GitHub (Nov 29, 2018): Because I had to deal with the same issue I have created [this](https://github.com/gmponos/monolog-slack) package. You can find it also in wiki of monolog.
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#363
No description provided.