OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Enable basic request logging for grape
Oliver Güntherf98e50ccf6bf
diff --git a/Gemfile b/Gemfileindex 09129acf665..bd54cf28450 100644--- a/Gemfile+++ b/Gemfile@@ -295,6 +295,7 @@ gem 'bootsnap', '~> 1.7.0', require: false# API gemsgem 'grape', '~> 1.5.0'+gem 'grape_logging', '~> 1.8.4'gem 'roar', '~> 1.1.0'# CORS for APIdiff --git a/Gemfile.lock b/Gemfile.lockindex 7a780615573..b7e49643f2a 100644--- a/Gemfile.lock+++ b/Gemfile.lock@@ -511,6 +511,9 @@ GEMmustermann-grape (~> 1.0.0)rack (>= 1.3.0)rack-accept+ grape_logging (1.8.4)+ grape+ rackgravatar_image_tag (1.2.0)hashdiff (1.0.1)hashery (2.1.2)@@ -1003,6 +1006,7 @@ DEPENDENCIESfuubar (~> 2.5.0)gon (~> 6.4.0)grape (~> 1.5.0)+ grape_logging (~> 1.8.4)grids!html-pipeline (~> 2.14.0)htmldiffdiff --git a/config/initializers/grape_logging.rb b/config/initializers/grape_logging.rbnew file mode 100644index 00000000000..24ea3fd324c--- /dev/null+++ b/config/initializers/grape_logging.rb@@ -0,0 +1,17 @@+OpenProject::Application.configure do+ config.after_initialize do+ formatter = ::Lograge::Formatters::KeyValue.new++ ActiveSupport::Notifications.subscribe('openproject_grape_logger') do |_, _, _, _, payload|+ time = payload.delete :time+ attributes = {+ duration: time[:total],+ db: time[:db],+ view: time[:view]+ }.merge(payload)++ string = formatter.call(attributes)+ Rails.logger.info string+ end+ end+enddiff --git a/lib/api/root_api.rb b/lib/api/root_api.rbindex 1d71cf492a6..340500d8f88 100644--- a/lib/api/root_api.rb+++ b/lib/api/root_api.rb@@ -39,6 +39,10 @@ module APIinclude OpenProject::Authentication::Scopeextend API::Utilities::GrapeHelper+ insert_before Grape::Middleware::Error,+ ::GrapeLogging::Middleware::RequestLogger,+ { instrumentation_key: 'openproject_grape_logger' }+content_type :json, 'application/json; charset=utf-8'use OpenProject::Authentication::Manager