-
Notifications
You must be signed in to change notification settings - Fork 184
feat(metrics): add metrics for symfony #977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,26 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sentry\SentryBundle\EventListener; | ||
|
|
||
| use Sentry\Metrics\TraceMetrics; | ||
| use Symfony\Component\HttpKernel\Event\TerminateEvent; | ||
|
|
||
| /** | ||
| * RequestListener for sentry metrics. | ||
| */ | ||
| class MetricsRequestListener | ||
| { | ||
| /** | ||
| * Flushes all metrics on kernel termination. | ||
| * | ||
| * @param TerminateEvent $event | ||
| * | ||
| * @return void | ||
| */ | ||
| public function handleKernelTerminateEvent(TerminateEvent $event) | ||
| { | ||
| TraceMetrics::getInstance()->flush(); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,23 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sentry\SentryBundle\Tests\End2End\App\Command; | ||
|
|
||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| use function Sentry\trace_metrics; | ||
|
|
||
| class MetricsCommand extends Command | ||
| { | ||
| protected function execute(InputInterface $input, OutputInterface $output): int | ||
| { | ||
| trace_metrics()->count('test-counter', 10); | ||
| trace_metrics()->gauge('test-gauge', 20.51); | ||
| trace_metrics()->distribution('test-distribution', 100.81); | ||
|
|
||
| return 0; | ||
| } | ||
| } |
This file contains hidden or 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,21 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sentry\SentryBundle\Tests\End2End\App\Controller; | ||
|
|
||
| use Symfony\Component\HttpFoundation\Response; | ||
|
|
||
| use function Sentry\trace_metrics; | ||
|
|
||
| class MetricsController | ||
| { | ||
| public function metrics(): Response | ||
| { | ||
| trace_metrics()->count('test-counter', 10); | ||
| trace_metrics()->gauge('test-gauge', 20.51); | ||
| trace_metrics()->distribution('test-distribution', 100.81); | ||
|
|
||
| return new Response(); | ||
| } | ||
| } |
This file contains hidden or 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,17 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sentry\SentryBundle\Tests\End2End\App; | ||
|
|
||
| use Symfony\Component\Config\Loader\LoaderInterface; | ||
|
|
||
| class KernelWithMetrics extends Kernel | ||
| { | ||
| public function registerContainerConfiguration(LoaderInterface $loader): void | ||
| { | ||
| parent::registerContainerConfiguration($loader); | ||
|
|
||
| $loader->load(__DIR__ . '/metrics.yml'); | ||
| } | ||
| } |
This file contains hidden or 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,9 @@ | ||
| services: | ||
| Sentry\SentryBundle\Tests\End2End\App\Controller\MetricsController: | ||
| autowire: true | ||
| tags: | ||
| - { name: controller.service_arguments } | ||
|
|
||
| Sentry\SentryBundle\Tests\End2End\App\Command\MetricsCommand: | ||
| autowire: true | ||
| tags: [ { name: 'console.command', command: 'metrics:test' } ] |
This file contains hidden or 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 hidden or 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,56 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace End2End; | ||
|
|
||
| use Sentry\SentryBundle\Tests\End2End\App\KernelWithMetrics; | ||
| use Sentry\SentryBundle\Tests\End2End\StubTransport; | ||
| use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
| use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
| use Symfony\Component\Console\Input\ArgvInput; | ||
| use Symfony\Component\Console\Output\NullOutput; | ||
|
|
||
| /** | ||
| * @runTestsInSeparateProcesses | ||
| */ | ||
| class MetricsCommandTest extends WebTestCase | ||
| { | ||
| /** | ||
| * @var Application | ||
| */ | ||
| private $application; | ||
|
|
||
| protected static function getKernelClass(): string | ||
| { | ||
| return KernelWithMetrics::class; | ||
| } | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| StubTransport::$events = []; | ||
| $this->application = new Application(self::bootKernel()); | ||
| } | ||
|
|
||
| public function testMetricsInCommand(): void | ||
| { | ||
| $this->application->doRun(new ArgvInput(['bin/console', 'metrics:test']), new NullOutput()); | ||
|
|
||
| $this->assertCount(1, StubTransport::$events); | ||
| $metrics = StubTransport::$events[0]->getMetrics(); | ||
|
|
||
| $this->assertCount(3, $metrics); | ||
|
|
||
| $count = $metrics[0]; | ||
| $this->assertSame('test-counter', $count->getName()); | ||
| $this->assertSame(10.0, $count->getValue()); | ||
|
|
||
| $gauge = $metrics[1]; | ||
| $this->assertSame('test-gauge', $gauge->getName()); | ||
| $this->assertSame(20.51, $gauge->getValue()); | ||
|
|
||
| $distribution = $metrics[2]; | ||
| $this->assertSame('test-distribution', $distribution->getName()); | ||
| $this->assertSame(100.81, $distribution->getValue()); | ||
| } | ||
| } | ||
This file contains hidden or 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,48 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sentry\SentryBundle\Tests\End2End; | ||
|
|
||
| use Sentry\SentryBundle\Tests\End2End\App\KernelWithMetrics; | ||
| use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
|
|
||
| /** | ||
| * @runTestsInSeparateProcesses | ||
| */ | ||
| class MetricsEnd2EndTest extends WebTestCase | ||
| { | ||
| protected function setUp(): void | ||
| { | ||
| StubTransport::$events = []; | ||
| } | ||
|
|
||
| protected static function getKernelClass(): string | ||
| { | ||
| return KernelWithMetrics::class; | ||
| } | ||
|
|
||
| public function testMetricsAreFlushedAfterRequest(): void | ||
| { | ||
| $client = static::createClient(['debug' => true]); | ||
|
|
||
| $client->request('GET', '/metrics'); | ||
| $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
|
|
||
| $this->assertCount(1, StubTransport::$events); | ||
| $metrics = StubTransport::$events[0]->getMetrics(); | ||
| $this->assertCount(3, $metrics); | ||
|
|
||
| $count = $metrics[0]; | ||
| $this->assertSame('test-counter', $count->getName()); | ||
| $this->assertSame(10.0, $count->getValue()); | ||
|
|
||
| $gauge = $metrics[1]; | ||
| $this->assertSame('test-gauge', $gauge->getName()); | ||
| $this->assertSame(20.51, $gauge->getValue()); | ||
|
|
||
| $distribution = $metrics[2]; | ||
| $this->assertSame('test-distribution', $distribution->getName()); | ||
| $this->assertSame(100.81, $distribution->getValue()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.