-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize setting parameters for transactions
With the recent refactoring of the Rack middleware, I changed how we set the request parameters on the transaction. Previously, we read the parameters from the request object in the transaction when we sampled it. Not always. Now that we use the currently active transaction when a transaction is already active, I needed to update how we set parameters using the `set_params`/`set_params_if_nil` helpers. These helper methods require us to pass in the parsed parameters, potentially making every request slower because it has to fetch and parse the request parameters. Add a block argument to the `set_params`/`set_params_if_nil` helpers to fetch and parse the parameters only when we sample the transaction. This change should reduce the AppSignal overhead for non-sampled transactions. I have no specific preference if the argument or block is leading. I chose the argument to be leading.
- Loading branch information
Showing
5 changed files
with
79 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
bump: patch | ||
type: add | ||
--- | ||
|
||
Add a block argument to the `Appsignal.set_params` and `Appsignal::Transaction#set_params` helpers. When `set_params` is called with a block argument, the block is executed when the parameters are stored on the Transaction. This block is only called when the Transaction is sampled. Use this block argument to avoid having to parse parameters for every transaction, even when it's not sampled. | ||
|
||
```ruby | ||
Appsignal.set_params do | ||
# Some slow code to parse parameters | ||
JSON.parse('{"param1": "value1"}') | ||
end | ||
``` |
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
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