Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking query times #232

Closed
scottrobertson opened this issue Nov 28, 2016 · 7 comments
Closed

Tracking query times #232

scottrobertson opened this issue Nov 28, 2016 · 7 comments

Comments

@scottrobertson
Copy link

Hey. We use scoutapp.com for monitoring.

We currently track our non NoBrainer queries, but we need a way to track the queries performed by NoBrainer. What we do for manual queries is wrap it in the following:

self.instrument("RethinkDB", RethinkDB::RPP.pp(query)) do
  # call .run
end

Can you think of a way to do this globally for all NoBrainer queries? Wrapping each call is not possible (it would be incredibly messy)

@jeroenvisser101
Copy link
Contributor

jeroenvisser101 commented Nov 28, 2016

Hey @scottrobertson, we instrument our queries for Appsignal (which is great btw)

I've adapted what we use and that should work for you:

require "nobrainer"

if defined?(ScoutApp) # Adapt to match your module
  class RethinkdDBInstrumentation < NoBrainer::QueryRunner::Middleware
    def call(env)
      ScoutApp.instrument("RethinkDB", RethinkDB::RPP.pp(env[:query])) do
        @runner.call(env)
      end
    end
  end

  NoBrainer::QueryRunner.stack.insert_after(
    NoBrainer::QueryRunner::Profiler,
    RethinkdDBInstrumentation
  )
end

PS. We've been using this, but we're still figuring out how to filter parameters from this (so it wouldn't send data to the monitoring party), do you know if there's any easy way to do that? Preferably without regex magic?

@scottrobertson
Copy link
Author

@jeroenvisser101 awesome, that is perfect. Thank you! I wasnt aware of insert_after

@scottrobertson
Copy link
Author

PS. We've been using this, but we're still figuring out how to filter parameters from this (so it wouldn't send data to the monitoring party), do you know if there's any easy way to do that? Preferably without regex magic?

Not yet sadly. The only way I can find is regex at the moment :(

@jeroenvisser101
Copy link
Contributor

Ah, too bad, thanks anyways :)

@nviennot
Copy link
Collaborator

nviennot commented Nov 28, 2016

You can get instrumentation by doing:

class YourProfiler
  def on_query(env)
    # env is a hash with a bunch of info.
    # see https://github.com/nviennot/nobrainer/blob/master/lib/no_brainer/profiler/logger.rb for example usage
  end

  NoBrainer::Profiler.register(self.new)
end

I'm not sure how to filter out params from the query in a systematic manner :/

@scottrobertson
Copy link
Author

Nice! Thank you

@jeroenvisser101
Copy link
Contributor

@nviennot that one is even better, thanks, will adapt ours too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants