diff --git a/CHANGELOG.md b/CHANGELOG.md index 1eef0bdfe..8e806511d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ - [Discussion thread and explanation on the decision](https://github.com/rails/rails/pull/43625#issuecomment-1072514175) - Check if ActiveRecord connection exists before calling AR connection pool [#1769](https://github.com/getsentry/sentry-ruby/pull/1769) - Fixes [#1745](https://github.com/getsentry/sentry-ruby/issues/1745) +- Fix `sentry-rails`'s tracing spans not nesting issue - [#1784](https://github.com/getsentry/sentry-ruby/pull/1784) + - Fixes [#1723](https://github.com/getsentry/sentry-ruby/issues/1723) - Update `config.transport.proxy` to allow String and URI values as previously supported by `sentry-ruby` versions <= 4.8 using Faraday - Fixes [#1782](https://github.com/getsentry/sentry-ruby/issues/1782) diff --git a/sentry-rails/examples/rails-7.0/app/views/layouts/application.html.erb b/sentry-rails/examples/rails-7.0/app/views/layouts/application.html.erb index 60ee8159f..58669e427 100644 --- a/sentry-rails/examples/rails-7.0/app/views/layouts/application.html.erb +++ b/sentry-rails/examples/rails-7.0/app/views/layouts/application.html.erb @@ -5,8 +5,8 @@ <%= csrf_meta_tags %> <%= csp_meta_tag %> - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> - <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> + <%# <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %1> %> + <%# <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %1> %> diff --git a/sentry-rails/examples/rails-7.0/db/migrate/20220403110436_create_posts.rb b/sentry-rails/examples/rails-7.0/db/migrate/20220403110436_create_posts.rb new file mode 100644 index 000000000..4117623a9 --- /dev/null +++ b/sentry-rails/examples/rails-7.0/db/migrate/20220403110436_create_posts.rb @@ -0,0 +1,10 @@ +class CreatePosts < ActiveRecord::Migration[7.0] + def change + create_table :posts do |t| + t.string :title + t.text :content + + t.timestamps + end + end +end diff --git a/sentry-rails/examples/rails-7.0/db/schema.rb b/sentry-rails/examples/rails-7.0/db/schema.rb new file mode 100644 index 000000000..1c4837a9d --- /dev/null +++ b/sentry-rails/examples/rails-7.0/db/schema.rb @@ -0,0 +1,21 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[7.0].define(version: 2022_04_03_110436) do + create_table "posts", force: :cascade do |t| + t.string "title" + t.text "content" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/sentry-rails/lib/sentry/rails/tracing/abstract_subscriber.rb b/sentry-rails/lib/sentry/rails/tracing/abstract_subscriber.rb index 086269ac0..17438d191 100644 --- a/sentry-rails/lib/sentry/rails/tracing/abstract_subscriber.rb +++ b/sentry-rails/lib/sentry/rails/tracing/abstract_subscriber.rb @@ -40,15 +40,12 @@ def subscribe_to_event(event_names) def record_on_current_span(duration:, **options) return unless options[:start_timestamp] - scope = Sentry.get_current_scope - transaction = scope.get_transaction - return unless transaction && transaction.sampled - - span = transaction.start_child(**options) - # duration in ActiveSupport is computed in millisecond - # so we need to covert it as second before calculating the timestamp - span.set_timestamp(span.start_timestamp + duration / 1000) - yield(span) if block_given? + Sentry.with_child_span(**options) do |child_span| + # duration in ActiveSupport is computed in millisecond + # so we need to covert it as second before calculating the timestamp + child_span.set_timestamp(child_span.start_timestamp + duration / 1000) + yield(child_span) if block_given? + end end end end