Skip to content

Commit b30d84a

Browse files
committed
Simple update demonstrating how the code may be written to handle nested childs
1 parent c65088f commit b30d84a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

sentry-rails/lib/sentry/rails/tracing/abstract_subscriber.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,18 @@ def record_on_current_span(duration:, **options)
4141
return unless options[:start_timestamp]
4242

4343
scope = Sentry.get_current_scope
44-
transaction = scope.get_transaction
45-
return unless transaction && transaction.sampled
44+
current_span = scope.get_span
45+
return unless current_span && current_span.sampled
46+
47+
span = current_span.start_child(**options)
48+
Sentry.get_current_scope.set_span(span)
4649

47-
span = transaction.start_child(**options)
4850
# duration in ActiveSupport is computed in millisecond
4951
# so we need to covert it as second before calculating the timestamp
5052
span.set_timestamp(span.start_timestamp + duration / 1000)
5153
yield(span) if block_given?
54+
55+
Sentry.get_current_scope.set_span(current_span)
5256
end
5357
end
5458
end

0 commit comments

Comments
 (0)