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

Non-existent service "sentry.client" #178

Closed
qdequippe opened this issue Jan 8, 2019 · 3 comments
Closed

Non-existent service "sentry.client" #178

qdequippe opened this issue Jan 8, 2019 · 3 comments

Comments

@qdequippe
Copy link

Hi,

I would like to set an event subscriber to add context like this:

<?php

namespace AppBundle\Sentry;

use Sentry\SentryBundle\Event\SentryUserContextEvent;
use Sentry\SentryBundle\SentrySymfonyEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class AddCommunityContextSubscriber implements EventSubscriberInterface
{
    /**
     * @var \Raven_Client
     */
    protected $client;

    public function __construct(\Raven_Client $client)
    {
        $this->client = $client;
    }

    public static function getSubscribedEvents()
    {
        return array(
            SentrySymfonyEvents::SET_USER_CONTEXT => 'onSetUserContext'
        );
    }

    public function onSetUserContext(SentryUserContextEvent $event)
    {
        ...
        $this->client->user_context([
                ...
        ]);
        
    }
}

But I'm facing an issue The service "AppBundle\Sentry\AddCommunityContextSubscriber" has a dependency on a non-existent service "sentry.client"
I tried several configurations but none worked.

# config1
AppBundle\Sentry\AddCommunityContextSubscriber:
     arguments:
          $client: '@sentry.client'
# config 2
services:
    Sentry\SentryBundle\SentrySymfonyClient: '@sentry.client'


class AddCommunityContextSubscriber implements EventSubscriberInterface
{
    protected $client;

    public function __construct(SentrySymfonyClient $client)
    {
        $this->client = $client;
    }

I checked #158 but without sucesss too.
My symfony version is 3.4 and I am using the latest version of this bundle (2.2.0).

@Jean85
Copy link
Collaborator

Jean85 commented Jan 8, 2019

The problem may arise from the fact that the client is present only when the bundle is present. If you have included the bundle only in the prod environment, that's where you're having the issue.

You either have to enable the bundle in dev too (but maybe disable the DSN) or include your listener only in the same envs.

@pradeepb6
Copy link

Hi, I am getting the same error with latest sentry version (3.3) and Symfony version 5.0.

I have below code in bundles.php

Sentry\SentryBundle\SentryBundle::class => ['all' => true],

And in Services.yaml

$sentryClient: '@sentry.client'

error is a non-existent service "sentry.client". Any idea?

@kowalk
Copy link

kowalk commented Oct 2, 2020

@pradeepb6 just use Sentry\ClientInterface

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