Skip to content

Commit 5bc0a65

Browse files
authored
Merge pull request #5313 from rmosolgo/sentry-nil-span-fix
Sentry trace: handle nil current_span
2 parents 425660c + f056564 commit 5bc0a65

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

lib/graphql/tracing/sentry_trace.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ def operation_name(query)
6464

6565
class Event < MonitorTrace::Monitor::Event
6666
def start
67-
if Sentry.initialized?
68-
@span = Sentry.get_current_scope.get_span
67+
if Sentry.initialized? && (@span = Sentry.get_current_scope.get_span)
6968
span_name = @monitor.name_for(@keyword, @object)
7069
@span.start_child(op: span_name)
7170
end

spec/graphql/tracing/sentry_trace_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ class SchemaWithTransactionName < GraphQL::Schema
4747
assert res.context[:other_trace_ran]
4848
end
4949

50+
it "handles cases when Sentry has no current span" do
51+
Sentry.use_nil_span = true
52+
assert SentryTraceTest::SchemaWithoutTransactionName.execute("{ int }")
53+
ensure
54+
Sentry.use_nil_span = false
55+
end
56+
5057
describe "When Sentry is not configured" do
5158
it "does not initialize any spans" do
5259
Sentry.stub(:initialized?, false) do

spec/support/sentry.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ module Sentry
1111
SPAN_DESCRIPTIONS = []
1212
TRANSACTION_NAMES = []
1313

14+
class << self
15+
attr_accessor :use_nil_span
16+
end
17+
1418
def self.initialized?
1519
true
1620
end
@@ -24,7 +28,7 @@ def self.get_current_scope
2428
end
2529

2630
def self.get_span
27-
DummySpan
31+
use_nil_span ? nil : DummySpan
2832
end
2933

3034
def self.with_child_span(**args, &block)

0 commit comments

Comments
 (0)