From 0ca3d12b19d8de10861d7d573aabf67f472deb45 Mon Sep 17 00:00:00 2001 From: st0012 Date: Sun, 3 Apr 2022 12:42:12 +0100 Subject: [PATCH 1/4] Ignore asset tags --- .../examples/rails-7.0/app/views/layouts/application.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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> %> From 102d11dd0bb100c38b996757055aac1e931d51fc Mon Sep 17 00:00:00 2001 From: st0012 Date: Sun, 3 Apr 2022 12:42:29 +0100 Subject: [PATCH 2/4] Create posts table in the example app --- .../db/migrate/20220403110436_create_posts.rb | 10 +++++++++ sentry-rails/examples/rails-7.0/db/schema.rb | 21 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 sentry-rails/examples/rails-7.0/db/migrate/20220403110436_create_posts.rb create mode 100644 sentry-rails/examples/rails-7.0/db/schema.rb 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 From d739519db6669511c986509d4b44ed8f273a4c0c Mon Sep 17 00:00:00 2001 From: st0012 Date: Mon, 4 Apr 2022 21:15:43 +0100 Subject: [PATCH 3/4] Use Sentry.with_child_span in the tracing subscribers --- .../sentry/rails/tracing/abstract_subscriber.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) 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 From f9a65018d41a88b6fbf63a5bf9c5b55f97376abe Mon Sep 17 00:00:00 2001 From: st0012 Date: Fri, 8 Apr 2022 09:42:07 +0100 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7102c9c4..9d1e3d8ab 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) ### Refactoring