Skip to content

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

Add distributed tracing to Sentry (#9181)

Oliver Günther3611c63098a7
diff --git a/app/helpers/sentry_helper.rb b/app/helpers/sentry_helper.rb
new file mode 100644
index 00000000000..139df36d03c
--- /dev/null
+++ b/app/helpers/sentry_helper.rb
@@ -0,0 +1,38 @@
+module SentryHelper
+ def sentry_frontend_tags
+ return '' unless OpenProject::Configuration.sentry_frontend_dsn
+
+ sentry_frontend_dsn_tag + sentry_tracing_meta_tag
+ end
+
+ ##
+ # Communicate the sentry DSN to the frontend
+ # if this instance has enabled JavaScript tracing
+ def sentry_frontend_dsn_tag
+ tag :meta,
+ name: 'openproject_sentry',
+ data: {
+ dsn: OpenProject::Configuration.sentry_frontend_dsn,
+ version: OpenProject::VERSION.to_s,
+ tracing_rate: OpenProject::Configuration.sentry_traces_sample_rate
+ }
+ end
+
+ ##
+ # Meta tag to connect backend request to frontend
+ # https://docs.sentry.io/platforms/javascript/performance/connect-services/ %>
+ def sentry_tracing_meta_tag
+ span_id = current_sentry_tracing_id
+ return '' unless span_id
+
+ tag :meta,
+ name: 'sentry-trace',
+ content: span_id
+ end
+
+ ##
+ # Get the parent sentry tracing id of the current transaction
+ def current_sentry_tracing_id
+ Sentry.get_current_scope&.span&.to_sentry_trace
+ end
+end
diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb
index 626486472af..e6705c8226e 100644
--- a/app/views/layouts/base.html.erb
+++ b/app/views/layouts/base.html.erb
@@ -35,6 +35,7 @@ See docs/COPYRIGHT.rdoc for more details.
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width">
<%= output_title_and_meta_tags %>
+ <%= sentry_frontend_tags %>
<% relative_url_root = OpenProject::Configuration['rails_relative_url_root'] || '' %>
<meta name="app_base_path" content="<%= relative_url_root %>"/>
@@ -52,16 +53,6 @@ See docs/COPYRIGHT.rdoc for more details.
data-id="<%= User.current.id %>" />
<% end %>
- <% if OpenProject::Configuration.sentry_frontend_dsn %>
- <%= tag :meta,
- name: 'openproject_sentry',
- data: {
- dsn: OpenProject::Configuration.sentry_frontend_dsn,
- version: OpenProject::VERSION.to_s,
- tracing_rate: OpenProject::Configuration.sentry_traces_sample_rate
- } %>
- <% end %>
-
<meta name="openproject_initializer"
data-locale="<%= I18n.locale %>"
data-first-week-of-year="<%= locale_first_week_of_year %>"