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

How to setup logging for sentry/sentry? #370

Closed
yourithielen opened this issue Sep 18, 2020 · 12 comments
Closed

How to setup logging for sentry/sentry? #370

yourithielen opened this issue Sep 18, 2020 · 12 comments

Comments

@yourithielen
Copy link

How do I setup sentry/sentry logging? I've had some issues sending messages to Sentry (HTTP Error 413 Payload Too Large) but could not find this anywhere in my logs.

I found out that Sentry\Transport\HttpTransport uses a Psr\Log\NullLogger. I'm not using autowiring.

What value should I pass to sentry.options.logger? I've tried a few but none of them work.

@yourithielen
Copy link
Author

Had a look at the inner workings and it seems the current version is not compatible with getsentry/sentry-php#989. Thoughts?

@yourithielen
Copy link
Author

yourithielen commented Sep 18, 2020

For now I fixed it like this in services.yaml:

    Sentry\ClientBuilderInterface:
      class: Sentry\ClientBuilder
      public: false
      arguments:
        - '@Sentry\Options'
      calls:
        - setLogger: ['@logger']

@Jean85 Jean85 added the support label Sep 21, 2020
@Jean85
Copy link
Collaborator

Jean85 commented Sep 21, 2020

That's the correct way to do it. getsentry/sentry-php#989 is for the 3.0 release, so that's way you can't use it yet.

@soullivaneuh
Copy link

In that case, what is the goal of sentry.options.logger?

It's quite hacky to override a vendor service.

@soullivaneuh
Copy link

@yourithielen Here is a less intrusive way using the kernel with CompilerPassInterface:

namespace App;

use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

final class Kernel extends BaseKernel implements CompilerPassInterface
{
    use MicroKernelTrait;

    public function process(ContainerBuilder $container): void
    {
        $container->getDefinition(\Sentry\ClientBuilderInterface::class)->addMethodCall(
            'setLogger',
            [new Reference('logger')]
        );
    }
}

@ste93cry
Copy link
Collaborator

In that case, what is the goal of sentry.options.logger?

That option sets the logger option of the SDK (and fills the field with the same name in the event), it's not for setting the PSR-3 logger 😉

@soullivaneuh
Copy link

@Jean85 Since the v4 of this bundle, the ClientBuilderInterfaceservice does not exist anymore.

What is the correct way to set a logger on the sentry client now? Do we have a documentation about this?

@Jean85
Copy link
Collaborator

Jean85 commented Jun 28, 2021

There's a full upgrade doc here: https://github.com/getsentry/sentry-symfony/blob/master/UPGRADE-4.0.md

Keep in mind that some stuff may belong to the underlying SDK, which has its upgrade document here: https://github.com/getsentry/sentry-php/blob/master/UPGRADE-3.0.md

@soullivaneuh
Copy link

@Jean85 Yes, I did read this documentation first, it says:

Removed the Sentry\ClientBuilderInterface and Sentry\Options services.

But there is not indication about the migration to do, especially for this not documented case.
Currently, I have not clue about how to keep our custom logger on the Sentry client.

Am I missing something?

@ste93cry
Copy link
Collaborator

Looking at the code I think there is no easy way, since as you said the builder is not anymore registered as a service mainly because it was not stateless (a mistake) and therefore an instance is not really re-usable to create different clients. What we can definitely do however, and maybe also the best thing, is to expose an option sentry.logger which points to a service and is set on the builder service when building the container. WDYT?

@soullivaneuh
Copy link

soullivaneuh commented Jun 28, 2021

@ste93cry You may. However, thanks to the Symfony's autowiring system to automatically bind the LoggerInterface if available.

Ref: https://symfony.com/doc/current/service_container/autowiring.html

Both of them allow two advantages:

  1. Ready to use sentry client with configured logging, that will cover 99% of the needs.
  2. The possibility to change the logger we want to plug on the sentry client.

My two cents. 👍

@ste93cry
Copy link
Collaborator

Using the main logger is not something recommended, because it may create a loop if you use Monolog to report errors to Sentry rather than relying on the custom error handler, which is something we absolutely want to throw away in the next major because it goes into conflict with the built-in one of Symfony.

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

4 participants