Skip to content

Commit c351aa0

Browse files
committed
Fix Options::setEnableLogs and add Options:: setBeforeSendLogCallback()
1 parent c738238 commit c351aa0

2 files changed

Lines changed: 71 additions & 39 deletions

File tree

src/Options.php

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,29 @@ public function getEnableTracing(): ?bool
155155
return $this->options['enable_tracing'];
156156
}
157157

158+
159+
/**
160+
* Sets if logs should be enabled or not.
161+
*
162+
* @param bool|null $enableLogs Boolean if logs should be enabled or not
163+
*/
164+
public function setEnableLogs(?bool $enableLogs): self
165+
{
166+
$options = array_merge($this->options, ['enable_logs' => $enableLogs]);
167+
168+
$this->options = $this->resolver->resolve($options);
169+
170+
return $this;
171+
}
172+
173+
/**
174+
* Gets if logs is enabled or not.
175+
*/
176+
public function getEnableLogs(): bool
177+
{
178+
return $this->options['enable_logs'] ?? false;
179+
}
180+
158181
/**
159182
* Sets the sampling factor to apply to transactions. A value of 0 will deny
160183
* sending any transactions, and a value of 1 will send 100% of transactions.
@@ -613,6 +636,34 @@ public function setBeforeSendCheckInCallback(callable $callback): self
613636
return $this;
614637
}
615638

639+
/**
640+
* Gets a callback that will be invoked before an log is sent to the server.
641+
* If `null` is returned it won't be sent.
642+
*
643+
* @psalm-return callable(Log): ?Log
644+
*/
645+
public function getBeforeSendLogCallback(): callable
646+
{
647+
return $this->options['before_send_log'];
648+
}
649+
650+
/**
651+
* Sets a callable to be called to decide whether a log should
652+
* be captured or not.
653+
*
654+
* @param callable $callback The callable
655+
*
656+
* @psalm-param callable(Log): ?Log $callback
657+
*/
658+
public function setBeforeSendLogCallback(callable $callback): self
659+
{
660+
$options = array_merge($this->options, ['before_send_log' => $callback]);
661+
662+
$this->options = $this->resolver->resolve($options);
663+
664+
return $this;
665+
}
666+
616667
/**
617668
* Gets a callback that will be invoked before metrics are sent to the server.
618669
* If `null` is returned it won't be sent.
@@ -1153,39 +1204,6 @@ public function setTracesSampler(?callable $sampler): self
11531204
return $this;
11541205
}
11551206

1156-
/**
1157-
* Sets if logs should be enabled or not.
1158-
*
1159-
* @param bool|null $enableLogs Boolean if logs should be enabled or not
1160-
*/
1161-
public function setEnableLogs(?bool $enableLogs): self
1162-
{
1163-
$options = array_merge($this->options, ['enable_tracing' => $enableLogs]);
1164-
1165-
$this->options = $this->resolver->resolve($options);
1166-
1167-
return $this;
1168-
}
1169-
1170-
/**
1171-
* Gets if logs is enabled or not.
1172-
*/
1173-
public function getEnableLogs(): bool
1174-
{
1175-
return $this->options['enable_logs'] ?? false;
1176-
}
1177-
1178-
/**
1179-
* Gets a callback that will be invoked before an log is sent to the server.
1180-
* If `null` is returned it won't be sent.
1181-
*
1182-
* @psalm-return callable(Log): ?Log
1183-
*/
1184-
public function getBeforeSendLogCallback(): callable
1185-
{
1186-
return $this->options['before_send_log'];
1187-
}
1188-
11891207
/**
11901208
* Configures the options of the client.
11911209
*
@@ -1202,6 +1220,7 @@ private function configureOptions(OptionsResolver $resolver): void
12021220
'prefixes' => array_filter(explode(\PATH_SEPARATOR, get_include_path() ?: '')),
12031221
'sample_rate' => 1,
12041222
'enable_tracing' => null,
1223+
'enable_logs' => false,
12051224
'traces_sample_rate' => null,
12061225
'traces_sampler' => null,
12071226
'profiles_sample_rate' => null,
@@ -1233,6 +1252,9 @@ private function configureOptions(OptionsResolver $resolver): void
12331252
'before_send_check_in' => static function (Event $checkIn): Event {
12341253
return $checkIn;
12351254
},
1255+
'before_send_log' => static function (Log $log): Log {
1256+
return $log;
1257+
},
12361258
/**
12371259
* @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x.
12381260
*/
@@ -1263,15 +1285,12 @@ private function configureOptions(OptionsResolver $resolver): void
12631285
'capture_silenced_errors' => false,
12641286
'max_request_body_size' => 'medium',
12651287
'class_serializers' => [],
1266-
'enable_logs' => false,
1267-
'before_send_log' => static function (Log $log): Log {
1268-
return $log;
1269-
},
12701288
]);
12711289

12721290
$resolver->setAllowedTypes('prefixes', 'string[]');
12731291
$resolver->setAllowedTypes('sample_rate', ['int', 'float']);
12741292
$resolver->setAllowedTypes('enable_tracing', ['null', 'bool']);
1293+
$resolver->setAllowedTypes('enable_logs', 'bool');
12751294
$resolver->setAllowedTypes('traces_sample_rate', ['null', 'int', 'float']);
12761295
$resolver->setAllowedTypes('traces_sampler', ['null', 'callable']);
12771296
$resolver->setAllowedTypes('profiles_sample_rate', ['null', 'int', 'float']);
@@ -1290,6 +1309,7 @@ private function configureOptions(OptionsResolver $resolver): void
12901309
$resolver->setAllowedTypes('server_name', 'string');
12911310
$resolver->setAllowedTypes('before_send', ['callable']);
12921311
$resolver->setAllowedTypes('before_send_transaction', ['callable']);
1312+
$resolver->setAllowedTypes('before_send_log', 'callable');
12931313
$resolver->setAllowedTypes('ignore_exceptions', 'string[]');
12941314
$resolver->setAllowedTypes('ignore_transactions', 'string[]');
12951315
$resolver->setAllowedTypes('trace_propagation_targets', ['null', 'string[]']);
@@ -1313,8 +1333,6 @@ private function configureOptions(OptionsResolver $resolver): void
13131333
$resolver->setAllowedTypes('capture_silenced_errors', 'bool');
13141334
$resolver->setAllowedTypes('max_request_body_size', 'string');
13151335
$resolver->setAllowedTypes('class_serializers', 'array');
1316-
$resolver->setAllowedTypes('enable_logs', 'bool');
1317-
$resolver->setAllowedTypes('before_send_log', 'callable');
13181336

13191337
$resolver->setAllowedValues('max_request_body_size', ['none', 'never', 'small', 'medium', 'always']);
13201338
$resolver->setAllowedValues('dsn', \Closure::fromCallable([$this, 'validateDsnOption']));

tests/OptionsTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ public static function optionsDataProvider(): \Generator
9696
'setSampleRate',
9797
];
9898

99+
yield [
100+
'enable_logs',
101+
true,
102+
'getEnableLogs',
103+
'setEnableLogs',
104+
];
105+
99106
yield [
100107
'traces_sample_rate',
101108
0.5,
@@ -264,6 +271,13 @@ static function (): void {},
264271
'setBeforeSendCheckInCallback',
265272
];
266273

274+
yield [
275+
'before_send_log',
276+
static function (): void {},
277+
'getBeforeSendLogCallback',
278+
'setBeforeSendLogCallback',
279+
];
280+
267281
yield [
268282
'before_send_metrics',
269283
static function (): void {},

0 commit comments

Comments
 (0)