Skip to content

Commit 68b73d2

Browse files
committed
Fiddle with some of the bits
1 parent 855beba commit 68b73d2

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
lines changed

lib/graphql/tracing/sentry_trace.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ module SentryTrace
1313
"analyze_multiplex" => "graphql.analyze_multiplex",
1414
"execute_multiplex" => "graphql.execute_multiplex",
1515
"execute_query" => "graphql.execute",
16-
"execute_query_lazy" => "graphql.execute",
17-
"execute_field" => "graphql.execute",
18-
"execute_field_lazy" => "graphql.execute"
16+
"execute_query_lazy" => "graphql.execute"
1917
}.each do |trace_method, platform_key|
2018
module_eval <<-RUBY, __FILE__, __LINE__
2119
def #{trace_method}(**data, &block)
@@ -49,7 +47,7 @@ def platform_resolve_type_lazy(platform_key, &block)
4947
end
5048

5149
def platform_field_key(field)
52-
"graphql.#{field.path}"
50+
"graphql.field.#{field.path}"
5351
end
5452

5553
def platform_authorized_key(type)
@@ -71,7 +69,7 @@ def instrument_execution(platform_key, trace_method, data=nil, &block)
7169

7270
if trace_method == "execute_multiplex" && data.key?(:multiplex)
7371
operation_names = data[:multiplex].queries.map{|q| operation_name(q) }
74-
span.set_description(operation_names.join(", ")) if operation_names.count > 1
72+
span.set_description(operation_names.join(", "))
7573
elsif trace_method == "execute_query" && data.key?(:query)
7674
span.set_description(operation_name(data[:query]))
7775
span.set_data('graphql.document', data[:query].query_string)

lib/graphql/tracing/sentry_tracing.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ class SentryTracing < PlatformTracing
1313
"execute_multiplex" => "graphql.execute_multiplex",
1414
"execute_query" => "graphql.execute",
1515
"execute_query_lazy" => "graphql.execute",
16-
"execute_field" => "graphql.execute",
17-
"execute_field_lazy" => "graphql.execute"
1816
}
1917

2018
def platform_trace(platform_key, trace_method, data, &block)
@@ -30,16 +28,16 @@ def platform_trace(platform_key, trace_method, data, &block)
3028
elsif trace_method == "execute_query" && data.key?(:query)
3129
span.set_description(operation_name(data[:query]))
3230
span.set_data("graphql.document", data[:query].query_string)
33-
span.set_data("graphql.operation.name", data[:query].selected_operation_name)
31+
span.set_data("graphql.operation.name", data[:query].selected_operation_name) if data[:query].selected_operation_name
3432
span.set_data("graphql.operation.type", data[:query].selected_operation.operation_type)
3533
end
3634

3735
result
3836
end
3937
end
4038

41-
def platform_field_key(field)
42-
"graphql.#{field.path}"
39+
def platform_field_key(_type, field)
40+
"graphql.field.#{field.path}"
4341
end
4442

4543
def platform_authorized_key(type)
@@ -55,7 +53,7 @@ def platform_resolve_type_key(type)
5553
def operation_name(query)
5654
selected_op = query.selected_operation
5755
if selected_op
58-
[selected_op.operation_type, selected_op.name].join(" ")
56+
[selected_op.operation_type, selected_op.name].compact.join(" ")
5957
else
6058
"GraphQL Operation"
6159
end

spec/graphql/tracing/sentry_trace_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def thing; :thing; end
2929
Sentry.clear_all
3030
end
3131

32-
describe 'When Sentry is not configured' do
33-
it 'does not initialize any spans' do
32+
describe "When Sentry is not configured" do
33+
it "does not initialize any spans" do
3434
Sentry.stub(:initialized?, false) do
3535
SentryTraceTestSchema.execute("{ int thing { str } }")
3636
assert_equal [], Sentry::SPAN_DATA
@@ -51,7 +51,7 @@ def thing; :thing; end
5151
"graphql.analyze",
5252
"graphql.execute",
5353
"graphql.authorized.Query",
54-
"graphql.Query.thing",
54+
"graphql.field.Query.thing",
5555
"graphql.authorized.Thing",
5656
"graphql.execute"
5757
].compact
@@ -62,7 +62,7 @@ def thing; :thing; end
6262
it "sets span descriptions for an anonymous query" do
6363
SentryTraceTestSchema.execute("{ int }")
6464

65-
assert_equal ['query'], Sentry::SPAN_DESCRIPTIONS
65+
assert_equal ["query", "query"], Sentry::SPAN_DESCRIPTIONS
6666
end
6767

6868
it "sets span data for an anonymous query" do
@@ -78,7 +78,7 @@ def thing; :thing; end
7878
it "sets span descriptions for a named query" do
7979
SentryTraceTestSchema.execute("query Ab { int }")
8080

81-
assert_equal ['query Ab'], Sentry::SPAN_DESCRIPTIONS
81+
assert_equal ["query Ab", "query Ab"], Sentry::SPAN_DESCRIPTIONS
8282
end
8383

8484
it "sets span data for a named query" do

spec/graphql/tracing/sentry_tracing_spec.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def thing; :thing; end
2929
Sentry.clear_all
3030
end
3131

32-
describe 'When Sentry is not configured' do
33-
it 'does not initialize any spans' do
32+
describe "When Sentry is not configured" do
33+
it "does not initialize any spans" do
3434
Sentry.stub(:initialized?, false) do
3535
SentryTracingTestSchema.execute("{ int thing { str } }")
3636
assert_equal [], Sentry::SPAN_DATA
@@ -51,7 +51,7 @@ def thing; :thing; end
5151
"graphql.analyze",
5252
"graphql.execute",
5353
"graphql.authorized.Query",
54-
"graphql.Query.thing",
54+
"graphql.field.Query.thing",
5555
"graphql.authorized.Thing",
5656
"graphql.execute"
5757
].compact
@@ -60,10 +60,9 @@ def thing; :thing; end
6060
end
6161

6262
it "sets span descriptions for an anonymous query" do
63-
debugger
6463
SentryTracingTestSchema.execute("{ int }")
6564

66-
assert_equal ['query'], Sentry::SPAN_DESCRIPTIONS
65+
assert_equal ["query", "query"], Sentry::SPAN_DESCRIPTIONS
6766
end
6867

6968
it "sets span data for an anonymous query" do
@@ -79,7 +78,7 @@ def thing; :thing; end
7978
it "sets span descriptions for a named query" do
8079
SentryTracingTestSchema.execute("query Ab { int }")
8180

82-
assert_equal ['query Ab'], Sentry::SPAN_DESCRIPTIONS
81+
assert_equal ["query Ab", "query Ab"], Sentry::SPAN_DESCRIPTIONS
8382
end
8483

8584
it "sets span data for a named query" do

0 commit comments

Comments
 (0)