diff --git a/.travis.yml b/.travis.yml index 41e52e20..bcad5577 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,32 +8,32 @@ php: env: matrix: # All versions below should be test on PHP ^7.1 (Sentry SDK requrement) - - LARAVEL=5.1.* TESTBENCH=3.1.* PHPUNIT=5.7.* SENTRY=^2.3 - - LARAVEL=5.2.* TESTBENCH=3.2.* PHPUNIT=5.7.* SENTRY=^2.3 - - LARAVEL=5.3.* TESTBENCH=3.3.* PHPUNIT=5.7.* SENTRY=^2.3 - - LARAVEL=5.4.* TESTBENCH=3.4.* PHPUNIT=5.7.* SENTRY=^2.3 - - LARAVEL=5.5.* TESTBENCH=3.5.* PHPUNIT=6.5.* SENTRY=^2.3 - - LARAVEL=5.6.* TESTBENCH=3.6.* PHPUNIT=7.5.* SENTRY=^2.3 - - LARAVEL=5.7.* TESTBENCH=3.7.* PHPUNIT=7.5.* SENTRY=^2.3 - - LARAVEL=5.8.* TESTBENCH=3.8.* PHPUNIT=7.5.* SENTRY=^2.3 + - LARAVEL=5.1.* TESTBENCH=3.1.* PHPUNIT=5.7.* SENTRY=^3.0 + - LARAVEL=5.2.* TESTBENCH=3.2.* PHPUNIT=5.7.* SENTRY=^3.0 + - LARAVEL=5.3.* TESTBENCH=3.3.* PHPUNIT=5.7.* SENTRY=^3.0 + - LARAVEL=5.4.* TESTBENCH=3.4.* PHPUNIT=5.7.* SENTRY=^3.0 + - LARAVEL=5.5.* TESTBENCH=3.5.* PHPUNIT=6.5.* SENTRY=^3.0 + - LARAVEL=5.6.* TESTBENCH=3.6.* PHPUNIT=7.5.* SENTRY=^3.0 + - LARAVEL=5.7.* TESTBENCH=3.7.* PHPUNIT=7.5.* SENTRY=^3.0 + - LARAVEL=5.8.* TESTBENCH=3.8.* PHPUNIT=7.5.* SENTRY=^3.0 # All versions below only support PHP ^7.2 (Laravel requirement) - - LARAVEL=^6.0 TESTBENCH=4.7.* PHPUNIT=8.4.* SENTRY=^2.3 - - LARAVEL=^7.0 TESTBENCH=5.1.* PHPUNIT=8.4.* SENTRY=^2.3 + - LARAVEL=^6.0 TESTBENCH=4.7.* PHPUNIT=8.4.* SENTRY=^3.0 + - LARAVEL=^7.0 TESTBENCH=5.1.* PHPUNIT=8.4.* SENTRY=^3.0 # We add one more test using the next version of Laravel which only support PHP ^7.3 (Laravel requirement) - - LARAVEL=8.x-dev@dev TESTBENCH=^6.0 PHPUNIT=8.4.* SENTRY=^2.3 COMPOSER_STABILITY=dev + - LARAVEL=8.x-dev@dev TESTBENCH=^6.0 PHPUNIT=8.4.* SENTRY=^3.0 COMPOSER_STABILITY=dev matrix: fast_finish: true allow_failures: - php: 7.3 - env: LARAVEL=8.x-dev@dev TESTBENCH=^6.0 PHPUNIT=8.4.* SENTRY=^2.3 COMPOSER_STABILITY=dev + env: LARAVEL=8.x-dev@dev TESTBENCH=^6.0 PHPUNIT=8.4.* SENTRY=^3.0 COMPOSER_STABILITY=dev - php: 7.4 - env: LARAVEL=8.x-dev@dev TESTBENCH=^6.0 PHPUNIT=8.4.* SENTRY=^2.3 COMPOSER_STABILITY=dev + env: LARAVEL=8.x-dev@dev TESTBENCH=^6.0 PHPUNIT=8.4.* SENTRY=^3.0 COMPOSER_STABILITY=dev exclude: - php: 7.2 - env: LARAVEL=8.x-dev@dev TESTBENCH=^6.0 PHPUNIT=8.4.* SENTRY=^2.3 COMPOSER_STABILITY=dev + env: LARAVEL=8.x-dev@dev TESTBENCH=^6.0 PHPUNIT=8.4.* SENTRY=^3.0 COMPOSER_STABILITY=dev cache: directories: diff --git a/CHANGELOG.md b/CHANGELOG.md index b11657c0..28b9180f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,29 @@ ## Unreleased +## 2.0.0 + +**Breaking Change**: This version uses the [envelope endpoint](https://develop.sentry.dev/sdk/envelopes/). If you are +using an on-premise installation it requires Sentry version `>= v20.6.0` to work. If you are using +[sentry.io](https://sentry.io) nothing will change and no action is needed. + +**Tracing API / Monitor Performance** + +In this version we released API for Tracing. `\Sentry\startTransaction` is your entry point for manual instrumentation. +More information can be found in our [Performance](https://docs.sentry.io/platforms/php/guides/laravel/performance/) docs. + +- Using `^3.0` of Sentry PHP SDK +- Add support for Tracing, enable it by setting `traces_sample_rate` in the config to a value > 0 (the value should be larger than `0.0` and smaller or equal than `1.0` (to send everything)) + +## 2.0.0-beta1 + +**Breaking Change**: This version uses the [envelope endpoint](https://develop.sentry.dev/sdk/envelopes/). If you are +using an on-premise installation it requires Sentry version `>= v20.6.0` to work. If you are using +[sentry.io](https://sentry.io) nothing will change and no action is needed. + +- Using `3.0.0-beta1` of Sentry PHP SDK +- Add support for Tracing, enable it by setting `traces_sample_rate` in the config to a value > 0 (the value should be larger than `0.0` and smaller or equal than `1.0` (to send everything)) + ## 1.9.0 - Respect the `SENTRY_ENVIRONMENT` environment variable to override the Laravel environment (#354) diff --git a/composer.json b/composer.json index 72ec9b81..c0d90988 100644 --- a/composer.json +++ b/composer.json @@ -21,9 +21,9 @@ } ], "require": { - "php": "^7.1", + "php": "^7.2", "illuminate/support": "5.0 - 5.8 | ^6.0 | ^7.0 | ^8.0", - "sentry/sdk": "^2.1" + "sentry/sdk": "^3.0" }, "require-dev": { "phpunit/phpunit": "^8.0", @@ -57,12 +57,13 @@ }, "extra": { "branch-alias": { - "dev-master": "1.x-dev", + "dev-master": "2.x-dev", "dev-0.x": "0.x-dev" }, "laravel": { "providers": [ - "Sentry\\Laravel\\ServiceProvider" + "Sentry\\Laravel\\ServiceProvider", + "Sentry\\Laravel\\Tracing\\ServiceProvider" ], "aliases": { "Sentry": "Sentry\\Laravel\\Facade" diff --git a/config/sentry.php b/config/sentry.php index ffcc8788..f71f830d 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -30,4 +30,5 @@ // @see: https://docs.sentry.io/error-reporting/configuration/?platform=php#send-default-pii 'send_default_pii' => false, + 'traces_sample_rate' => \floatval(env('SENTRY_TRACES_SAMPLE_RATE', 0.0)), ]; diff --git a/src/Sentry/Laravel/EventHandler.php b/src/Sentry/Laravel/EventHandler.php index 896259e7..6018b03e 100644 --- a/src/Sentry/Laravel/EventHandler.php +++ b/src/Sentry/Laravel/EventHandler.php @@ -16,11 +16,12 @@ use Illuminate\Queue\QueueManager; use Illuminate\Routing\Events\RouteMatched; use Illuminate\Routing\Route; -use Illuminate\Support\Str; use RuntimeException; use Sentry\Breadcrumb; use Sentry\SentrySdk; use Sentry\State\Scope; +use Sentry\Tracing\SpanContext; +use Sentry\Tracing\Transaction; class EventHandler { @@ -194,26 +195,16 @@ public function __call($method, $arguments) */ protected function routerMatchedHandler(Route $route) { - $routeName = null; + $routeName = Integration::extractNameForRoute($route) ?? ''; - if ($route->getName()) { - // someaction (route name/alias) - $routeName = $route->getName(); + $transaction = SentrySdk::getCurrentHub()->getTransaction(); - // Laravel 7 route caching generates a route names if the user didn't specify one - // theirselfs to optimize route matching. These route names are useless to the - // developer so if we encounter a generated route name we discard the value - if (Str::startsWith($routeName, 'generated::')) { - $routeName = null; - } - } - - if (empty($routeName) && $route->getActionName()) { - // SomeController@someAction (controller action) - $routeName = $route->getActionName(); - } elseif (empty($routeName) || $routeName === 'Closure') { - // /someaction // Fallback to the url - $routeName = $route->uri(); + if ($transaction instanceof Transaction) { + $transaction->setName($routeName); + $transaction->setData([ + 'action' => $route->getActionName(), + 'name' => $route->getName() + ]); } Integration::addBreadcrumb(new Breadcrumb( @@ -287,6 +278,16 @@ private function addQueryBreadcrumb($query, $bindings, $time, $connectionName) $data['bindings'] = $bindings; } + $transaction = SentrySdk::getCurrentHub()->getTransaction(); + if (null !== $transaction) { + $context = new SpanContext(); + $context->setOp('sql.query'); + $context->setDescription($query); + $context->setStartTimestamp(microtime(true) - $time / 1000); + $context->setEndTimestamp($context->getStartTimestamp() + $time / 1000); + $transaction->startChild($context); + } + Integration::addBreadcrumb(new Breadcrumb( Breadcrumb::LEVEL_INFO, Breadcrumb::TYPE_DEFAULT, diff --git a/src/Sentry/Laravel/Integration.php b/src/Sentry/Laravel/Integration.php index 7c6eff68..01d215c9 100644 --- a/src/Sentry/Laravel/Integration.php +++ b/src/Sentry/Laravel/Integration.php @@ -2,8 +2,11 @@ namespace Sentry\Laravel; +use Illuminate\Routing\Route; +use Illuminate\Support\Str; use Sentry\FlushableClientInterface; use Sentry\SentrySdk; +use Sentry\Tracing\Span; use function Sentry\addBreadcrumb; use function Sentry\configureScope; use Sentry\Breadcrumb; @@ -30,7 +33,9 @@ public function setupOnce(): void return $event; } - $event->setTransaction($self->getTransaction()); + if (null === $event->getTransaction()) { + $event->setTransaction($self->getTransaction()); + } return $event; }); @@ -71,7 +76,7 @@ public static function configureScope(callable $callback): void /** * @return null|string */ - public static function getTransaction() + public static function getTransaction(): ?string { return self::$transaction; } @@ -98,4 +103,78 @@ public static function flushEvents(): void $client->flush(); } } + + /** + * Extract the readable name for a route. + * + * @param \Illuminate\Routing\Route $route + * + * @return string|null + */ + public static function extractNameForRoute(Route $route): ?string + { + $routeName = null; + + if (empty($routeName) && $route->getName()) { + // someaction (route name/alias) + $routeName = $route->getName(); + + // Laravel 7 route caching generates a route names if the user didn't specify one + // theirselfs to optimize route matching. These route names are useless to the + // developer so if we encounter a generated route name we discard the value + if (Str::startsWith($routeName, 'generated::')) { + $routeName = null; + } + + // If the route name ends with a `.` we assume an incomplete group name prefix + // we discard this value since it will most likely not mean anything to the + // developer and will be duplicated by other unnamed routes in the group + if (Str::endsWith($routeName, '.')) { + $routeName = null; + } + } + + if (empty($routeName) && $route->getActionName()) { + // SomeController@someAction (controller action) + $routeName = ltrim($route->getActionName(), '\\'); + } + + if (empty($routeName) || $routeName === 'Closure') { + // /someaction // Fallback to the url + $routeName = '/' . ltrim($route->uri(), '/'); + } + + return $routeName; + } + + /** + * Retrieve the meta tags with tracing information to link this request to front-end requests. + * + * @return string + */ + public static function sentryTracingMeta(): string + { + $span = self::currentTracingSpan(); + + if ($span === null) { + return ''; + } + + $content = sprintf('', $span->toTraceparent()); + // $content .= sprintf('', $span->getDescription()); + + return $content; + } + + /** + * Get the current active tracing span from the scope. + * + * @return \Sentry\Tracing\Span|null + * + * @internal This is used internally as an easy way to retrieve the current active tracing span. + */ + public static function currentTracingSpan(): ?Span + { + return SentrySdk::getCurrentHub()->getSpan(); + } } diff --git a/src/Sentry/Laravel/PublishConfigCommand.php b/src/Sentry/Laravel/PublishConfigCommand.php new file mode 100644 index 00000000..1296749e --- /dev/null +++ b/src/Sentry/Laravel/PublishConfigCommand.php @@ -0,0 +1,86 @@ +info('[Sentry] Publishing config ...'); + $this->call('vendor:publish', [ + '--provider' => 'Sentry\Laravel\ServiceProvider' + ]); + + if ($this->confirm('Enable Performance Monitoring?', true)) { + $this->setEnvironmentValue(['SENTRY_TRACES_SAMPLE_RATE' => 1.0]); + + $this->info('[Sentry] Added `SENTRY_TRACES_SAMPLE_RATE=1` to your .env file.'); + + $testCommandPrompt = 'Want to send a test Event & Transaction?'; + $args = ['--transaction' => true]; + } else { + $testCommandPrompt = 'Want to send a test Event?'; + $args = []; + } + + if ($this->confirm($testCommandPrompt, true)) { + $this->call('sentry:test', $args); + } + } + + public function setEnvironmentValue(array $values) + { + $envFile = app()->environmentFilePath(); + $str = file_get_contents($envFile); + + if (count($values) > 0) { + foreach ($values as $envKey => $envValue) { + + $str .= "\n"; // In case the searched variable is in the last line without \n + $keyPosition = strpos($str, "{$envKey}="); + $endOfLinePosition = strpos($str, "\n", $keyPosition); + $oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition); + + // If key does not exist, add it + if (!$keyPosition || !$endOfLinePosition || !$oldLine) { + $str .= "{$envKey}={$envValue}\n"; + } else { + $str = str_replace($oldLine, "{$envKey}={$envValue}", $str); + } + + } + } + + $str = substr($str, 0, -1); + if (!file_put_contents($envFile, $str)) return false; + return true; + } +} diff --git a/src/Sentry/Laravel/ServiceProvider.php b/src/Sentry/Laravel/ServiceProvider.php index c3482fc0..cb0538b8 100644 --- a/src/Sentry/Laravel/ServiceProvider.php +++ b/src/Sentry/Laravel/ServiceProvider.php @@ -2,6 +2,7 @@ namespace Sentry\Laravel; +use Illuminate\Contracts\Http\Kernel as HttpKernelInterface; use Sentry\SentrySdk; use Sentry\State\Hub; use Sentry\ClientBuilder; @@ -12,6 +13,7 @@ use Sentry\Integration as SdkIntegration; use Illuminate\Foundation\Application as Laravel; use Illuminate\Support\ServiceProvider as IlluminateServiceProvider; +use Illuminate\Support\Facades\Storage; class ServiceProvider extends IlluminateServiceProvider { @@ -91,6 +93,7 @@ protected function registerArtisanCommands(): void { $this->commands([ TestCommand::class, + PublishConfigCommand::class, ]); } diff --git a/src/Sentry/Laravel/TestCommand.php b/src/Sentry/Laravel/TestCommand.php index 08a69185..e344f542 100644 --- a/src/Sentry/Laravel/TestCommand.php +++ b/src/Sentry/Laravel/TestCommand.php @@ -4,6 +4,8 @@ use Exception; use Illuminate\Console\Command; +use Sentry\Tracing\SpanContext; +use Sentry\Tracing\TransactionContext; class TestCommand extends Command { @@ -19,7 +21,7 @@ class TestCommand extends Command * * @var string */ - protected $signature = 'sentry:test'; + protected $signature = 'sentry:test {--transaction}'; /** * The console command description. @@ -43,32 +45,51 @@ public function handle() $hub = app('sentry'); if ($hub->getClient()->getOptions()->getDsn()) { - $this->info('[sentry] Client DSN discovered!'); + $this->info('[Sentry] DSN discovered!'); } else { - $this->error('[sentry] Could not discover DSN!'); - $this->error('[sentry] Please check if you DSN is set properly in your config or `.env` as `SENTRY_LARAVEL_DSN`.'); + $this->error('[Sentry] Could not discover DSN!'); + $this->error('[Sentry] Please check if you DSN is set properly in your config or `.env` as `SENTRY_LARAVEL_DSN`.'); return; } - $this->info('[sentry] Generating test event'); + if ($this->option('transaction')) { + $hub->getClient()->getOptions()->setTracesSampleRate(1); + } + + $transactionContext = new TransactionContext(); + $transactionContext->setName('Sentry Test Transaction'); + $transactionContext->setOp('sentry.test'); + $transaction = $hub->startTransaction($transactionContext); + + $spanContext = new SpanContext(); + $spanContext->setOp('sentry.sent'); + $span1 = $transaction->startChild($spanContext); + + $this->info('[Sentry] Generating test Event'); $ex = $this->generateTestException('command name', ['foo' => 'bar']); $hub->captureException($ex); - $this->info('[sentry] Sending test event'); + $this->info('[Sentry] Sending test Event'); + + $span1->finish(); + $result = $transaction->finish(); + if ($result) { + $this->info('[Sentry] Sending test Transaction'); + } $lastEventId = $hub->getLastEventId(); if (!$lastEventId) { - $this->error('[sentry] There was an error sending the test event.'); - $this->error('[sentry] Please check if you DSN is set properly in your config or `.env` as `SENTRY_LARAVEL_DSN`.'); + $this->error('[Sentry] There was an error sending the test event.'); + $this->error('[Sentry] Please check if you DSN is set properly in your config or `.env` as `SENTRY_LARAVEL_DSN`.'); } else { - $this->info("[sentry] Event sent with ID: {$lastEventId}"); + $this->info("[Sentry] Event sent with ID: {$lastEventId}"); } } catch (Exception $e) { - $this->error("[sentry] {$e->getMessage()}"); + $this->error("[Sentry] {$e->getMessage()}"); } error_reporting($old_error_reporting); diff --git a/src/Sentry/Laravel/Tracing/Middleware.php b/src/Sentry/Laravel/Tracing/Middleware.php new file mode 100644 index 00000000..41fd27d4 --- /dev/null +++ b/src/Sentry/Laravel/Tracing/Middleware.php @@ -0,0 +1,116 @@ +bound('sentry')) { + $this->startTransaction($request, app('sentry')); + } + + return $next($request); + } + + /** + * Handle the application termination. + * + * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Response $response + * + * @return void + */ + public function terminate($request, $response): void + { + if ($this->transaction !== null && app()->bound('sentry')) { + $this->transaction->finish(); + } + } + + private function startTransaction(Request $request, Hub $sentry): void + { + $path = '/' . ltrim($request->path(), '/'); + $fallbackTime = microtime(true); + $sentryTraceHeader = $request->header('sentry-trace'); + + $context = $sentryTraceHeader + ? TransactionContext::fromTraceparent($sentryTraceHeader) + : new TransactionContext; + + $context->setOp('http.server'); + $context->setName($path); + $context->setData([ + 'url' => $path, + 'method' => strtoupper($request->method()), + ]); + $context->setStartTimestamp($request->server('REQUEST_TIME_FLOAT', $fallbackTime)); + + $this->transaction = $sentry->startTransaction($context); + + // Setting the Transaction on the Hub + SentrySdk::getCurrentHub()->setSpan($this->transaction); + + if (!$this->addBootTimeSpans()) { + // @TODO: We might want to move this together with the `RouteMatches` listener to some central place and or do this from the `EventHandler` + app()->booted(function () use ($request, $fallbackTime): void { + $spanContextStart = new SpanContext(); + $spanContextStart->setOp('app.bootstrap'); + $spanContextStart->setStartTimestamp(defined('LARAVEL_START') ? LARAVEL_START : $request->server('REQUEST_TIME_FLOAT', $fallbackTime)); + $spanContextStart->setEndTimestamp(microtime(true)); + $this->transaction->startChild($spanContextStart); + }); + } + } + + private function addBootTimeSpans(): bool + { + if (!defined('LARAVEL_START') || !LARAVEL_START) { + return false; + } + + if (!defined('SENTRY_AUTOLOAD') || !SENTRY_AUTOLOAD) { + return false; + } + + if (!defined('SENTRY_BOOTSTRAP') || !SENTRY_BOOTSTRAP) { + return false; + } + + $spanContextStart = new SpanContext(); + $spanContextStart->setOp('autoload'); + $spanContextStart->setStartTimestamp(LARAVEL_START); + $spanContextStart->setEndTimestamp(SENTRY_AUTOLOAD); + $this->transaction->startChild($spanContextStart); + + $spanContextStart = new SpanContext(); + $spanContextStart->setOp('bootstrap'); + $spanContextStart->setStartTimestamp(SENTRY_AUTOLOAD); + $spanContextStart->setEndTimestamp(SENTRY_BOOTSTRAP); + $this->transaction->startChild($spanContextStart); + + return true; + } +} diff --git a/src/Sentry/Laravel/Tracing/ServiceProvider.php b/src/Sentry/Laravel/Tracing/ServiceProvider.php new file mode 100644 index 00000000..084ee835 --- /dev/null +++ b/src/Sentry/Laravel/Tracing/ServiceProvider.php @@ -0,0 +1,63 @@ +app->bound(HttpKernelInterface::class)) { + /** @var \Illuminate\Contracts\Http\Kernel $httpKernel */ + $httpKernel = $this->app->make(HttpKernelInterface::class); + + $httpKernel->prependMiddleware(Middleware::class); + } + } + + public function register(): void + { + $this->app->singleton(Middleware::class); + + $viewEngineWrapper = function (EngineResolver $engineResolver): void { + foreach (['file', 'php', 'blade'] as $engineName) { + try { + $realEngine = $engineResolver->resolve($engineName); + + $engineResolver->register($engineName, function () use ($realEngine) { + return $this->wrapViewEngine($realEngine); + }); + } catch (InvalidArgumentException $e) { + // The `file` engine was introduced in Laravel 5.4. On lower Laravel versions + // resolving that driver will throw an `InvalidArgumentException`. We can + // ignore this exception because we can't wrap drivers that don't exist + } + } + }; + + if ($this->app->resolved('view.engine.resolver')) { + $viewEngineWrapper($this->app->make('view.engine.resolver')); + } else { + $this->app->afterResolving('view.engine.resolver', $viewEngineWrapper); + } + } + + private function wrapViewEngine(Engine $realEngine): Engine + { + /** @var ViewFactory $viewFactory */ + $viewFactory = $this->app->make('view'); + + /** @noinspection UnusedFunctionResultInspection */ + $viewFactory->composer('*', static function (View $view) use ($viewFactory) : void { + $viewFactory->share(ViewEngineDecorator::SHARED_KEY, $view->name()); + }); + + return new ViewEngineDecorator($realEngine, $viewFactory); + } +} diff --git a/src/Sentry/Laravel/Tracing/ViewEngineDecorator.php b/src/Sentry/Laravel/Tracing/ViewEngineDecorator.php new file mode 100644 index 00000000..cc715bd7 --- /dev/null +++ b/src/Sentry/Laravel/Tracing/ViewEngineDecorator.php @@ -0,0 +1,59 @@ +engine = $engine; + $this->viewFactory = $viewFactory; + } + + /** + * {@inheritdoc} + */ + public function get($path, array $data = []): string + { + $parentSpan = Integration::currentTracingSpan(); + + if ($parentSpan === null) { + return $this->engine->get($path, $data); + } + + $context = new SpanContext(); + $context->setOp('view.render'); + $context->setDescription($this->viewFactory->shared(self::SHARED_KEY, basename($path))); + + $span = $parentSpan->startChild($context); + + $result = $this->engine->get($path, $data); + + $span->finish(); + + return $result; + } + + /** + * Laravel uses this function internally + */ + public function getCompiler(): CompilerInterface + { + return $this->engine->getCompiler(); + } +} diff --git a/src/Sentry/Laravel/Version.php b/src/Sentry/Laravel/Version.php index ff728e89..36cf7fa5 100644 --- a/src/Sentry/Laravel/Version.php +++ b/src/Sentry/Laravel/Version.php @@ -5,5 +5,5 @@ final class Version { public const SDK_IDENTIFIER = 'sentry.php.laravel'; - public const SDK_VERSION = '1.9.0'; + public const SDK_VERSION = '2.0.0-beta1'; } diff --git a/test/Sentry/IntegrationsOptionTest.php b/test/Sentry/IntegrationsOptionTest.php index 096e3d47..6507a0da 100644 --- a/test/Sentry/IntegrationsOptionTest.php +++ b/test/Sentry/IntegrationsOptionTest.php @@ -97,39 +97,10 @@ public function testDisabledIntegrationsAreNotPresentWithCustomIntegrations() ], ]); - $integrations = $this->getHubFromContainer()->getClient()->getOptions()->getIntegrations(); - - $found = false; - - foreach ($integrations as $integration) { - $this->ensureIsNotDisabledIntegration($integration); - - if ($integration instanceof IntegrationsOptionTestIntegrationStub) { - $found = true; - } - } - - $this->assertTrue($found, 'No IntegrationsOptionTestIntegrationStub found in final integrations enabled'); - } - - /** - * Make sure the passed integration is not one of the disabled integrations. - * - * @param \Sentry\Integration\IntegrationInterface $integration - */ - private function ensureIsNotDisabledIntegration(IntegrationInterface $integration) - { - if ($integration instanceof ErrorListenerIntegration) { - $this->fail('Should not have ErrorListenerIntegration registered'); - } - - if ($integration instanceof ExceptionListenerIntegration) { - $this->fail('Should not have ExceptionListenerIntegration registered'); - } - - if ($integration instanceof FatalErrorListenerIntegration) { - $this->fail('Should not have FatalErrorListenerIntegration registered'); - } + $this->assertNotNull($this->getHubFromContainer()->getClient()->getIntegration(IntegrationsOptionTestIntegrationStub::class)); + $this->assertNull($this->getHubFromContainer()->getClient()->getIntegration(ErrorListenerIntegration::class)); + $this->assertNull($this->getHubFromContainer()->getClient()->getIntegration(ExceptionListenerIntegration::class)); + $this->assertNull($this->getHubFromContainer()->getClient()->getIntegration(FatalErrorListenerIntegration::class)); } } diff --git a/test/Sentry/ServiceProviderTest.php b/test/Sentry/ServiceProviderTest.php index f3bd6702..218d3121 100644 --- a/test/Sentry/ServiceProviderTest.php +++ b/test/Sentry/ServiceProviderTest.php @@ -51,10 +51,10 @@ public function testDsnWasSetFromConfig() /** @var \Sentry\Options $options */ $options = app('sentry')->getClient()->getOptions(); - $this->assertEquals('http://sentry.dev', $options->getDsn()); - $this->assertEquals(123, $options->getProjectId()); - $this->assertEquals('publickey', $options->getPublicKey()); - $this->assertEquals('secretkey', $options->getSecretKey()); + $this->assertEquals('http://sentry.dev', $options->getDsn()->getScheme() . '://' . $options->getDsn()->getHost()); + $this->assertEquals(123, $options->getDsn()->getProjectId()); + $this->assertEquals('publickey', $options->getDsn()->getPublicKey()); + $this->assertEquals('secretkey', $options->getDsn()->getSecretKey()); } /** diff --git a/test/Sentry/ServiceProviderWithCustomAliasTest.php b/test/Sentry/ServiceProviderWithCustomAliasTest.php index 8d0ee77b..2f44f3d7 100644 --- a/test/Sentry/ServiceProviderWithCustomAliasTest.php +++ b/test/Sentry/ServiceProviderWithCustomAliasTest.php @@ -51,10 +51,10 @@ public function testDsnWasSetFromConfig() /** @var \Sentry\Options $options */ $options = app('custom-sentry')->getClient()->getOptions(); - $this->assertEquals('http://sentry.dev', $options->getDsn()); - $this->assertEquals(123, $options->getProjectId()); - $this->assertEquals('publickey', $options->getPublicKey()); - $this->assertEquals('secretkey', $options->getSecretKey()); + $this->assertEquals('http://sentry.dev', $options->getDsn()->getScheme() . '://' . $options->getDsn()->getHost()); + $this->assertEquals(123, $options->getDsn()->getProjectId()); + $this->assertEquals('publickey', $options->getDsn()->getPublicKey()); + $this->assertEquals('secretkey', $options->getDsn()->getSecretKey()); } /**