Skip to content

Commit 3282c8d

Browse files
authored
Merge pull request #5277 from rmosolgo/nr-fix-dataloaded-skipped-scalars
NewRelicTrace: fix dataloaded, skipped scalar fields
2 parents cb92bf8 + 1c4bb69 commit 3282c8d

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

lib/graphql/tracing/new_relic_trace.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,10 @@ def dataloader_fiber_yield(source)
158158
def dataloader_fiber_resume(source)
159159
prev_segment = Fiber[:graphql_nr_previous_segment]
160160
Fiber[:graphql_nr_previous_segment] = nil
161-
seg_partial_name = prev_segment.name.sub(/^.*(GraphQL.*)$/, '\1')
162-
start_segment(partial_name: seg_partial_name, category: :web)
161+
if prev_segment
162+
seg_partial_name = prev_segment.name.sub(/^.*(GraphQL.*)$/, '\1')
163+
start_segment(partial_name: seg_partial_name, category: :web)
164+
end
163165
super
164166
end
165167

spec/graphql/tracing/new_relic_trace_spec.rb

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
describe GraphQL::Tracing::NewRelicTrace do
55
module NewRelicTraceTest
6-
class NestedSource < GraphQL::Dataloader::Source
6+
class EchoSource < GraphQL::Dataloader::Source
77
def fetch(keys)
88
keys
99
end
1010
end
1111

1212
class OtherSource < GraphQL::Dataloader::Source
1313
def fetch(keys)
14-
dataloader.with(NestedSource).load_all(keys)
14+
dataloader.with(EchoSource).load_all(keys)
1515
end
1616
end
1717
class Thing < GraphQL::Schema::Object
@@ -31,7 +31,11 @@ class Other < GraphQL::Schema::Object
3131
def self.authorized?(obj, ctx)
3232
ctx[:lazy] ? -> { true } : true
3333
end
34-
field :name, String, fallback_value: "other"
34+
field :name, String
35+
36+
def name
37+
dataload(EchoSource, "name")
38+
end
3539
end
3640

3741
class Query < GraphQL::Schema::Object
@@ -83,6 +87,7 @@ class SchemaWithScalarTrace < GraphQL::Schema
8387
class SchemaWithoutAuthorizedOrResolveType < GraphQL::Schema
8488
query(Query)
8589
trace_with(GraphQL::Tracing::NewRelicTrace, set_transaction_name: true, trace_authorized: false, trace_resolve_type: false, trace_scalars: true)
90+
use GraphQL::Dataloader
8691
end
8792
end
8893

@@ -157,15 +162,17 @@ class SchemaWithoutAuthorizedOrResolveType < GraphQL::Schema
157162
"GraphQL/Source/NewRelicTraceTest::OtherSource",
158163
"FINISH GraphQL/Source/NewRelicTraceTest::OtherSource",
159164
# Nested source:
160-
"GraphQL/Source/NewRelicTraceTest::NestedSource",
161-
"FINISH GraphQL/Source/NewRelicTraceTest::NestedSource",
165+
"GraphQL/Source/NewRelicTraceTest::EchoSource",
166+
"FINISH GraphQL/Source/NewRelicTraceTest::EchoSource",
162167
"GraphQL/Source/NewRelicTraceTest::OtherSource",
163168
"FINISH GraphQL/Source/NewRelicTraceTest::OtherSource",
164169
# And back to the field:
165170
"GraphQL/Query/other",
166171
"FINISH GraphQL/Query/other",
167172
"GraphQL/Authorized/Other",
168173
"FINISH GraphQL/Authorized/Other",
174+
"GraphQL/Source/NewRelicTraceTest::EchoSource",
175+
"FINISH GraphQL/Source/NewRelicTraceTest::EchoSource",
169176
"FINISH GraphQL/execute"
170177
]
171178
assert_equal expected_steps, NewRelic::EXECUTION_SCOPES
@@ -191,6 +198,12 @@ class SchemaWithoutAuthorizedOrResolveType < GraphQL::Schema
191198
# "FINISH GraphQL/Authorized/Other",
192199
"GraphQL/Other/name",
193200
"FINISH GraphQL/Other/name",
201+
202+
"GraphQL/Source/NewRelicTraceTest::EchoSource",
203+
"FINISH GraphQL/Source/NewRelicTraceTest::EchoSource",
204+
"GraphQL/Other/name",
205+
"FINISH GraphQL/Other/name",
206+
194207
"FINISH GraphQL/execute"
195208
]
196209
assert_equal expected_steps, NewRelic::EXECUTION_SCOPES
@@ -232,6 +245,8 @@ class SchemaWithoutAuthorizedOrResolveType < GraphQL::Schema
232245
"FINISH GraphQL/Authorized/Other",
233246
"GraphQL/Authorized/Other",
234247
"FINISH GraphQL/Authorized/Other",
248+
"GraphQL/Source/NewRelicTraceTest::EchoSource",
249+
"FINISH GraphQL/Source/NewRelicTraceTest::EchoSource",
235250

236251
"FINISH GraphQL/execute",
237252
]

0 commit comments

Comments
 (0)