Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Appsignal.set_empty_params! helper method #1332

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .changesets/add-set_empty_params--helper-method.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
bump: patch
type: add
---

Add `Appsignal.set_empty_params!` helper method. This helper method can be used to unset parameters on a transaction and to prevent the Appsignal instrumentation from adding parameters to a transaction.

Example usage:

```ruby
class PaymentsController < ApplicationController
def create
Appsignal.set_empty_params!

# Do things with sensitive parameters
end
end
```

When `Appsignal.add_params` is called afterward, the "empty parameters" state is cleared and any AppSignal instrumentation (if called afterward) will also add parameters again.

```ruby
# Example: Unset parameters when set
Appsignal.add_params("abc" => "def")
# Parameters: { "abc" => "def" }
Appsignal.set_empty_params!
# Parameters: {}

# Example: When AppSignal instrumentation sets parameters:
Appsignal.set_empty_params!
# Parameters: {}
# Pseudo example code:
Appsignal::Instrumentation::SomeLibrary.new.add_params("xyz" => "...")
# Parameters: {}

# Example: Set parameters after them being unset previously
Appsignal.set_empty_params!
# Parameters: {}
Appsignal.add_params("abc" => "def")
# Parameters: { "abc" => "def" }
```
2 changes: 1 addition & 1 deletion lib/appsignal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def stop(called_by = nil)
# # Or for the environment given as an argument
# Appsignal.configure(:production)
#
# @param env [String, Symbol] The environment to load.
# @param env_param [String, Symbol] The environment to load.
# @param root_path [String] The path to look the `config/appsignal.yml` config file in.
# Defaults to the current working directory.
# @yield [Config] Gives the {Config} instance to the block.
Expand Down
15 changes: 12 additions & 3 deletions lib/appsignal/helpers/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,20 @@ def add_params(params = nil, &block)

# Mark the parameters sample data to be set as an empty value.
#
# @api private
# @since 4.0.0
# Use this helper to unset request parameters / background job arguments
# and not report any for this transaction.
#
# If parameters would normally be added by AppSignal instrumentations of
# libraries, these parameters will not be added to the Transaction.
#
# Calling {#add_params} after this helper will add new parameters to the
# transaction.
#
# @since 4.2.0
# @return [void]
#
# @see Helpers::Instrumentation#set_empty_params!
# @see Transaction#set_empty_params!
# @see Transaction#set_params_if_nil
def set_empty_params!
return unless active?
return unless Appsignal::Transaction.current?
Expand Down
Loading