Sha256: d951681d98dfedb1b269c8897227291a3a7f64077836b20c5fb95d7277a5655c

Contents?: true

Size: 1.44 KB

Versions: 31

Compression:

Stored size: 1.44 KB

Contents

require 'active_support/concern'
require 'active_support/notifications'
require 'active_graph/ansi'
require 'active_graph/core/logging'

module ActiveGraph
  module Core
    module Instrumentable
      extend ActiveSupport::Concern

      EMPTY = ''
      NEWLINE_W_SPACES = "\n  "

      class_methods do
        def subscribe_to_request
          ActiveSupport::Notifications.subscribe('neo4j.core.bolt.request') do |_, start, finish, _id, _payload|
            ms = (finish - start) * 1000
            yield " #{ANSI::BLUE}BOLT:#{ANSI::CLEAR} #{ANSI::YELLOW}#{ms.round}ms#{ANSI::CLEAR}"
          end
        end

        def subscribe_to_query
          ActiveSupport::Notifications.subscribe('neo4j.core.cypher_query') do |_, _start, _finish, _id, payload|
            query = payload[:query]
            params_string = (query.parameters && !query.parameters.empty? ? "| #{query.parameters.inspect}" : EMPTY)
            cypher = query.pretty_cypher ? (NEWLINE_W_SPACES if query.pretty_cypher.include?("\n")).to_s + query.pretty_cypher.gsub(/\n/, NEWLINE_W_SPACES) : query.cypher

            source_line, line_number = Logging.first_external_path_and_line(caller_locations)

            yield " #{ANSI::CYAN}#{query.context || 'CYPHER'}#{ANSI::CLEAR} #{cypher} #{params_string}" +
              ("\n   ↳ #{source_line}:#{line_number}" if ActiveGraph::Config.fetch(:verbose_query_logs, false) && source_line).to_s
          end
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
activegraph-11.4.0 lib/active_graph/core/instrumentable.rb
activegraph-11.3.1 lib/active_graph/core/instrumentable.rb
activegraph-11.3.0 lib/active_graph/core/instrumentable.rb
activegraph-11.2.0 lib/active_graph/core/instrumentable.rb
activegraph-11.1.0 lib/active_graph/core/instrumentable.rb
activegraph-11.1.0.beta.1 lib/active_graph/core/instrumentable.rb
activegraph-11.1.0.alpha.4 lib/active_graph/core/instrumentable.rb
activegraph-11.1.0.alpha.3 lib/active_graph/core/instrumentable.rb
activegraph-11.1.0.alpha.2 lib/active_graph/core/instrumentable.rb
activegraph-11.1.0.alpha.1 lib/active_graph/core/instrumentable.rb
activegraph-10.2.0.beta.1 lib/active_graph/core/instrumentable.rb
activegraph-11.0.2-java lib/active_graph/core/instrumentable.rb
activegraph-10.1.1 lib/active_graph/core/instrumentable.rb
activegraph-11.0.1-java lib/active_graph/core/instrumentable.rb
activegraph-11.0.0-java lib/active_graph/core/instrumentable.rb
activegraph-10.1.0 lib/active_graph/core/instrumentable.rb
activegraph-11.0.0.beta.4-java lib/active_graph/core/instrumentable.rb
activegraph-10.0.2 lib/active_graph/core/instrumentable.rb
activegraph-11.0.0.beta.3-java lib/active_graph/core/instrumentable.rb
activegraph-11.0.0.beta.2-java lib/active_graph/core/instrumentable.rb