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

[Monolog] Handler not including context #870

Closed
apapsch opened this issue Aug 22, 2019 · 3 comments
Closed

[Monolog] Handler not including context #870

apapsch opened this issue Aug 22, 2019 · 3 comments

Comments

@apapsch
Copy link

apapsch commented Aug 22, 2019

We have many log calls that are structured in the suggested way, i.e. context is an array with arbitrary fields:

                    $this->logger->error('Could not find channel of order', [
                        'order_id' => $orderId,
                        'channel_id' => $channelId,
                    ]);

Up until this week, we were still using Sentry 1.10 and the deprecated handler from Monolog upstream. The handler was configured with a LineFormatter and the line format %message% %context% %extra%. Sentry received messages like:

Could not find channel of order {"order_id": "FOO-1", "channel_id": "42"} []

Now we upgraded to Sentry 2.x and switched to the Sentry\Monolog\Handler. The message is now:

Could not find channel of order

The context is missing and also cannot be found under "Additional Data". Looking in the source of the integrated handler, the reasons become clear:

  • l. 49: The Sentry field message ist set using the Monolog field message, which ignores the formatted field set by the LineFormatter.
  • The arbitary context fields are not set in the Sentry scope.

The old behavior with the context added to the message as JSON object was not ideal, because Sentry would have had a hard time automatically merging the issues, resulting in many separate issues that needed manual merging. Therefore I would send a PR that adds the arbitrary context fields to the Sentry scope via setExtra.

@ste93cry
Copy link
Collaborator

This has already been discussed in #848 and #844 and reasons have been explained about why we won't support anymore out-of-the-box blindly setting what is in the context and/or in the extra field in the event. There is a package developed by @B-Galati that can help you by restoring pretty much what was done in 1.x.

@apapsch
Copy link
Author

apapsch commented Aug 22, 2019

Good stuff, I will check it out. Closing then.

@nuryagdym
Copy link

seems like this feature is supported now.

in symfony sentry bundle with following config worked:

monolog:
    handlers:
        sentry:
            type: sentry
            dsn: "%env(SENTRY_DSN)%"
            level: !php/const Monolog\Logger::ERROR
            fill_extra_context: true #<- monolog data can be logged with this flag

for more info you can check Sentry\Monolog\Handler

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

No branches or pull requests

3 participants