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

Client doesn't work with Laravel Queue #30

Open
georgecoca opened this issue Dec 13, 2021 · 5 comments
Open

Client doesn't work with Laravel Queue #30

georgecoca opened this issue Dec 13, 2021 · 5 comments

Comments

@georgecoca
Copy link

georgecoca commented Dec 13, 2021

Hi,

We have this package installed in a Laravel application. The app listens for events for some specific events which are queued and processed in background (through queues). The thing is that when the queued jobs are processed we also submit the events to PostHog, eg:

        PostHog::capture([
            'distinctId' => 'user:1',
            'event' => 'some-event'
        ]);

But we found out that the event is never sent to PostHog. There are no errors, it just does nothing. We tested the same app locally (without queue) and it works as expected. Also we tested making a HTTP request directly to the API through the Guzzle client and it works fine. After some debugging I think there may be some issues with the consumers clients (which by default is lib_curl.), and I guess its related to how __destruct function handles the code within a queued job in Laravel app.

Laravel Version 8.75.0
Queue Jobs are processed with the command php artisan queue:work.

Looking forward to a solution. Thank you.

@georgecoca georgecoca changed the title Client doesn't work on AWS Lambda Client doesn't work with Laravel Queue Dec 13, 2021
@rvanbaalen
Copy link

Are you calling PostHog::init in the queue job as well?

Sounds like PostHog::init wasn't called

@IsraelOrtuno
Copy link

Facing the same problem. I have tested calling PostHog::init in the queued job as well but still didn't work:

        PostHog::init(config()->get('services.posthog.api_key'), [
            'host' => config()->get('services.posthog.host'),
        ]);

        PostHog::capture([
            'distinctId' => $this->user->getKey(),
            'event' => 'user:registered',
            'properties' => [
                'registered_via' => $this->registerdVia,
            ],
        ]);

However it does work when running the job synchronously.

@nwdles
Copy link

nwdles commented Oct 25, 2023

batch_size as optional parameter solved my problem (we don't have 100 events in time, that's why we didn't catch events in PostHog)

@IsraelOrtuno
Copy link

@nwdles could you show an example? I am confused about that parameter. Do yo mean this?

https://posthog.com/docs/api/post-only-endpoints#batch-events

@nwdles
Copy link

nwdles commented Oct 25, 2023

https://posthog.com/docs/api/post-only-endpoints#batch-events

I mean this
Posthog::init(config('posthog.api_key'), ['host' => config('posthog.url'), 'batch_size' => 1]);

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