Skip to content

Commit ddfcbbe

Browse files
authored
feat: Add profiles_sample_rate (#698)
1 parent 573794a commit ddfcbbe

File tree

9 files changed

+80
-1
lines changed

9 files changed

+80
-1
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"php": "^7.2||^8.0",
2727
"jean85/pretty-package-versions": "^1.5 || ^2.0",
2828
"sentry/sdk": "^3.3",
29-
"sentry/sentry": "^3.12",
29+
"sentry/sentry": "^3.15",
3030
"symfony/cache-contracts": "^1.1||^2.4||^3.0",
3131
"symfony/config": "^4.4.20||^5.0.11||^6.0",
3232
"symfony/console": "^4.4.20||^5.0.11||^6.0",

phpstan-baseline.neon

+5
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@ parameters:
260260
count: 1
261261
path: src/Tracing/HttpClient/TraceableResponseForV6.php
262262

263+
-
264+
message: "#^Cannot access offset 'profiles_sample_rate' on mixed\\.$#"
265+
count: 1
266+
path: tests/DependencyInjection/ConfigurationTest.php
267+
263268
-
264269
message: "#^Cannot access offset 'sample_rate' on mixed\\.$#"
265270
count: 1

src/DependencyInjection/Configuration.php

+5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public function getConfigTreeBuilder(): TreeBuilder
7373
->max(1.0)
7474
->info('The sampling factor to apply to transactions. A value of 0 will deny sending any transaction, and a value of 1 will send all transactions.')
7575
->end()
76+
->floatNode('profiles_sample_rate')
77+
->min(0.0)
78+
->max(1.0)
79+
->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')
80+
->end()
7681
->scalarNode('traces_sampler')->end()
7782
->arrayNode('trace_propagation_targets')
7883
->scalarPrototype()->end()

src/Resources/config/schema/sentry-1.0.xsd

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<xsd:attribute name="send-attempts" type="xsd:integer" />
3737
<xsd:attribute name="sample-rate" type="xsd:float" />
3838
<xsd:attribute name="traces-sample-rate" type="xsd:float" />
39+
<xsd:attribute name="profiles-sample-rate" type="xsd:float" />
3940
<xsd:attribute name="traces-sampler" type="xsd:string" />
4041
<xsd:attribute name="attach-stacktrace" type="xsd:boolean" />
4142
<xsd:attribute name="context-lines" type="xsd:integer" />

tests/DependencyInjection/ConfigurationTest.php

+64
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,70 @@ public function tracesSampleRateOptionWithInvalidValuesDataProvider(): \Generato
195195
];
196196
}
197197

198+
/**
199+
* @param int|float $value
200+
*
201+
* @dataProvider profilesSampleRateOptionDataProvider
202+
*/
203+
public function testProfilesSampleRateOption($value): void
204+
{
205+
$config = $this->processConfiguration(['options' => ['profiles_sample_rate' => $value]]);
206+
207+
$this->assertSame($value, $config['options']['profiles_sample_rate']);
208+
}
209+
210+
/**
211+
* @return \Generator<mixed>
212+
*/
213+
public function profilesSampleRateOptionDataProvider(): \Generator
214+
{
215+
yield [0];
216+
yield [1];
217+
yield [0.0];
218+
yield [1.0];
219+
yield [0.01];
220+
yield [0.9];
221+
}
222+
223+
/**
224+
* @param int|float $value
225+
*
226+
* @dataProvider profilesSampleRateOptionWithInvalidValuesDataProvider
227+
*/
228+
public function testProfilesSampleRateOptionWithInvalidValues($value, string $exceptionMessage): void
229+
{
230+
$this->expectException(InvalidConfigurationException::class);
231+
$this->expectExceptionMessage($exceptionMessage);
232+
233+
$this->processConfiguration(['options' => ['profiles_sample_rate' => $value]]);
234+
}
235+
236+
/**
237+
* @return \Generator<mixed>
238+
*/
239+
public function profilesSampleRateOptionWithInvalidValuesDataProvider(): \Generator
240+
{
241+
yield [
242+
-1,
243+
'The value -1 is too small for path "sentry.options.profiles_sample_rate". Should be greater than or equal to 0',
244+
];
245+
246+
yield [
247+
2,
248+
'The value 2 is too big for path "sentry.options.profiles_sample_rate". Should be less than or equal to 1',
249+
];
250+
251+
yield [
252+
-0.1,
253+
'The value -0.1 is too small for path "sentry.options.profiles_sample_rate". Should be greater than or equal to 0',
254+
];
255+
256+
yield [
257+
1.01,
258+
'The value 1.01 is too big for path "sentry.options.profiles_sample_rate". Should be less than or equal to 1',
259+
];
260+
}
261+
198262
/**
199263
* @param array<string, mixed> $values
200264
*

tests/DependencyInjection/Fixtures/php/full.php

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
'prefixes' => ['%kernel.project_dir%'],
1717
'sample_rate' => 1,
1818
'traces_sample_rate' => 1,
19+
'profiles_sample_rate' => 1,
1920
'traces_sampler' => 'App\\Sentry\\Tracing\\TracesSampler',
2021
'trace_propagation_targets' => ['website.invalid'],
2122
'attach_stacktrace' => true,

tests/DependencyInjection/Fixtures/xml/full.xml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
send-attempts="1"
1616
sample-rate="1"
1717
traces-sample-rate="1"
18+
profiles-sample-rate="1"
1819
traces-sampler="App\Sentry\Tracing\TracesSampler"
1920
attach-stacktrace="true"
2021
context-lines="0"

tests/DependencyInjection/Fixtures/yml/full.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ sentry:
1111
- '%kernel.project_dir%'
1212
sample_rate: 1
1313
traces_sample_rate: 1
14+
profiles_sample_rate: 1
1415
traces_sampler: App\Sentry\Tracing\TracesSampler
1516
trace_propagation_targets:
1617
- 'website.invalid'

tests/DependencyInjection/SentryExtensionTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ public function testClientIsCreatedFromOptions(): void
204204
'prefixes' => [$container->getParameter('kernel.project_dir')],
205205
'sample_rate' => 1,
206206
'traces_sample_rate' => 1,
207+
'profiles_sample_rate' => 1,
207208
'traces_sampler' => new Reference('App\\Sentry\\Tracing\\TracesSampler'),
208209
'trace_propagation_targets' => ['website.invalid'],
209210
'attach_stacktrace' => true,

0 commit comments

Comments
 (0)