generated from worksome/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure that config is used at runtime
- Loading branch information
Showing
6 changed files
with
126 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Contracts\Config\Repository as ConfigRepository; | ||
use OpenTelemetry\API\Logs\LoggerInterface; | ||
use OpenTelemetry\API\Logs\LoggerProviderInterface; | ||
use OpenTelemetry\API\Logs\NoopLogger; | ||
use OpenTelemetry\API\Metrics\MeterInterface; | ||
use OpenTelemetry\API\Metrics\MeterProviderInterface; | ||
use OpenTelemetry\API\Metrics\Noop\NoopMeter; | ||
use OpenTelemetry\API\Trace\NoopTracer; | ||
use OpenTelemetry\API\Trace\TracerInterface; | ||
use OpenTelemetry\API\Trace\TracerProviderInterface; | ||
use OpenTelemetry\SDK\Logs\LoggerProviderInterface as LoggerProviderSdkInterface; | ||
use OpenTelemetry\SDK\Metrics\MeterProviderInterface as MeterProviderSdkInterface; | ||
use OpenTelemetry\SDK\Sdk; | ||
use OpenTelemetry\SDK\Trace\TracerProviderInterface as TracerProviderSdkInterface; | ||
|
||
it('registers the default config', function () { | ||
/** @var ConfigRepository $config */ | ||
$config = $this->app->get(ConfigRepository::class); | ||
|
||
expect($config->get('telemetry')) | ||
->sdk->disabled->toBeFalse() | ||
->exporter->otlp->endpoint->toBe('http://localhost:4318'); | ||
}); | ||
|
||
it('can update the config at runtime', function () { | ||
/** @var ConfigRepository $config */ | ||
$config = $this->app->get(ConfigRepository::class); | ||
|
||
expect(Sdk::isDisabled())->toBeFalse(); | ||
|
||
$config->set('telemetry.sdk.disabled', true); | ||
|
||
expect(Sdk::isDisabled())->toBeTrue(); | ||
}); | ||
|
||
it('registers the logger provider', function () { | ||
expect( | ||
$this->app->get(LoggerProviderInterface::class) | ||
) | ||
->toBeInstanceOf(LoggerProviderInterface::class) | ||
->toBeInstanceOf(LoggerProviderSdkInterface::class); | ||
}); | ||
|
||
it('registers the metric provider', function () { | ||
expect( | ||
$this->app->get(MeterProviderInterface::class) | ||
) | ||
->toBeInstanceOf(MeterProviderInterface::class) | ||
->toBeInstanceOf(MeterProviderSdkInterface::class); | ||
}); | ||
|
||
it('registers the tracer provider', function () { | ||
expect( | ||
$this->app->get(TracerProviderInterface::class) | ||
) | ||
->toBeInstanceOf(TracerProviderInterface::class) | ||
->toBeInstanceOf(TracerProviderSdkInterface::class); | ||
}); | ||
|
||
it('can get a logger from the logger provider', function () { | ||
expect( | ||
$this->app->get(LoggerProviderInterface::class)->getLogger('test') | ||
) | ||
->toBeInstanceOf(LoggerInterface::class); | ||
}); | ||
|
||
it('can get a meter from the meter provider', function () { | ||
expect( | ||
$this->app->get(MeterProviderInterface::class)->getMeter('test') | ||
) | ||
->toBeInstanceOf(MeterInterface::class); | ||
}); | ||
|
||
it('can get a tracer from the tracer provider', function () { | ||
expect( | ||
$this->app->get(TracerProviderInterface::class)->getTracer('test') | ||
) | ||
->toBeInstanceOf(TracerInterface::class); | ||
}); | ||
|
||
it('returns no-op instances when the SDK is disabled', function () { | ||
/** @var ConfigRepository $config */ | ||
$config = $this->app->get(ConfigRepository::class); | ||
|
||
$config->set('telemetry.sdk.disabled', true); | ||
|
||
expect( | ||
$this->app->get(LoggerProviderInterface::class)->getLogger('test') | ||
) | ||
->toBeInstanceOf(NoopLogger::class); | ||
|
||
expect( | ||
$this->app->get(MeterProviderInterface::class)->getLogger('test') | ||
) | ||
->toBeInstanceOf(NoopMeter::class); | ||
|
||
expect( | ||
$this->app->get(TracerProviderInterface::class)->getLogger('test') | ||
) | ||
->toBeInstanceOf(NoopTracer::class); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Worksome\LaravelTelemetry\Tests\TestCase; | ||
|
||
uses(TestCase::class)->in(__DIR__); | ||
uses(TestCase::class)->in('Feature'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Worksome\LaravelTelemetry\Tests; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Orchestra\Testbench\TestCase as Orchestra; | ||
use Worksome\LaravelTelemetry\LaravelTelemetryServiceProvider; | ||
|
||
class TestCase extends Orchestra | ||
abstract class TestCase extends Orchestra | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Factory::guessFactoryNamesUsing( | ||
fn (string $modelName) => 'Worksome\\LaravelTelemetry\\Database\\Factories\\' . class_basename( | ||
$modelName | ||
) . 'Factory' | ||
); | ||
} | ||
|
||
protected function getPackageProviders($app) | ||
protected function getPackageProviders($app): array | ||
{ | ||
return [ | ||
LaravelTelemetryServiceProvider::class, | ||
]; | ||
} | ||
|
||
public function getEnvironmentSetUp($app) | ||
{ | ||
config()->set('database.default', 'testing'); | ||
|
||
/* | ||
$migration = include __DIR__.'/../database/migrations/create_laravel-telemetry_table.php.stub'; | ||
$migration->up(); | ||
*/ | ||
} | ||
} |