diff --git a/CHANGELOG.md b/CHANGELOG.md index 352ef2472..aed6c3666 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ - Transaction data are now included in the context ([#2365](https://github.com/getsentry/sentry-ruby/pull/2365)) - Closes [#2364](https://github.com/getsentry/sentry-ruby/issues/2363) +- Include Sentry meta tag in the layout automatically ([#2369](https://github.com/getsentry/sentry-ruby/pull/2369)) + ### Bug Fixes - Fix skipping `connect` spans in open-telemetry [#2364](https://github.com/getsentry/sentry-ruby/pull/2364) diff --git a/sentry-rails/lib/generators/sentry_generator.rb b/sentry-rails/lib/generators/sentry_generator.rb index 76ad3ecf9..de694e40d 100644 --- a/sentry-rails/lib/generators/sentry_generator.rb +++ b/sentry-rails/lib/generators/sentry_generator.rb @@ -3,6 +3,8 @@ class SentryGenerator < ::Rails::Generators::Base class_option :dsn, type: :string, desc: "Sentry DSN" + class_option :inject_meta, type: :boolean, default: true, desc: "Inject meta tag into layout" + def copy_initializer_file dsn = options[:dsn] ? "'#{options[:dsn]}'" : "ENV['SENTRY_DSN']" @@ -16,4 +18,12 @@ def copy_initializer_file end RUBY end + + def inject_code_into_layout + return unless options[:inject_meta] + + inject_into_file "app/views/layouts/application.html.erb", before: "\n" do + " <%= Sentry.get_trace_propagation_meta.html_safe %>\n " + end + end end diff --git a/sentry-rails/spec/sentry/generator_spec.rb b/sentry-rails/spec/sentry/generator_spec.rb index ac4aff730..7da9e12a7 100644 --- a/sentry-rails/spec/sentry/generator_spec.rb +++ b/sentry-rails/spec/sentry/generator_spec.rb @@ -10,8 +10,33 @@ self.destination File.expand_path('../../tmp', __dir__) self.generator_class = described_class + let(:layout_file) do + File.join(destination_root, "app/views/layouts/application.html.erb") + end + before do prepare_destination + + FileUtils.mkdir_p(File.dirname(layout_file)) + + File.write(layout_file, <<~STR) + + +
+