Skip to content

Commit

Permalink
Merge pull request #10 from worksome/feature/otel-1.x
Browse files Browse the repository at this point in the history
chore(deps): update to OpenTelemetry 1.x
  • Loading branch information
owenvoke authored Nov 14, 2023
2 parents c432065 + c1222a8 commit 7d7d74a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
"require": {
"php": "^8.2",
"illuminate/contracts": "^10.0",
"laravel/horizon": "^5.10",
"open-telemetry/api": "^0.0.17",
"worksome/laravel-telemetry": "^0.3"
"laravel/horizon": "^5.21.3",
"open-telemetry/api": "^1.0",
"worksome/laravel-telemetry": "^0.4"
},
"require-dev": {
"nunomaduro/collision": "^7.0",
"nunomaduro/larastan": "^2.0",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^2.0",
"worksome/coding-style": "^2.5"
"nunomaduro/collision": "^7.10",
"nunomaduro/larastan": "^2.6.4",
"orchestra/testbench": "^8.15",
"pestphp/pest": "^2.24.3",
"worksome/coding-style": "^2.6.1"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 2 additions & 0 deletions config/telemetry.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Worksome\HorizonTelemetry\Enums\MeterName;

return [

'horizon' => [
/**
* The crontab schedule for the current number of master supervisors.
Expand Down Expand Up @@ -54,4 +55,5 @@
*/
MeterName::ProcessedJobsPeakMemoryUsage->value => true,
],

];
19 changes: 11 additions & 8 deletions src/HorizonTelemetryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class HorizonTelemetryServiceProvider extends ServiceProvider
{
private const CONFIG_PATH = __DIR__ . '/../config/telemetry.php';

private const CONFIG_PREFIX = 'telemetry.horizon.';

public function boot(): void
{
$this->callAfterResolving(Dispatcher::class, function (Dispatcher $dispatcher) {
Expand All @@ -36,15 +34,15 @@ public function boot(): void
return null;
}

if ($config->get(self::CONFIG_PREFIX . MeterName::FailedJobs->value, true)) {
if ($config->get($this->configKey(MeterName::FailedJobs), true)) {
$dispatcher->listen(JobFailed::class, FailedJobsListener::class);
}

if ($config->get(self::CONFIG_PREFIX . MeterName::ProcessedJobs->value, true)) {
if ($config->get($this->configKey(MeterName::ProcessedJobs), true)) {
$dispatcher->listen(JobProcessed::class, ProcessedJobsListener::class);
}

if ($config->get(self::CONFIG_PREFIX . MeterName::ProcessedJobsPeakMemoryUsage->value, true)) {
if ($config->get($this->configKey(MeterName::ProcessedJobsPeakMemoryUsage), true)) {
$dispatcher->listen(JobProcessed::class, ProcessedJobsPeakMemoryUsageListener::class);
$dispatcher->listen(JobProcessing::class, ProcessedJobsPeakMemoryUsagePreparationListener::class);
}
Expand All @@ -59,22 +57,22 @@ public function boot(): void
}

if ($currentMasterSupervisorsSchedule = $config->get(
self::CONFIG_PREFIX . MeterName::CurrentMasterSupervisors->value
$this->configKey(MeterName::CurrentMasterSupervisors)
)) {
/** @var string $currentMasterSupervisorsSchedule */
$schedule->call(CurrentMasterSupervisorsMetric::class)
->cron($currentMasterSupervisorsSchedule)
->name(MeterName::CurrentMasterSupervisors->value);
}

if ($currentProcessesSchedule = $config->get(self::CONFIG_PREFIX . MeterName::CurrentProcesses->value)) {
if ($currentProcessesSchedule = $config->get($this->configKey(MeterName::CurrentProcesses))) {
/** @var string $currentProcessesSchedule */
$schedule->call(CurrentProcessesMetric::class)
->cron($currentProcessesSchedule)
->name(MeterName::CurrentProcesses->value);
}

if ($currentJobsSchedule = $config->get(self::CONFIG_PREFIX . MeterName::CurrentJobs->value)) {
if ($currentJobsSchedule = $config->get($this->configKey(MeterName::CurrentJobs))) {
/** @var string $currentJobsSchedule */
$schedule->call(CurrentJobsMetric::class)
->cron($currentJobsSchedule)
Expand All @@ -87,4 +85,9 @@ public function register(): void
{
$this->mergeConfigFrom(self::CONFIG_PATH, 'telemetry');
}

private function configKey(MeterName $meterName): string
{
return "telemetry.horizon.{$meterName->value}";
}
}
1 change: 0 additions & 1 deletion src/Listeners/ProcessedJobsPeakMemoryUsageListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Worksome\HorizonTelemetry\Listeners;

use Illuminate\Queue\Events\JobProcessed;
use OpenTelemetry\API\Metrics\ObserverInterface;
use Worksome\HorizonTelemetry\Enums\MeterName;
use Worksome\HorizonTelemetry\Enums\MeterUnit;
use Worksome\HorizonTelemetry\MeterProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

namespace Worksome\HorizonTelemetry\Listeners;

use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;
use OpenTelemetry\API\Metrics\ObserverInterface;
use Worksome\HorizonTelemetry\Enums\MeterName;
use Worksome\HorizonTelemetry\Enums\MeterUnit;
use Worksome\HorizonTelemetry\MeterProvider;

/**
* Needed for cleaning the peak memory usage variable inside PHP between jobs.
Expand Down

0 comments on commit 7d7d74a

Please sign in to comment.