def instrument(keyword, object)
return yield unless Sentry.initialized?
platform_key = name_for(keyword, object)
Sentry.with_child_span(op: platform_key, start_timestamp: Sentry.utc_now.to_f) do |span|
result = yield
return result unless span
span.finish
if keyword == :execute
queries = object.queries
operation_names = queries.map{|q| operation_name(q) }
span.set_description(operation_names.join(", "))
if queries.size == 1
query = queries.first
set_this_txn_name = query.context[:set_sentry_transaction_name]
if set_this_txn_name == true || (set_this_txn_name.nil? && @set_transaction_name)
Sentry.configure_scope do |scope|
scope.set_transaction_name(transaction_name(query))
end
end
if graphql_data_collection.nil? || graphql_data_collection.document
span.set_data('graphql.document', query.query_string)
end
if query.selected_operation_name
span.set_data('graphql.operation.name', query.selected_operation_name)
end
if query.selected_operation
span.set_data('graphql.operation.type', query.selected_operation.operation_type)
end
if graphql_data_collection&.variables && !query.provided_variables.empty?
span.set_data('graphql.variables', query.provided_variables)
end
end
end
result
end
end