diff --git a/src/Providers/JobServiceProvider.php b/src/Providers/JobServiceProvider.php index b4c7b99..4cf79d4 100644 --- a/src/Providers/JobServiceProvider.php +++ b/src/Providers/JobServiceProvider.php @@ -33,19 +33,15 @@ public function boot() }); $this->app['events']->listen(JobProcessing::class, function (JobProcessing $event) { - // Start a transaction id there's not one // todo: add "&& Filters::isApprovedJob($event->job)" + + // Start a transaction id there's not one if(!$this->app['inspector']->isRecording()){ $this->app['inspector']->startTransaction($event->job->resolveName()); + } else { + // Open a segment if a transaction already exists + $this->initializeSegment($event->job); } - - $segment = $this->app['inspector'] - ->startSegment('job') - ->setLabel($event->job->resolveName()) - ->setContext($event->job->payload()); - - // Jot down the job with a unique ID - $this->segments[$this->getJobId($event->job)] = $segment; }); $this->app['events']->listen(JobProcessed::class, function (JobProcessed $event) { @@ -61,6 +57,17 @@ public function boot() }); } + protected function initializeSegment(Job $job) + { + $segment = $this->app['inspector'] + ->startSegment('job') + ->setLabel($job->resolveName()) + ->setContext($job->payload()); + + // Jot down the job with a unique ID + $this->segments[$this->getJobId($job)] = $segment; + } + /** * Report job execution to Inspector. *