From ce434b2c1d14736c910dd838f9fa2073160b90cd Mon Sep 17 00:00:00 2001 From: Tom de Bruijn Date: Mon, 11 Nov 2024 14:25:32 +0100 Subject: [PATCH 1/3] Fix API docs for Appsignal.configure method I renamed this argument and didn't update the docs. --- lib/appsignal.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/appsignal.rb b/lib/appsignal.rb index dcf39887..2a74fef9 100644 --- a/lib/appsignal.rb +++ b/lib/appsignal.rb @@ -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. From 20a8050e63605f08e9377dda84b3a422810dd49a Mon Sep 17 00:00:00 2001 From: Tom de Bruijn Date: Mon, 11 Nov 2024 14:31:49 +0100 Subject: [PATCH 2/3] Document Appsignal.set_empty_params! helper method Make this method public now that we've had someone ask for it. Previously it was kept private because we were the only ones using it and I wasn't quite sure of the implementation. I don't know of a better implementation so let's make it public. --- .../add-set_empty_params--helper-method.md | 41 +++++++++++++++++++ lib/appsignal/helpers/instrumentation.rb | 15 +++++-- 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 .changesets/add-set_empty_params--helper-method.md diff --git a/.changesets/add-set_empty_params--helper-method.md b/.changesets/add-set_empty_params--helper-method.md new file mode 100644 index 00000000..ac265f33 --- /dev/null +++ b/.changesets/add-set_empty_params--helper-method.md @@ -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: {} +# Example code: +Appsignal::Instrumtation::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" } +``` diff --git a/lib/appsignal/helpers/instrumentation.rb b/lib/appsignal/helpers/instrumentation.rb index df4c1f1f..6bb3ce86 100644 --- a/lib/appsignal/helpers/instrumentation.rb +++ b/lib/appsignal/helpers/instrumentation.rb @@ -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? From 23627cd7e7c2b2939c43701228e77aa14eae5c68 Mon Sep 17 00:00:00 2001 From: Tom de Bruijn Date: Mon, 11 Nov 2024 15:01:55 +0100 Subject: [PATCH 3/3] Update changeset example code Fix typo in the example module name. --- .changesets/add-set_empty_params--helper-method.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changesets/add-set_empty_params--helper-method.md b/.changesets/add-set_empty_params--helper-method.md index ac265f33..d9d55121 100644 --- a/.changesets/add-set_empty_params--helper-method.md +++ b/.changesets/add-set_empty_params--helper-method.md @@ -29,8 +29,8 @@ Appsignal.set_empty_params! # Example: When AppSignal instrumentation sets parameters: Appsignal.set_empty_params! # Parameters: {} -# Example code: -Appsignal::Instrumtation::SomeLibrary.new.add_params("xyz" => "...") +# Pseudo example code: +Appsignal::Instrumentation::SomeLibrary.new.add_params("xyz" => "...") # Parameters: {} # Example: Set parameters after them being unset previously