1212
1313class Sentry extends Adapter
1414{
15+ private const DEFAULT_TIMEOUT = 5 ;
16+
17+ private const DEFAULT_CONNECT_TIMEOUT = 1 ;
18+
1519 /**
1620 * @var string (required, this part of Sentry DSN: 'https://{{THIS_PART}}@blabla.ingest.sentry.io/blabla')
1721 */
@@ -28,14 +32,26 @@ class Sentry extends Adapter
2832 */
2933 protected string $ sentryHost ;
3034
35+ /**
36+ * Timeout (seconds) for the complete request.
37+ */
38+ protected int $ timeout ;
39+
40+ /**
41+ * Timeout (seconds) for establishing the connection.
42+ */
43+ protected int $ connectTimeout ;
44+
3145 /**
3246 * Sentry constructor.
3347 *
3448 * @param string $projectId
3549 * @param string $key
3650 * @param string $host
51+ * @param int $timeout
52+ * @param int $connectTimeout
3753 */
38- public function __construct (string $ projectId , string $ key , string $ host = '' )
54+ public function __construct (string $ projectId , string $ key , string $ host = '' , int $ timeout = self :: DEFAULT_TIMEOUT , int $ connectTimeout = self :: DEFAULT_CONNECT_TIMEOUT )
3955 {
4056 if (empty ($ host )) {
4157 $ host = 'https://sentry.io ' ;
@@ -44,6 +60,8 @@ public function __construct(string $projectId, string $key, string $host = '')
4460 $ this ->sentryHost = $ host ;
4561 $ this ->sentryKey = $ key ;
4662 $ this ->projectId = $ projectId ;
63+ $ this ->timeout = $ timeout > 0 ? $ timeout : self ::DEFAULT_TIMEOUT ;
64+ $ this ->connectTimeout = $ connectTimeout > 0 ? $ connectTimeout : self ::DEFAULT_CONNECT_TIMEOUT ;
4765 }
4866
4967 /**
@@ -141,6 +159,8 @@ public function push(Log $log): int
141159 CURLOPT_RETURNTRANSFER => true ,
142160 CURLOPT_POST => true ,
143161 CURLOPT_POSTFIELDS => \json_encode ($ requestBody ),
162+ CURLOPT_TIMEOUT => $ this ->timeout ,
163+ CURLOPT_CONNECTTIMEOUT => $ this ->connectTimeout ,
144164 CURLOPT_HEADEROPT => \CURLHEADER_UNIFIED ,
145165 CURLOPT_HTTPHEADER => ['Content-Type: application/json ' , 'X-Sentry-Auth: Sentry sentry_version=7, sentry_key= ' .$ this ->sentryKey .', sentry_client=utopia-logger/ ' .Logger::LIBRARY_VERSION ],
146166 ];
0 commit comments