Skip to content

Commit

Permalink
delay instrumentation registration after app booted
Browse files Browse the repository at this point in the history
  • Loading branch information
cappuc committed Apr 22, 2024
1 parent 5cf7efb commit 06adcae
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
28 changes: 28 additions & 0 deletions src/InstrumentationServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Keepsuit\LaravelOpenTelemetry;

use Illuminate\Support\ServiceProvider;
use Keepsuit\LaravelOpenTelemetry\Instrumentation\Instrumentation;

class InstrumentationServiceProvider extends ServiceProvider
{
public function boot(): void
{
foreach (config('opentelemetry.instrumentation') as $key => $options) {
if ($options === false) {
continue;
}

if (is_array($options) && ! ($options['enabled'] ?? true)) {
continue;
}

$watcher = $this->app->make($key);

if ($watcher instanceof Instrumentation) {
$watcher->register(is_array($options) ? $options : []);
}
}
}
}
20 changes: 4 additions & 16 deletions src/LaravelOpenTelemetryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

use Composer\InstalledVersions;
use Illuminate\Config\Repository;
use Illuminate\Foundation\Application;
use Illuminate\Support\Arr;
use Illuminate\Support\Env;
use Illuminate\Support\Str;
use Keepsuit\LaravelOpenTelemetry\Instrumentation\Instrumentation;
use Keepsuit\LaravelOpenTelemetry\Support\CarbonClock;
use Keepsuit\LaravelOpenTelemetry\Support\OpenTelemetryMonologHandler;
use Keepsuit\LaravelOpenTelemetry\Support\PropagatorBuilder;
Expand Down Expand Up @@ -140,21 +140,9 @@ protected function registerInstrumentation(): void
return;
}

foreach (config('opentelemetry.instrumentation') as $key => $options) {
if ($options === false) {
continue;
}

if (is_array($options) && ! ($options['enabled'] ?? true)) {
continue;
}

$watcher = $this->app->make($key);

if ($watcher instanceof Instrumentation) {
$watcher->register(is_array($options) ? $options : []);
}
}
$this->app->booted(function (Application $app) {
$app->register(InstrumentationServiceProvider::class);
});
}

private function configureEnvironmentVariables(): void
Expand Down

0 comments on commit 06adcae

Please sign in to comment.