-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move delayed transaction finisher state out of middleware (#936)
* Move delayed transaction finisher state out of middleware * Update comment
- Loading branch information
1 parent
6d916ca
commit 72b6731
Showing
3 changed files
with
39 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Sentry\Laravel\Tracing; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class TransactionFinisher | ||
{ | ||
public function __construct() | ||
{ | ||
// We need to finish the transaction after the response has been sent to the client | ||
// so we register a terminating callback to do so, this allows us to also capture | ||
// spans that are created during the termination of the application like queue | ||
// dispatches using dispatch(...)->afterResponse() which are terminating | ||
// callbacks themselfs just like we do below. | ||
// | ||
// This class is registered as a singleton in the container to ensure it's only | ||
// instantiated once and the terminating callback is only registered once. | ||
// | ||
// It should be resolved from the container before the terminating callbacks are called. | ||
// Good place is in the `terminate` callback of a middleware for example. | ||
// This way we can be 99.9% sure to be the last ones to run. | ||
app()->terminating(function () { | ||
app(Middleware::class)->finishTransaction(); | ||
}); | ||
} | ||
} |