Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include Sentry meta tag in the layout automatically #2369

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,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)
Expand Down
6 changes: 6 additions & 0 deletions sentry-rails/lib/generators/sentry_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ def copy_initializer_file
end
RUBY
end

def inject_code_into_layout
inject_into_file "app/views/layouts/application.html.erb", before: "</head>\n" do
solnic marked this conversation as resolved.
Show resolved Hide resolved
" <%= Sentry.get_trace_propagation_meta.html_safe %>\n "
end
end
end
33 changes: 33 additions & 0 deletions sentry-rails/spec/sentry/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<!DOCTYPE html>
<html>
<head>
<title>SentryTesting</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
</head>

<body>
<%= yield %>
</body>
</html>
STR
end

it "creates a initializer file" do
Expand All @@ -29,6 +54,14 @@
RUBY
end

it "injects meta tag into the layout" do
run_generator

content = File.read(layout_file)

expect(content).to include("Sentry.get_trace_propagation_meta.html_safe")
end

context "with a DSN option" do
it "creates a initializer file with the DSN" do
run_generator %w[--dsn foobarbaz]
Expand Down
2 changes: 2 additions & 0 deletions sentry-sidekiq/spec/sentry/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
require "sentry-rails"
require "spec_helper"

require "action_controller/railtie"

class TestApp < Rails::Application
end

Expand Down
Loading