165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
# File 'lib/brainzlab/instrumentation/graphql.rb', line 165
def execute_query(query:)
started_at = Time.now.utc
operation_name = query.operation_name || 'anonymous'
operation_type = query.selected_operation&.operation_type || 'query'
result = super
duration_ms = ((Time.now.utc - started_at) * 1000).round(2)
has_errors = result.to_h['errors']&.any?
if BrainzLab.configuration.reflex_enabled
BrainzLab::Reflex.add_breadcrumb(
"GraphQL #{operation_type} #{operation_name}",
category: 'graphql.execute',
level: has_errors ? :error : :info,
data: {
operation_name: operation_name,
operation_type: operation_type,
duration_ms: duration_ms
}
)
end
spans = Thread.current[:brainzlab_pulse_spans]
if spans
spans << {
span_id: SecureRandom.uuid,
name: "GraphQL #{operation_type} #{operation_name}",
kind: 'graphql',
started_at: started_at,
ended_at: Time.now.utc,
duration_ms: duration_ms,
data: {
operation_name: operation_name,
operation_type: operation_type
},
error: has_errors
}
end
result
rescue StandardError => e
if BrainzLab.configuration.reflex_enabled
BrainzLab::Reflex.add_breadcrumb(
"GraphQL #{operation_type} #{operation_name} failed",
category: 'graphql.error',
level: :error,
data: { error: e.class.name }
)
end
raise
end
|