Skip to content

Commit

Permalink
Fix sentry-rails's tracing spans not nesting issue (#1784)
Browse files Browse the repository at this point in the history
* Ignore asset tags

* Create posts table in the example app

* Use Sentry.with_child_span in the tracing subscribers

* Update changelog
  • Loading branch information
st0012 committed Apr 9, 2022
1 parent 72396ce commit c735744
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> %>
</head>

<body>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions sentry-rails/examples/rails-7.0/db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions sentry-rails/lib/sentry/rails/tracing/abstract_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c735744

Please sign in to comment.