@@ -32,7 +32,13 @@ class Client implements ClientInterface
3232 /**
3333 * The version of the SDK.
3434 */
35- public const SDK_VERSION = '4.12.0 ' ;
35+ public const SDK_VERSION = '4.13.0 ' ;
36+
37+ /**
38+ * Regex pattern to detect if a string is a regex pattern (starts and ends with / optionally followed by flags).
39+ * Supported flags: i (case-insensitive), m (multiline), s (dotall), u (unicode).
40+ */
41+ private const REGEX_PATTERN_DETECTION = '/^\/.*\/[imsu]*$/ ' ;
3642
3743 /**
3844 * @var Options The client options
@@ -149,7 +155,7 @@ public function captureMessage(string $message, ?Severity $level = null, ?Scope
149155 public function captureException (\Throwable $ exception , ?Scope $ scope = null , ?EventHint $ hint = null ): ?EventId
150156 {
151157 $ className = \get_class ($ exception );
152- if ($ this ->isIgnoredException ($ className )) {
158+ if ($ this ->shouldIgnoreException ($ className )) {
153159 $ this ->logger ->info (
154160 'The exception will be discarded because it matches an entry in "ignore_exceptions". ' ,
155161 ['className ' => $ className ]
@@ -359,11 +365,64 @@ private function prepareEvent(Event $event, ?EventHint $hint = null, ?Scope $sco
359365 return $ event ;
360366 }
361367
362- private function isIgnoredException (string $ className ): bool
368+ /**
369+ * Checks if an exception should be ignored based on configured patterns.
370+ * Supports both class hierarchy matching and regex patterns.
371+ * Patterns starting and ending with '/' are treated as regex patterns.
372+ */
373+ private function shouldIgnoreException (string $ className ): bool
374+ {
375+ foreach ($ this ->options ->getIgnoreExceptions () as $ pattern ) {
376+ // Check for regex pattern (starts with / and ends with / optionally followed by flags)
377+ if (preg_match (self ::REGEX_PATTERN_DETECTION , $ pattern )) {
378+ try {
379+ if (preg_match ($ pattern , $ className )) {
380+ return true ;
381+ }
382+ } catch (\Throwable $ e ) {
383+ // Invalid regex pattern, log and skip
384+ $ this ->logger ->warning (
385+ \sprintf ('Invalid regex pattern in ignore_exceptions: "%s". Error: %s ' , $ pattern , $ e ->getMessage ())
386+ );
387+ continue ;
388+ }
389+ } else {
390+ // Class hierarchy check
391+ if (is_a ($ className , $ pattern , true )) {
392+ return true ;
393+ }
394+ }
395+ }
396+
397+ return false ;
398+ }
399+
400+ /**
401+ * Checks if a transaction should be ignored based on configured patterns.
402+ * Supports both exact string matching and regex patterns.
403+ * Patterns starting and ending with '/' are treated as regex patterns.
404+ */
405+ private function shouldIgnoreTransaction (string $ transactionName ): bool
363406 {
364- foreach ($ this ->options ->getIgnoreExceptions () as $ ignoredException ) {
365- if (is_a ($ className , $ ignoredException , true )) {
366- return true ;
407+ foreach ($ this ->options ->getIgnoreTransactions () as $ pattern ) {
408+ // Check for regex pattern (starts with / and ends with / optionally followed by flags)
409+ if (preg_match (self ::REGEX_PATTERN_DETECTION , $ pattern )) {
410+ try {
411+ if (preg_match ($ pattern , $ transactionName )) {
412+ return true ;
413+ }
414+ } catch (\Throwable $ e ) {
415+ // Invalid regex pattern, log and skip
416+ $ this ->logger ->warning (
417+ \sprintf ('Invalid regex pattern in ignore_transactions: "%s". Error: %s ' , $ pattern , $ e ->getMessage ())
418+ );
419+ continue ;
420+ }
421+ } else {
422+ // Exact string match
423+ if ($ transactionName === $ pattern ) {
424+ return true ;
425+ }
367426 }
368427 }
369428
@@ -380,7 +439,7 @@ private function applyIgnoreOptions(Event $event, string $eventDescription): ?Ev
380439 }
381440
382441 foreach ($ exceptions as $ exception ) {
383- if ($ this ->isIgnoredException ($ exception ->getType ())) {
442+ if ($ this ->shouldIgnoreException ($ exception ->getType ())) {
384443 $ this ->logger ->info (
385444 \sprintf ('The %s will be discarded because it matches an entry in "ignore_exceptions". ' , $ eventDescription ),
386445 ['event ' => $ event ]
@@ -398,7 +457,7 @@ private function applyIgnoreOptions(Event $event, string $eventDescription): ?Ev
398457 return $ event ;
399458 }
400459
401- if (\in_array ( $ transactionName , $ this ->options -> getIgnoreTransactions (), true )) {
460+ if ($ this ->shouldIgnoreTransaction ( $ transactionName )) {
402461 $ this ->logger ->info (
403462 \sprintf ('The %s will be discarded because it matches a entry in "ignore_transactions". ' , $ eventDescription ),
404463 ['event ' => $ event ]
0 commit comments