Skip to content

Commit 8d20bbc

Browse files
committed
GraphQL - individual tracers for missing notification keys
1 parent f7aec98 commit 8d20bbc

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

lib/skylight/normalizers/graphql/base.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ class Execute < Base
6565
# This is a new, combined normalizer for execute_query and execute_multiplex,
6666
# to be used for graphql >= 2.5
6767
#
68-
def normalize(trace, _name, payload)
68+
def normalize(trace, name, payload)
6969
if payload[:query]
70-
_execute_query_normalize
70+
_execute_query_normalize(trace, name, payload)
7171
else
7272
[CAT, "graphql.#{key}", nil]
7373
end
@@ -123,7 +123,7 @@ def _execute_multiplex_normalize_after(trace, _span, _name, payload)
123123
end
124124
end
125125

126-
class ExecuteQuery < Base
126+
class ExecuteQuery < Execute
127127
register_graphql
128128
end
129129

lib/skylight/probes/graphql.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,48 @@ def execute_multiplex(**metadata, &blk)
3535
end
3636
end
3737

38+
# GraphQL versions >= 2.5 are missing this notification
39+
module ExecuteQueryNotification
40+
def execute_query(**metadata, &blk)
41+
if @notifications_engine
42+
@notifications_engine.instrument("execute_query.graphql", metadata, &blk)
43+
elsif @notifications
44+
@notifications.instrument("execute_query.graphql", metadata, &blk)
45+
else
46+
# safety fallback in case graphql's authors unexpectedly rename @notifications_engine or @notifications
47+
super
48+
end
49+
end
50+
end
51+
52+
# GraphQL versions >= 2.5 are missing this notification
53+
module ExecuteQueryLazyNotification
54+
def execute_query_lazy(**metadata, &blk)
55+
if @notifications_engine
56+
@notifications_engine.instrument("execute_query_lazy.graphql", metadata, &blk)
57+
elsif @notifications
58+
@notifications.instrument("execute_query_lazy.graphql", metadata, &blk)
59+
else
60+
# safety fallback in case graphql's authors unexpectedly rename @notifications_engine or @notifications
61+
super
62+
end
63+
end
64+
end
65+
66+
# GraphQL versions >= 2.5 are missing this notification
67+
module AnalyzeQueryNotification
68+
def analyze_query(**metadata, &blk)
69+
if @notifications_engine
70+
@notifications_engine.instrument("analyze_query.graphql", metadata, &blk)
71+
elsif @notifications
72+
@notifications.instrument("analyze_query.graphql", metadata, &blk)
73+
else
74+
# safety fallback in case graphql's authors unexpectedly rename @notifications_engine or @notifications
75+
super
76+
end
77+
end
78+
end
79+
3880
module ClassMethods
3981
def new_trace(*, **)
4082
unless @__sk_instrumentation_installed
@@ -44,6 +86,18 @@ def new_trace(*, **)
4486
trace_with(ExecuteMultiplexNotification)
4587
end
4688

89+
unless ::GraphQL::Tracing::ActiveSupportNotificationsTrace.instance_methods.include?(:execute_query)
90+
trace_with(ExecuteQueryNotification)
91+
end
92+
93+
unless ::GraphQL::Tracing::ActiveSupportNotificationsTrace.instance_methods.include?(:execute_query_lazy)
94+
trace_with(ExecuteQueryLazyNotification)
95+
end
96+
97+
unless ::GraphQL::Tracing::ActiveSupportNotificationsTrace.instance_methods.include?(:analyze_query)
98+
trace_with(AnalyzeQueryNotification)
99+
end
100+
47101
@__sk_instrumentation_installed = true
48102
end
49103

0 commit comments

Comments
 (0)