Skip to content

Commit 93ef143

Browse files
committed
Add new options
1 parent e645712 commit 93ef143

File tree

2 files changed

+113
-4
lines changed

2 files changed

+113
-4
lines changed

src/Options.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,7 @@ public function setTracesSampleRate(?float $sampleRate): self
194194

195195
public function getProfilesSampleRate(): ?float
196196
{
197-
/** @var int|float|null $value */
198-
$value = $this->options['profiles_sample_rate'] ?? null;
199-
200-
return $value ?? null;
197+
return $this->options['profiles_sample_rate'];
201198
}
202199

203200
public function setProfilesSampleRate(?float $sampleRate): self
@@ -209,6 +206,34 @@ public function setProfilesSampleRate(?float $sampleRate): self
209206
return $this;
210207
}
211208

209+
public function getProfileSessionSampleRate(): ?float
210+
{
211+
return $this->options['profile_session_sample_rate'];
212+
}
213+
214+
public function setProfileSessionSampleRate(?float $sampleRate): self
215+
{
216+
$options = array_merge($this->options, ['profile_session_sample_rate' => $sampleRate]);
217+
218+
$this->options = $this->resolver->resolve($options);
219+
220+
return $this;
221+
}
222+
223+
public function getProfileLifecycle(): ?string
224+
{
225+
return $this->options['profile_lifecycle'];
226+
}
227+
228+
public function setProfileLifecycle(?string $lifecycle): self
229+
{
230+
$options = array_merge($this->options, ['profile_lifecycle' => $lifecycle]);
231+
232+
$this->options = $this->resolver->resolve($options);
233+
234+
return $this;
235+
}
236+
212237
/**
213238
* Gets whether tracing is enabled or not. The feature is enabled when at
214239
* least one of the `traces_sample_rate` and `traces_sampler` options is
@@ -1223,6 +1248,8 @@ private function configureOptions(OptionsResolver $resolver): void
12231248
'traces_sample_rate' => null,
12241249
'traces_sampler' => null,
12251250
'profiles_sample_rate' => null,
1251+
'profile_session_sample_rate' => null,
1252+
'profile_lifecycle' => null,
12261253
'attach_stacktrace' => false,
12271254
/**
12281255
* @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x.
@@ -1293,6 +1320,8 @@ private function configureOptions(OptionsResolver $resolver): void
12931320
$resolver->setAllowedTypes('traces_sample_rate', ['null', 'int', 'float']);
12941321
$resolver->setAllowedTypes('traces_sampler', ['null', 'callable']);
12951322
$resolver->setAllowedTypes('profiles_sample_rate', ['null', 'int', 'float']);
1323+
$resolver->setAllowedTypes('profile_session_sample_rate', ['null', 'int', 'float']);
1324+
$resolver->setAllowedTypes('profile_lifecycle', ['null', 'string']);
12961325
$resolver->setAllowedTypes('attach_stacktrace', 'bool');
12971326
$resolver->setAllowedTypes('attach_metric_code_locations', 'bool');
12981327
$resolver->setAllowedTypes('context_lines', ['null', 'int']);
@@ -1335,6 +1364,7 @@ private function configureOptions(OptionsResolver $resolver): void
13351364
$resolver->setAllowedTypes('class_serializers', 'array');
13361365

13371366
$resolver->setAllowedValues('max_request_body_size', ['none', 'never', 'small', 'medium', 'always']);
1367+
$resolver->setAllowedValues('profile_lifecycle', [null, 'trace', 'manual']);
13381368
$resolver->setAllowedValues('dsn', \Closure::fromCallable([$this, 'validateDsnOption']));
13391369
$resolver->setAllowedValues('max_breadcrumbs', \Closure::fromCallable([$this, 'validateMaxBreadcrumbsOptions']));
13401370
$resolver->setAllowedValues('class_serializers', \Closure::fromCallable([$this, 'validateClassSerializersOption']));

tests/OptionsTest.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,27 @@ static function (): void {},
138138
'setProfilesSampleRate',
139139
];
140140

141+
yield [
142+
'profile_lifecycle',
143+
'trace',
144+
'getProfileLifecycle',
145+
'setProfileLifecycle',
146+
];
147+
148+
yield [
149+
'profile_lifecycle',
150+
'manual',
151+
'getProfileLifecycle',
152+
'setProfileLifecycle',
153+
];
154+
155+
yield [
156+
'profile_lifecycle',
157+
null,
158+
'getProfileLifecycle',
159+
'setProfileLifecycle',
160+
];
161+
141162
yield [
142163
'attach_stacktrace',
143164
false,
@@ -630,6 +651,64 @@ public static function contextLinesOptionValidatesInputValueDataProvider(): \Gen
630651
];
631652
}
632653

654+
/**
655+
* @dataProvider profileLifecycleOptionValidatesInputValueDataProvider
656+
*/
657+
public function testProfileLifecycleOptionValidatesInputValue($value, ?string $expectedExceptionMessage): void
658+
{
659+
if ($expectedExceptionMessage !== null) {
660+
$this->expectException(InvalidOptionsException::class);
661+
$this->expectExceptionMessage($expectedExceptionMessage);
662+
} else {
663+
$this->expectNotToPerformAssertions();
664+
}
665+
666+
new Options(['profile_lifecycle' => $value]);
667+
}
668+
669+
public static function profileLifecycleOptionValidatesInputValueDataProvider(): \Generator
670+
{
671+
yield [
672+
'trace',
673+
null,
674+
];
675+
676+
yield [
677+
'manual',
678+
null,
679+
];
680+
681+
yield [
682+
null,
683+
null,
684+
];
685+
686+
yield [
687+
'invalid',
688+
'The option "profile_lifecycle" with value "invalid" is invalid.',
689+
];
690+
691+
yield [
692+
'auto',
693+
'The option "profile_lifecycle" with value "auto" is invalid.',
694+
];
695+
696+
yield [
697+
'',
698+
'The option "profile_lifecycle" with value "" is invalid.',
699+
];
700+
701+
yield [
702+
123,
703+
'The option "profile_lifecycle" with value 123 is expected to be of type "null" or "string", but is of type "int".',
704+
];
705+
706+
yield [
707+
true,
708+
'The option "profile_lifecycle" with value true is expected to be of type "null" or "string", but is of type "bool".',
709+
];
710+
}
711+
633712
/**
634713
* @backupGlobals enabled
635714
*/

0 commit comments

Comments
 (0)