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

Add an easy cron integration #757

Closed
vasilvestre opened this issue Aug 29, 2023 · 6 comments
Closed

Add an easy cron integration #757

vasilvestre opened this issue Aug 29, 2023 · 6 comments

Comments

@vasilvestre
Copy link

Problem Statement

Everywhere you use the CRON feature, you have to specify which environment and release you use. The initialized sentry SDK is not reused

Solution Brainstorm

Add the capacity to reuse configured SDK maybe with an helper ?

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Aug 29, 2023
@cleptric
Copy link
Member

We made the process of reporting check-ins simpler in https://github.com/getsentry/sentry-php/releases/tag/3.21.0

See #719 for more context on this.

@vasilvestre
Copy link
Author

We made the process of reporting check-ins simpler in https://github.com/getsentry/sentry-php/releases/tag/3.21.0

See #719 for more context on this.

It doesn't help for the environment thing, in my case it always log in production when I'm in environment "dev"

@cleptric cleptric reopened this Aug 31, 2023
@cleptric
Copy link
Member

How does your config/packages/sentry.yaml file look like?

@vasilvestre
Copy link
Author

How does your config/packages/sentry.yaml file look like?

parameters:
    env(SENTRY_ENV): undefined
    env(SENTRY_DSN):
    env(VERSION): undefined
    env(SENTRY_TRACE_SAMPLE_RATE): '0.1'

sentry:
    dsn: '%env(SENTRY_DSN)%'
    options:
        environment: '%env(SENTRY_ENV)%'
        traces_sample_rate: '%env(float:SENTRY_TRACE_SAMPLE_RATE)%'
        integrations:
            - 'Sentry\Integration\IgnoreErrorsIntegration'

The SENTRY_ENV is set to "prod", "staging", "preprod" or "dev" depending of the environment. When I ran my test with SENTRY_ENV set to "dev", production was the environment reported in Sentry cron.

@getsantry getsantry bot moved this from Waiting for: Community to Waiting for: Product Owner in GitHub Issues with 👀 Sep 1, 2023
@cleptric
Copy link
Member

cleptric commented Sep 1, 2023

I'm unable to reproduce the issue you're seeing.

\Sentry\captureCheckIn(
    slug: 'my-cron-job',
    status: \Sentry\CheckInStatus::ok(),
);

Screenshot 2023-09-01 at 11 00 16

Maybe check the version you have installed for our underlying PHP SDK (sentry/sentry).
To be able to use captureCheckIn(), you'll need 3.21.0.

You can update the underlying SDK by running composer update sentry/sentry-symfony -W.

@vasilvestre
Copy link
Author

vasilvestre commented Sep 1, 2023

Alright, I had to update my sdk and use the captureCheckIn and it's working great now.

Thank you :)

I still hope that there will be a trait or some kind of helper for Commands. Here's my code for future reference :

    private function initSentry(): ?string
    {
        return captureCheckIn(
            slug: 'cancel-unpaid-order',
            status: CheckInStatus::inProgress()
        );
    }

    private function notifySentryForSuccess(string $checkInId): void
    {
        captureCheckIn(
            slug: 'cancel-unpaid-order',
            status: CheckInStatus::ok(),
            checkInId: $checkInId,
        );
    }

    private function notifySentryForError(string $checkInId): void
    {
        captureCheckIn(
            slug: 'cancel-unpaid-order',
            status: CheckInStatus::error(),
            checkInId: $checkInId,
        );
    }
    ```

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

No branches or pull requests

2 participants