@@ -35,6 +35,9 @@ class EventHandler
35
35
HttpClientEvents \RequestSending::class => 'httpClientRequestSending ' ,
36
36
HttpClientEvents \ResponseReceived::class => 'httpClientResponseReceived ' ,
37
37
HttpClientEvents \ConnectionFailed::class => 'httpClientConnectionFailed ' ,
38
+ DatabaseEvents \TransactionBeginning::class => 'transactionBeginning ' ,
39
+ DatabaseEvents \TransactionCommitted::class => 'transactionCommitted ' ,
40
+ DatabaseEvents \TransactionRolledBack::class => 'transactionRolledBack ' ,
38
41
];
39
42
40
43
/**
@@ -116,6 +119,9 @@ public function __construct(array $config, BacktraceHelper $backtraceHelper)
116
119
*
117
120
* @uses self::routeMatchedHandler()
118
121
* @uses self::queryExecutedHandler()
122
+ * @uses self::transactionBeginningHandler()
123
+ * @uses self::transactionCommittedHandler()
124
+ * @uses self::transactionRolledBackHandler()
119
125
* @uses self::httpClientRequestSendingHandler()
120
126
* @uses self::httpClientResponseReceivedHandler()
121
127
* @uses self::httpClientConnectionFailedHandler()
@@ -240,6 +246,40 @@ private function resolveQueryOriginFromBacktrace(): ?string
240
246
return "{$ filePath }: {$ firstAppFrame ->getLine ()}" ;
241
247
}
242
248
249
+ protected function transactionBeginningHandler (DatabaseEvents \TransactionBeginning $ event ): void
250
+ {
251
+ $ parentSpan = SentrySdk::getCurrentHub ()->getSpan ();
252
+
253
+ if ($ parentSpan === null ) {
254
+ return ;
255
+ }
256
+
257
+ $ context = new SpanContext ;
258
+ $ context ->setOp ('db.transaction ' );
259
+
260
+ $ this ->pushSpan ($ parentSpan ->startChild ($ context ));
261
+ }
262
+
263
+ protected function transactionCommittedHandler (DatabaseEvents \TransactionCommitted $ event ): void
264
+ {
265
+ $ span = $ this ->popSpan ();
266
+
267
+ if ($ span !== null ) {
268
+ $ span ->finish ();
269
+ $ span ->setStatus (SpanStatus::ok ());
270
+ }
271
+ }
272
+
273
+ protected function transactionRolledBackHandler (DatabaseEvents \TransactionRolledBack $ event ): void
274
+ {
275
+ $ span = $ this ->popSpan ();
276
+
277
+ if ($ span !== null ) {
278
+ $ span ->finish ();
279
+ $ span ->setStatus (SpanStatus::internalError ());
280
+ }
281
+ }
282
+
243
283
protected function httpClientRequestSendingHandler (HttpClientEvents \RequestSending $ event ): void
244
284
{
245
285
$ parentSpan = SentrySdk::getCurrentHub ()->getSpan ();
@@ -252,7 +292,6 @@ protected function httpClientRequestSendingHandler(HttpClientEvents\RequestSendi
252
292
253
293
$ context ->setOp ('http.client ' );
254
294
$ context ->setDescription ($ event ->request ->method () . ' ' . $ event ->request ->url ());
255
- $ context ->setStartTimestamp (microtime (true ));
256
295
257
296
$ this ->pushSpan ($ parentSpan ->startChild ($ context ));
258
297
}
0 commit comments