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
Add request tagging to rails and grape
Oliver Günther7a5efe1e052d
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex e845dde39a1..1336e01bb00 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -132,6 +132,7 @@ class ApplicationController < ActionController::Basebefore_action :user_setup,:set_localization,+ :tag_request,:check_if_login_required,:log_requesting_user,:reset_i18n_fallbacks,@@ -167,6 +168,10 @@ class ApplicationController < ActionController::Baseendend+ def tag_request+ ::OpenProject::Appsignal.tag_request(controller: self, request:)+ end+def reload_mailer_settings!Setting.reload_mailer_settings!enddiff --git a/config/initializers/appsignal.rb b/config/initializers/appsignal.rbindex cc86c93fdc1..e3045507a3d 100644--- a/config/initializers/appsignal.rb+++ b/config/initializers/appsignal.rb@@ -1,6 +1,7 @@require 'open_project/version'+require_relative '../../lib_static/open_project/appsignal'-if ENV['APPSIGNAL_ENABLED'] == 'true'+if OpenProject::Appsignal.enabled?require 'appsignal'OpenProject::Application.configure do |app|config = {diff --git a/lib/api/appsignal_api.rb b/lib/api/appsignal_api.rbindex 898b0704a62..4797c2d9c83 100644--- a/lib/api/appsignal_api.rb+++ b/lib/api/appsignal_api.rb@@ -25,14 +25,12 @@## See COPYRIGHT and LICENSE files for more details.#++-require "appsignal"-require "appsignal/integrations/grape"-module APImodule AppsignalAPIdef self.included(base)base.class_eval do- if Appsignal.active?+ if OpenProject::Appsignal.enabled?+ require "appsignal/integrations/grape"insert_before Grape::Middleware::Error, Appsignal::Grape::Middlewareendenddiff --git a/lib/api/root_api.rb b/lib/api/root_api.rbindex f6b8eb72b55..b1116d51c1f 100644--- a/lib/api/root_api.rb+++ b/lib/api/root_api.rb@@ -258,6 +258,7 @@ module APIauthenticateset_localizationenforce_content_type+ ::OpenProject::Appsignal.tag_request(request:)endendenddiff --git a/lib_static/open_project/appsignal.rb b/lib_static/open_project/appsignal.rbnew file mode 100644index 00000000000..775f9264209--- /dev/null+++ b/lib_static/open_project/appsignal.rb@@ -0,0 +1,59 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module OpenProject+ module Appsignal+ module_function++ def enabled?+ ENV['APPSIGNAL_ENABLED'] == 'true'+ end++ ##+ # Add current user and other stateful tags to appsignal+ # @param context A hash of context, such as passing in the current controller or request+ def tag_request(**context)+ return unless enabled?++ extended = OpenProject::Logging.extend_payload!(default_payload, context)+ ::Appsignal.tag_request(extended)+ end++ ##+ # Default payload to add for appsignal+ def default_payload+ {+ locale: I18n.locale,+ version: OpenProject::VERSION.to_semver,+ core_hash: OpenProject::VERSION.revision,+ core_version: OpenProject::VERSION.core_version,+ product_version: OpenProject::VERSION.product_version+ }.compact+ end+ end+end