@@ -73,7 +73,7 @@ public function __construct(bool $continueAfterResponse = true)
73
73
public function handle (Request $ request , Closure $ next )
74
74
{
75
75
if (app ()->bound (HubInterface::class)) {
76
- $ this ->startTransaction ($ request, app (HubInterface::class) );
76
+ $ this ->startTransaction ($ request );
77
77
}
78
78
79
79
return $ next ($ request );
@@ -89,12 +89,14 @@ public function handle(Request $request, Closure $next)
89
89
*/
90
90
public function terminate (Request $ request , $ response ): void
91
91
{
92
- // If there is no transaction or the HubInterface is not bound in the container there is nothing for us to do
93
- if ($ this ->transaction === null || ! app ()-> bound (HubInterface::class) ) {
92
+ // If there is no transaction there is nothing for us to do
93
+ if ($ this ->transaction === null ) {
94
94
return ;
95
95
}
96
96
97
97
if ($ this ->shouldRouteBeIgnored ($ request )) {
98
+ $ this ->discardTransaction ();
99
+
98
100
return ;
99
101
}
100
102
@@ -132,10 +134,12 @@ public function setBootedTimestamp(?float $timestamp = null): void
132
134
$ this ->bootedTimestamp = $ timestamp ?? microtime (true );
133
135
}
134
136
135
- private function startTransaction (Request $ request, HubInterface $ sentry ): void
137
+ private function startTransaction (Request $ request ): void
136
138
{
139
+ $ hub = SentrySdk::getCurrentHub ();
140
+
137
141
// Prevent starting a new transaction if we are already in a transaction
138
- if ($ sentry ->getTransaction () !== null ) {
142
+ if ($ hub ->getTransaction () !== null ) {
139
143
return ;
140
144
}
141
145
@@ -168,9 +172,9 @@ private function startTransaction(Request $request, HubInterface $sentry): void
168
172
'http.request.method ' => strtoupper ($ request ->method ()),
169
173
]);
170
174
171
- $ transaction = $ sentry ->startTransaction ($ context );
175
+ $ transaction = $ hub ->startTransaction ($ context );
172
176
173
- SentrySdk:: getCurrentHub () ->setSpan ($ transaction );
177
+ $ hub ->setSpan ($ transaction );
174
178
175
179
// If this transaction is not sampled, we can stop here to prevent doing work for nothing
176
180
if (!$ transaction ->getSampled ()) {
@@ -188,7 +192,17 @@ private function startTransaction(Request $request, HubInterface $sentry): void
188
192
->setStartTimestamp ($ bootstrapSpan ? $ bootstrapSpan ->getEndTimestamp () : microtime (true ))
189
193
);
190
194
191
- SentrySdk::getCurrentHub ()->setSpan ($ this ->appSpan );
195
+ $ hub ->setSpan ($ this ->appSpan );
196
+ }
197
+
198
+ private function discardTransaction (): void
199
+ {
200
+ $ this ->appSpan = null ;
201
+ $ this ->transaction = null ;
202
+ $ this ->didRouteMatch = false ;
203
+ $ this ->bootedTimestamp = null ;
204
+
205
+ SentrySdk::getCurrentHub ()->setSpan (null );
192
206
}
193
207
194
208
private function addAppBootstrapSpan (): ?Span
0 commit comments