Skip to content

Commit 92fd79e

Browse files
authored
ref(metrics): add metric options (#981)
1 parent 44bdbb1 commit 92fd79e

15 files changed

+169
-4
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"php": "^7.2||^8.0",
1616
"guzzlehttp/psr7": "^2.1.1",
1717
"jean85/pretty-package-versions": "^1.5||^2.0",
18-
"sentry/sentry": "^4.19",
18+
"sentry/sentry": "^4.19.1",
1919
"symfony/cache-contracts": "^1.1||^2.4||^3.0",
2020
"symfony/config": "^4.4.20||^5.0.11||^6.0||^7.0||^8.0",
2121
"symfony/console": "^4.4.20||^5.0.11||^6.0||^7.0||^8.0",

phpstan-baseline.neon

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ parameters:
9090
count: 1
9191
path: src/DependencyInjection/SentryExtension.php
9292

93+
-
94+
message: "#^Cannot access offset 'before_send_metric' on mixed\\.$#"
95+
count: 1
96+
path: src/DependencyInjection/SentryExtension.php
97+
9398
-
9499
message: "#^Parameter \\#1 \\$array of function array_filter expects array, mixed given\\.$#"
95100
count: 1
@@ -102,7 +107,7 @@ parameters:
102107

103108
-
104109
message: "#^Parameter \\#1 \\$id of class Symfony\\\\Component\\\\DependencyInjection\\\\Reference constructor expects string, mixed given\\.$#"
105-
count: 11
110+
count: 12
106111
path: src/DependencyInjection/SentryExtension.php
107112

108113
-

src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function getConfigTreeBuilder(): TreeBuilder
8989
->info('The sampling factor to apply to profiles. A value of 0 will deny sending any profiles, and a value of 1 will send all profiles. Profiles are sampled in relation to traces_sample_rate')
9090
->end()
9191
->booleanNode('enable_logs')->end()
92+
->booleanNode('enable_metrics')->defaultTrue()->end()
9293
->booleanNode('attach_stacktrace')->end()
9394
->booleanNode('attach_metric_code_locations')->end()
9495
->integerNode('context_lines')->min(0)->end()
@@ -117,6 +118,7 @@ public function getConfigTreeBuilder(): TreeBuilder
117118
->scalarNode('before_send_check_in')->end()
118119
->scalarNode('before_send_metrics')->end()
119120
->scalarNode('before_send_log')->end()
121+
->scalarNode('before_send_metric')->end()
120122
->variableNode('trace_propagation_targets')->end()
121123
->arrayNode('tags')
122124
->useAttributeAsKey('name')

src/DependencyInjection/SentryExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ private function registerConfiguration(ContainerBuilder $container, array $confi
137137
$options['before_breadcrumb'] = new Reference($options['before_breadcrumb']);
138138
}
139139

140+
if (isset($options['before_send_metric'])) {
141+
$options['before_send_metric'] = new Reference($options['before_send_metric']);
142+
}
143+
140144
if (isset($options['class_serializers'])) {
141145
$options['class_serializers'] = array_map(static function (string $value): Reference {
142146
return new Reference($value);

tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function testProcessConfigurationWithDefaultConfiguration(): void
2727
'options' => [
2828
'integrations' => [],
2929
'prefixes' => array_merge(['%kernel.project_dir%'], array_filter(explode(\PATH_SEPARATOR, get_include_path() ?: ''))),
30+
'enable_metrics' => true,
3031
'environment' => '%kernel.environment%',
3132
'release' => '%env(default::SENTRY_RELEASE)%',
3233
'ignore_exceptions' => [],

tests/DependencyInjection/SentryExtensionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ public function testClientIsCreatedFromOptions(): void
217217
'traces_sampler' => new Reference('App\\Sentry\\Tracing\\TracesSampler'),
218218
'profiles_sample_rate' => 1,
219219
'enable_logs' => true,
220+
'enable_metrics' => true,
220221
'attach_stacktrace' => true,
221222
'attach_metric_code_locations' => true,
222223
'context_lines' => 0,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sentry\SentryBundle\Tests\End2End\App;
6+
7+
use Symfony\Component\Config\Loader\LoaderInterface;
8+
9+
class KernelWithMetricsCallback extends Kernel
10+
{
11+
public function registerContainerConfiguration(LoaderInterface $loader): void
12+
{
13+
parent::registerContainerConfiguration($loader);
14+
15+
$loader->load(__DIR__ . '/metrics.yml');
16+
$loader->load(__DIR__ . '/metrics_with_callback.yml');
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sentry\SentryBundle\Tests\End2End\App;
6+
7+
use Symfony\Component\Config\Loader\LoaderInterface;
8+
9+
class KernelWithMetricsDisabled extends Kernel
10+
{
11+
public function registerContainerConfiguration(LoaderInterface $loader): void
12+
{
13+
parent::registerContainerConfiguration($loader);
14+
15+
$loader->load(__DIR__ . '/metrics.yml');
16+
$loader->load(__DIR__ . '/metrics_disabled.yml');
17+
}
18+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sentry:
2+
options:
3+
enable_metrics: false
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
sentry:
2+
options:
3+
before_send_metric: 'sentry.callback.before_send_metric'
4+
5+
services:
6+
Sentry\SentryBundle\Tests\End2End\Fixtures\SentryCallbacks:
7+
class: 'Sentry\SentryBundle\Tests\End2End\Fixtures\SentryCallbacks'
8+
9+
sentry.callback.before_send_metric:
10+
class: 'Sentry\SentryBundle\Tests\End2End\Fixtures\SentryCallbacks'
11+
factory: ['@Sentry\SentryBundle\Tests\End2End\Fixtures\SentryCallbacks', 'getBeforeSendMetric']
12+

0 commit comments

Comments
 (0)