Class: SentryGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/sentry_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_initializer_fileObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/generators/sentry_generator.rb', line 10

def copy_initializer_file
  dsn = options[:dsn] ? "'#{options[:dsn]}'" : "ENV['SENTRY_DSN']"

  create_file "config/initializers/sentry.rb", <<~RUBY
    # frozen_string_literal: true

    Sentry.init do |config|
      config.breadcrumbs_logger = [:active_support_logger]
      config.dsn = #{dsn}
      config.enable_tracing = true
    end
  RUBY
end

#inject_code_into_layoutObject



24
25
26
27
28
29
30
# File 'lib/generators/sentry_generator.rb', line 24

def inject_code_into_layout
  return unless options[:inject_meta]

  inject_into_file "app/views/layouts/application.html.erb", before: "</head>\n" do
    "  <%= Sentry.get_trace_propagation_meta.html_safe %>\n  "
  end
end