From 4ab3906d0a006c2b441db304e39c7c920a51d43f Mon Sep 17 00:00:00 2001 From: Jeremy Prevost Date: Thu, 20 Aug 2026 11:39:44 -0400 Subject: [PATCH] Stop logging GraphQL query and adds searchterm log Why are these changes being introduced: * Our logs were inclidng the full graphql query (twice) * This was excessively long and taking up a lot of space in our logs Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/TIMX-677 How does this address that need: * Suppresses logging the graphql query and extracts and logs just the search term Document any side effects to this change: * When we move to structured logging, we'll want to include the search term as a field and not a separate logline. That is out of scope of this work but will come soon as we move from Logz to CloudWatch --- app/graphql/types/query_type.rb | 8 ++++++++ config/initializers/filter_parameter_logging.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index c866ed5..2718573 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -115,6 +115,8 @@ def record_id(id:, index:) def search(searchterm:, citation:, contributors:, funding_information:, geodistance:, geobox:, identifiers:, locations:, subjects:, title:, index:, source:, from:, boolean_type:, fulltext:, per_page: 20, query_mode: 'keyword', use_global_scoring: false, tuning_parameters_input: nil, **filters) + Rails.logger.info("Searchterm: #{format_searchterm_for_log(searchterm)}") + query = construct_query(searchterm, citation, contributors, funding_information, geodistance, geobox, identifiers, locations, subjects, title, source, boolean_type, filters, per_page, query_mode) @@ -204,6 +206,12 @@ def source_deprecation_handler(query, new_source, old_source) query end + def format_searchterm_for_log(searchterm) + return '[missing]' if searchterm.blank? + + searchterm.to_s.truncate(200) + end + def validate_and_build_semantic_options(tuning_parameters) return {} if tuning_parameters.blank? diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index c0b717f..306ed87 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -4,5 +4,5 @@ # Use this to limit dissemination of sensitive information. # See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. Rails.application.config.filter_parameters += [ - :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn, :cvv, :cvc + :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn, :cvv, :cvc, :query ]