3
3
namespace Sentry \Laravel \Tracing ;
4
4
5
5
use Closure ;
6
- use Illuminate \Contracts \Foundation \Application ;
6
+ use Illuminate \Contracts \Foundation \Application as LaravelApplication ;
7
7
use Illuminate \Http \Request ;
8
+ use Laravel \Lumen \Application as LumenApplication ;
8
9
use Sentry \SentrySdk ;
9
10
use Sentry \State \HubInterface ;
10
11
use Sentry \Tracing \Span ;
@@ -37,9 +38,9 @@ class Middleware
37
38
private $ bootedTimestamp ;
38
39
39
40
/**
40
- * The Laravel application instance.
41
+ * The Laravel or Lumen application instance.
41
42
*
42
- * @var Application|null
43
+ * @var LaravelApplication|LumenApplication
43
44
*/
44
45
private $ app ;
45
46
@@ -53,9 +54,9 @@ class Middleware
53
54
/**
54
55
* Construct the Sentry tracing middleware.
55
56
*
56
- * @param Application|null $app
57
+ * @param LaravelApplication|LumenApplication $app
57
58
*/
58
- public function __construct (? Application $ app )
59
+ public function __construct ($ app )
59
60
{
60
61
$ this ->app = $ app ;
61
62
}
@@ -106,26 +107,22 @@ public function terminate(Request $request, $response): void
106
107
$ this ->hydrateResponseData ($ response );
107
108
}
108
109
109
- if ($ this ->app === null ) {
110
- $ this ->finishTransaction ();
111
- } else {
112
- // Ensure we do not register the terminating callback multiple times since there is no point in doing so
113
- if ($ this ->registeredTerminatingCallback ) {
114
- return ;
115
- }
116
-
117
- // We need to finish the transaction after the response has been sent to the client
118
- // so we register a terminating callback to do so, this allows us to also capture
119
- // spans that are created during the termination of the application like queue
120
- // dispatched using dispatch(...)->afterResponse(). This middleware is called
121
- // before the terminating callbacks so we are 99.9% sure to be the last one
122
- // to run except if another terminating callback is registered after ours.
123
- $ this ->app ->terminating (function () {
124
- $ this ->finishTransaction ();
125
- });
126
-
127
- $ this ->registeredTerminatingCallback = true ;
110
+ // Ensure we do not register the terminating callback multiple times since there is no point in doing so
111
+ if ($ this ->registeredTerminatingCallback ) {
112
+ return ;
128
113
}
114
+
115
+ // We need to finish the transaction after the response has been sent to the client
116
+ // so we register a terminating callback to do so, this allows us to also capture
117
+ // spans that are created during the termination of the application like queue
118
+ // dispatched using dispatch(...)->afterResponse(). This middleware is called
119
+ // before the terminating callbacks so we are 99.9% sure to be the last one
120
+ // to run except if another terminating callback is registered after ours.
121
+ $ this ->app ->terminating (function () {
122
+ $ this ->finishTransaction ();
123
+ });
124
+
125
+ $ this ->registeredTerminatingCallback = true ;
129
126
}
130
127
131
128
/**
0 commit comments