diff --git a/src/Options.php b/src/Options.php index b4f9ba3ed..f1e0bffc0 100644 --- a/src/Options.php +++ b/src/Options.php @@ -155,6 +155,28 @@ public function getEnableTracing(): ?bool return $this->options['enable_tracing']; } + /** + * Sets if logs should be enabled or not. + * + * @param bool|null $enableLogs Boolean if logs should be enabled or not + */ + public function setEnableLogs(?bool $enableLogs): self + { + $options = array_merge($this->options, ['enable_logs' => $enableLogs]); + + $this->options = $this->resolver->resolve($options); + + return $this; + } + + /** + * Gets if logs is enabled or not. + */ + public function getEnableLogs(): bool + { + return $this->options['enable_logs'] ?? false; + } + /** * Sets the sampling factor to apply to transactions. A value of 0 will deny * sending any transactions, and a value of 1 will send 100% of transactions. @@ -613,6 +635,34 @@ public function setBeforeSendCheckInCallback(callable $callback): self return $this; } + /** + * Gets a callback that will be invoked before an log is sent to the server. + * If `null` is returned it won't be sent. + * + * @psalm-return callable(Log): ?Log + */ + public function getBeforeSendLogCallback(): callable + { + return $this->options['before_send_log']; + } + + /** + * Sets a callable to be called to decide whether a log should + * be captured or not. + * + * @param callable $callback The callable + * + * @psalm-param callable(Log): ?Log $callback + */ + public function setBeforeSendLogCallback(callable $callback): self + { + $options = array_merge($this->options, ['before_send_log' => $callback]); + + $this->options = $this->resolver->resolve($options); + + return $this; + } + /** * Gets a callback that will be invoked before metrics are sent to the server. * If `null` is returned it won't be sent. @@ -1153,39 +1203,6 @@ public function setTracesSampler(?callable $sampler): self return $this; } - /** - * Sets if logs should be enabled or not. - * - * @param bool|null $enableLogs Boolean if logs should be enabled or not - */ - public function setEnableLogs(?bool $enableLogs): self - { - $options = array_merge($this->options, ['enable_tracing' => $enableLogs]); - - $this->options = $this->resolver->resolve($options); - - return $this; - } - - /** - * Gets if logs is enabled or not. - */ - public function getEnableLogs(): bool - { - return $this->options['enable_logs'] ?? false; - } - - /** - * Gets a callback that will be invoked before an log is sent to the server. - * If `null` is returned it won't be sent. - * - * @psalm-return callable(Log): ?Log - */ - public function getBeforeSendLogCallback(): callable - { - return $this->options['before_send_log']; - } - /** * Configures the options of the client. * @@ -1202,6 +1219,7 @@ private function configureOptions(OptionsResolver $resolver): void 'prefixes' => array_filter(explode(\PATH_SEPARATOR, get_include_path() ?: '')), 'sample_rate' => 1, 'enable_tracing' => null, + 'enable_logs' => false, 'traces_sample_rate' => null, 'traces_sampler' => null, 'profiles_sample_rate' => null, @@ -1233,6 +1251,9 @@ private function configureOptions(OptionsResolver $resolver): void 'before_send_check_in' => static function (Event $checkIn): Event { return $checkIn; }, + 'before_send_log' => static function (Log $log): Log { + return $log; + }, /** * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. */ @@ -1263,15 +1284,12 @@ private function configureOptions(OptionsResolver $resolver): void 'capture_silenced_errors' => false, 'max_request_body_size' => 'medium', 'class_serializers' => [], - 'enable_logs' => false, - 'before_send_log' => static function (Log $log): Log { - return $log; - }, ]); $resolver->setAllowedTypes('prefixes', 'string[]'); $resolver->setAllowedTypes('sample_rate', ['int', 'float']); $resolver->setAllowedTypes('enable_tracing', ['null', 'bool']); + $resolver->setAllowedTypes('enable_logs', 'bool'); $resolver->setAllowedTypes('traces_sample_rate', ['null', 'int', 'float']); $resolver->setAllowedTypes('traces_sampler', ['null', 'callable']); $resolver->setAllowedTypes('profiles_sample_rate', ['null', 'int', 'float']); @@ -1290,6 +1308,7 @@ private function configureOptions(OptionsResolver $resolver): void $resolver->setAllowedTypes('server_name', 'string'); $resolver->setAllowedTypes('before_send', ['callable']); $resolver->setAllowedTypes('before_send_transaction', ['callable']); + $resolver->setAllowedTypes('before_send_log', 'callable'); $resolver->setAllowedTypes('ignore_exceptions', 'string[]'); $resolver->setAllowedTypes('ignore_transactions', 'string[]'); $resolver->setAllowedTypes('trace_propagation_targets', ['null', 'string[]']); @@ -1313,8 +1332,6 @@ private function configureOptions(OptionsResolver $resolver): void $resolver->setAllowedTypes('capture_silenced_errors', 'bool'); $resolver->setAllowedTypes('max_request_body_size', 'string'); $resolver->setAllowedTypes('class_serializers', 'array'); - $resolver->setAllowedTypes('enable_logs', 'bool'); - $resolver->setAllowedTypes('before_send_log', 'callable'); $resolver->setAllowedValues('max_request_body_size', ['none', 'never', 'small', 'medium', 'always']); $resolver->setAllowedValues('dsn', \Closure::fromCallable([$this, 'validateDsnOption'])); diff --git a/tests/OptionsTest.php b/tests/OptionsTest.php index dd47ca778..4192781a0 100644 --- a/tests/OptionsTest.php +++ b/tests/OptionsTest.php @@ -96,6 +96,13 @@ public static function optionsDataProvider(): \Generator 'setSampleRate', ]; + yield [ + 'enable_logs', + true, + 'getEnableLogs', + 'setEnableLogs', + ]; + yield [ 'traces_sample_rate', 0.5, @@ -264,6 +271,13 @@ static function (): void {}, 'setBeforeSendCheckInCallback', ]; + yield [ + 'before_send_log', + static function (): void {}, + 'getBeforeSendLogCallback', + 'setBeforeSendLogCallback', + ]; + yield [ 'before_send_metrics', static function (): void {},