Skip to content

Commit

Permalink
feat: add LoggerProvider container binding
Browse files Browse the repository at this point in the history
  • Loading branch information
owenvoke committed Jul 23, 2024
1 parent 6311367 commit b700a52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ You can publish the config file with:
```shell
php artisan vendor:publish --tag="laravel-telemetry-config"
```

## Usage

This package will work out of the box with a default OTLP exporter configuration.
Expand Down
10 changes: 10 additions & 0 deletions src/LaravelTelemetryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
use Illuminate\Queue\Events\WorkerStopping;
use Illuminate\Support\ServiceProvider;
use OpenTelemetry\API\LoggerHolder;
use OpenTelemetry\API\Logs\LoggerProviderInterface;
use OpenTelemetry\API\Metrics\MeterProviderInterface;
use OpenTelemetry\API\Trace\TracerProviderInterface;
use OpenTelemetry\SDK\Common\Configuration\Resolver\CompositeResolver;
use OpenTelemetry\SDK\Logs\LoggerProviderFactory;
use OpenTelemetry\SDK\Logs\LoggerProviderInterface as LoggerProviderSdkInterface;
use OpenTelemetry\SDK\Metrics\MeterProviderFactory;
use OpenTelemetry\SDK\Metrics\MeterProviderInterface as MeterProviderSdkInterface;
use OpenTelemetry\SDK\Trace\TracerProviderFactory;
Expand All @@ -22,6 +25,12 @@ class LaravelTelemetryServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton(LoggerProviderSdkInterface::class, function () {
return (new LoggerProviderFactory())->create();
});

$this->app->bind(LoggerProviderInterface::class, LoggerProviderSdkInterface::class);

$this->app->singleton(MeterProviderSdkInterface::class, function () {
return (new MeterProviderFactory())->create();
});
Expand All @@ -46,6 +55,7 @@ public function boot(): void
'telemetry',
);

$this->app->beforeResolving(LoggerProviderInterface::class, $this->prepareConfigResolver(...));
$this->app->beforeResolving(MeterProviderInterface::class, $this->prepareConfigResolver(...));
$this->app->beforeResolving(TracerProviderInterface::class, $this->prepareConfigResolver(...));

Expand Down

0 comments on commit b700a52

Please sign in to comment.