Skip to content
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
4 changes: 2 additions & 2 deletions lib/graphql/tracing/perfetto_trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def begin_execute_field(field, object, arguments, query)
packet = trace_packet(
type: TrackEvent::Type::TYPE_SLICE_BEGIN,
track_uuid: fid,
name: query.context.current_path.join("."),
name: query.context.current_path&.join(".") || field.path,
category_iids: FIELD_EXECUTE_CATEGORY_IIDS,
extra_counter_track_uuids: @counts_objects,
extra_counter_values: [count_allocations],
Expand All @@ -269,7 +269,7 @@ def end_execute_field(field, object, arguments, query, app_result)
if @create_debug_annotations
start_field.track_event = dup_with(start_field.track_event,{
debug_annotations: [
payload_to_debug(nil, object.object, iid: DA_OBJECT_IID, intern_value: true),
payload_to_debug(nil, (object.is_a?(GraphQL::Schema::Object) ? object.object : object), iid: DA_OBJECT_IID, intern_value: true),
payload_to_debug(nil, arguments, iid: DA_ARGUMENTS_IID),
payload_to_debug(nil, app_result, iid: DA_RESULT_IID, intern_value: true)
]
Expand Down
33 changes: 26 additions & 7 deletions spec/graphql/tracing/detailed_trace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
describe GraphQL::Tracing::DetailedTrace do
class SamplerSchema < GraphQL::Schema
class Query < GraphQL::Schema::Object
field :truthy, Boolean, fallback_value: true
field :truthy, Boolean, fallback_value: true, resolve_static: true
def self.truthy(ctx); true; end
end

query(Query)
Expand All @@ -16,30 +17,48 @@ def self.detailed_trace?(query)
query.context[:profile] != false
end
end

use GraphQL::Execution::Next
end

before do
SamplerSchema.detailed_trace.delete_all_traces
end

def exec_query(...)
if TESTING_EXEC_NEXT
SamplerSchema.execute_next(...)
else
SamplerSchema.execute(...)
end
end

def exec_multiplex(...)
if TESTING_EXEC_NEXT
SamplerSchema.multiplex_next(...)
else
SamplerSchema.multiplex(...)
end
end

it "runs when the configured trace mode is set" do
assert_equal 0, SamplerSchema.detailed_trace.traces.size
res = SamplerSchema.execute("{ truthy }", context: { profile: false })
res = exec_query("{ truthy }", context: { profile: false })
assert_equal true, res["data"]["truthy"]
assert_equal 0, SamplerSchema.detailed_trace.traces.size

SamplerSchema.execute("{ truthy }")
exec_query("{ truthy }")
assert_equal 1, SamplerSchema.detailed_trace.traces.size
end

it "calls through to storage for access methods" do
SamplerSchema.execute("{ truthy }")
exec_query("{ truthy }")
id = SamplerSchema.detailed_trace.traces.first.id
assert_kind_of GraphQL::Tracing::DetailedTrace::StoredTrace, SamplerSchema.detailed_trace.find_trace(id)
SamplerSchema.detailed_trace.delete_trace(id)
assert_equal 0, SamplerSchema.detailed_trace.traces.size

SamplerSchema.execute("{ truthy }")
exec_query("{ truthy }")
assert_equal 1, SamplerSchema.detailed_trace.traces.size
SamplerSchema.detailed_trace.delete_all_traces
end
Expand All @@ -66,13 +85,13 @@ def self.detailed_trace?(query)
it "calls detailed_profile? on a Multiplex" do
assert_equal 0, SamplerSchema.detailed_trace.traces.size

SamplerSchema.multiplex([
exec_multiplex([
{ query: "{ truthy }", context: { profile: false } },
{ query: "{ truthy }", context: { profile: true } },
])
assert_equal 0, SamplerSchema.detailed_trace.traces.size

SamplerSchema.multiplex([
exec_multiplex([
{ query: "{ truthy }", context: { profile: true } },
{ query: "{ truthy }", context: { profile: true } },
])
Expand Down
5 changes: 4 additions & 1 deletion spec/graphql/tracing/perfetto_trace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ def self.detailed_trace?(q)
PerfettoSchema.execute(query_str, variables: { thingId: "Book-#{::Book.first.id}" })

res = PerfettoSchema.execute(query_str, variables: { thingId: "Book-#{::Book.first.id}" })
assert_equal 4, res["data"]["authors"].size
refute res.key?("errors")

if ENV["DUMP_PERFETTO"]
res.context.query.current_trace.write(file: "perfetto.dump")
end
Expand All @@ -184,7 +187,7 @@ def self.detailed_trace?(q)
data = JSON.parse(json)


check_snapshot(data, "example-rails-#{Rails::VERSION::MAJOR}-#{Rails::VERSION::MINOR}.json")
check_snapshot(data, "example-rails-#{Rails::VERSION::MAJOR}-#{Rails::VERSION::MINOR}#{TESTING_EXEC_NEXT ? "-next" : ""}.json")
end

it "replaces nil class name with (anonymous)" do
Expand Down
Loading