Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return early if Sentry.with_child_span returns nil #4828

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/graphql/tracing/sentry_trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ def instrument_execution(platform_key, trace_method, data=nil, &block)
return yield unless Sentry.initialized?

Sentry.with_child_span(op: platform_key, start_timestamp: Sentry.utc_now.to_f) do |span|
result = block.call
span.finish
result = yield
return result unless span

span.finish
if trace_method == "execute_multiplex" && data.key?(:multiplex)
operation_names = data[:multiplex].queries.map{|q| operation_name(q) }
span.set_description(operation_names.join(", "))
Expand Down
11 changes: 11 additions & 0 deletions spec/graphql/tracing/sentry_trace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ def thing; :thing; end
end
end

describe "When Sentry.with_child_span returns nil" do
it "does not initialize any spans" do
Sentry.stub(:with_child_span, nil) do
SentryTraceTestSchema.execute("{ int thing { str } }")
assert_equal [], Sentry::SPAN_DATA
assert_equal [], Sentry::SPAN_DESCRIPTIONS
assert_equal [], Sentry::SPAN_OPS
end
end
end

it "sets the expected spans" do
SentryTraceTestSchema.execute("{ int thing { str } }")
expected_span_ops = [
Expand Down
Loading