Skip to content

Conversation

@dereuromark
Copy link
Owner

Summary

This PR adds events compatible with lordsimal/cakephp-sentry for queue monitoring and tracing, as proposed in LordSimal/cakephp-sentry#43.

Instead of including Sentry-specific code directly in the queue plugin (as in #449), this approach dispatches generic events that the Sentry plugin can listen to:

  • CakeSentry.Queue.enqueue: Fired when a job is added to the queue (producer side)
  • CakeSentry.Queue.beforeExecute: Fired when a worker begins processing a job (consumer side)
  • CakeSentry.Queue.afterExecute: Fired when a job finishes (success or failure)

This enables integration with Sentry's queue monitoring without requiring the queue plugin to depend on the Sentry SDK.

Trace Propagation

For distributed tracing, users can add Sentry trace headers to job data when creating jobs:

$data = ['your_data' => 'here'];

if (class_exists(\Sentry\SentrySdk::class)) {
    $data['_sentry_trace'] = \Sentry\getTraceparent();
    $data['_sentry_baggage'] = \Sentry\getBaggage();
}

$queuedJobsTable->createJob('MyTask', $data);

The queue plugin will pass these headers to the beforeExecute event for trace continuation.

Related Issues

Test plan

  • Added test for CakeSentry.Queue.enqueue event
  • Added test for CakeSentry.Queue.beforeExecute event
  • Added test for CakeSentry.Queue.afterExecute success event
  • Added test for CakeSentry.Queue.afterExecute failure event
  • All 131 tests pass
  • Documentation updated in docs/sections/misc.md

Dispatch events compatible with lordsimal/cakephp-sentry:
- CakeSentry.Queue.enqueue: when job is added to queue
- CakeSentry.Queue.beforeExecute: when job processing starts
- CakeSentry.Queue.afterExecute: when job completes or fails

This enables queue monitoring via Sentry without requiring
the queue plugin to depend on Sentry SDK directly.
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.65%. Comparing base (e447805) to head (5ec7e88).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #452      +/-   ##
============================================
+ Coverage     73.28%   73.65%   +0.37%     
- Complexity      777      778       +1     
============================================
  Files            41       41              
  Lines          2691     2725      +34     
============================================
+ Hits           1972     2007      +35     
+ Misses          719      718       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dereuromark
Copy link
Owner Author

Closing in favor of #453

@dereuromark dereuromark deleted the feature/cakesentry-queue-events branch December 28, 2025 16:10
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

Successfully merging this pull request may close these issues.

3 participants