Module: GraphQL::Tracing::NotificationsTrace

Included in:
ActiveSupportNotificationsTrace
Defined in:
lib/graphql/tracing/notifications_trace.rb

Overview

This implementation forwards events to a notification handler (i.e. ActiveSupport::Notifications or Dry::Monitor::Notifications) with a graphql suffix.

See ActiveSupportNotificationsTrace ActiveSupport::Notifications integration

Defined Under Namespace

Classes: ActiveSupportNotificationsAdapter, Adapter, DryMonitorAdapter

Constant Summary collapse

CURRENT_EV_KEY =
:__notifications_graphql_trace_event
PREVIOUS_EV_KEY =
:__notifications_graphql_trace_previous_event

Instance Method Summary collapse

Instance Method Details

#begin_analyze_multiplex(multiplex, analyzers) ⇒ Object



111
112
113
114
# File 'lib/graphql/tracing/notifications_trace.rb', line 111

def begin_analyze_multiplex(multiplex, analyzers)
  begin_notifications_event("analyze.graphql", {multiplex: multiplex, analyzers: analyzers})
  super
end

#begin_authorized(type, object, context) ⇒ Object



150
151
152
153
# File 'lib/graphql/tracing/notifications_trace.rb', line 150

def begin_authorized(type, object, context)
  begin_notifications_event("authorized.graphql", {type: type, object: object, context: context})
  super
end

#begin_dataloader_source(source) ⇒ Object



170
171
172
173
# File 'lib/graphql/tracing/notifications_trace.rb', line 170

def begin_dataloader_source(source)
  begin_notifications_event("dataloader_source.graphql", { source: source })
  super
end

#begin_execute_field(field, object, arguments, query) ⇒ Object



127
128
129
130
# File 'lib/graphql/tracing/notifications_trace.rb', line 127

def begin_execute_field(field, object, arguments, query)
  begin_notifications_event("execute_field.graphql", {field: field, object: object, arguments: arguments, query: query})
  super
end

#begin_resolve_type(type, object, context) ⇒ Object



160
161
162
163
# File 'lib/graphql/tracing/notifications_trace.rb', line 160

def begin_resolve_type(type, object, context)
  begin_notifications_event("resolve_type.graphql", {type: type, object: object, context: context})
  super
end

#dataloader_fiber_resume(source) ⇒ Object



142
143
144
145
146
147
148
# File 'lib/graphql/tracing/notifications_trace.rb', line 142

def dataloader_fiber_resume(source)
  prev_ev = Fiber[PREVIOUS_EV_KEY]
  if prev_ev
    begin_notifications_event(prev_ev.name, prev_ev.payload)
  end
  super
end

#dataloader_fiber_yield(source) ⇒ Object



137
138
139
140
# File 'lib/graphql/tracing/notifications_trace.rb', line 137

def dataloader_fiber_yield(source)
  Fiber[PREVIOUS_EV_KEY] = finish_notifications_event
  super
end

#end_analyze_multiplex(_multiplex, _analyzers) ⇒ Object



116
117
118
119
# File 'lib/graphql/tracing/notifications_trace.rb', line 116

def end_analyze_multiplex(_multiplex, _analyzers)
  finish_notifications_event
  super
end

#end_authorized(type, object, context, result) ⇒ Object



155
156
157
158
# File 'lib/graphql/tracing/notifications_trace.rb', line 155

def end_authorized(type, object, context, result)
  finish_notifications_event
  super
end

#end_dataloader_source(source) ⇒ Object



175
176
177
178
# File 'lib/graphql/tracing/notifications_trace.rb', line 175

def end_dataloader_source(source)
  finish_notifications_event
  super
end

#end_execute_field(_field, _object, _arguments, _query, _result) ⇒ Object



132
133
134
135
# File 'lib/graphql/tracing/notifications_trace.rb', line 132

def end_execute_field(_field, _object, _arguments, _query, _result)
  finish_notifications_event
  super
end

#end_resolve_type(type, object, context, resolved_type) ⇒ Object



165
166
167
168
# File 'lib/graphql/tracing/notifications_trace.rb', line 165

def end_resolve_type(type, object, context, resolved_type)
  finish_notifications_event
  super
end

#execute_multiplex(**payload) ⇒ Object



121
122
123
124
125
# File 'lib/graphql/tracing/notifications_trace.rb', line 121

def execute_multiplex(**payload)
  @notifications.instrument("execute.graphql", payload) do
    super
  end
end

#initialize(engine:, **rest) ⇒ Object

Parameters

  • engine (Class) — The notifications engine to use, eg Dry::Monitor or ActiveSupport::Notifications

:call-seq:

initialize(Class engine:, **rest)


81
82
83
84
85
86
87
88
89
90
91
# File 'lib/graphql/tracing/notifications_trace.rb', line 81

def initialize(engine:, **rest)
  adapter = if defined?(Dry::Monitor) && engine == Dry::Monitor
    DryMonitoringAdapter
  elsif defined?(ActiveSupport::Notifications) && engine == ActiveSupport::Notifications
    ActiveSupportNotificationsAdapter
  else
    engine
  end
  @notifications = adapter.new
  super
end

#lex(**payload) ⇒ Object



99
100
101
102
103
# File 'lib/graphql/tracing/notifications_trace.rb', line 99

def lex(**payload)
  @notifications.instrument("lex.graphql", payload) do
    super
  end
end

#parse(**payload) ⇒ Object



93
94
95
96
97
# File 'lib/graphql/tracing/notifications_trace.rb', line 93

def parse(**payload)
  @notifications.instrument("parse.graphql", payload) do
    super
  end
end

#validate(**payload) ⇒ Object



105
106
107
108
109
# File 'lib/graphql/tracing/notifications_trace.rb', line 105

def validate(**payload)
  @notifications.instrument("validate.graphql", payload) do
    super
  end
end