From fb9d3ab51328d8722122f8923a2bb6330d7bc9c8 Mon Sep 17 00:00:00 2001 From: st0012 Date: Mon, 4 Apr 2022 21:15:43 +0100 Subject: [PATCH] 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