autometrics-dev / autometrics-py

Easily add metrics to your code that actually help you spot and debug issues in production. Built on Prometheus and OpenTelemetry.
https://autometrics.dev
Apache License 2.0
214 stars 7 forks source link

Question: Using autometrics in a database (postgresql)? #68

Closed aiswaryapajit closed 1 year ago

aiswaryapajit commented 1 year ago

can we use autometrics to be run at database side(postgresql) or is there any way to use api of autometrics

brettimus commented 1 year ago

hey! so discussed this with @actualwitch this morning.

if you want to track metrics of database queries, you would have to wrap your application code that calls the database. of course, this doesn't give you metrics on specific subqueries, and would include the latency of sending the request to the database server, however! it would give you metrics for getting the data your application needs from the database, which is closest to what your users would experience.

to make it concrete, this is what you'd be trying to do, application-side:

@autometrics
def list_all_users():
  return db.query("select * from users")
brettimus commented 1 year ago

a little bit off topic, but @actualwitch pointed out that lots of python APIs will use context instead of functions for this kind of (db) operation. she proposed supporting instrumentation via context manager here

i'm going to close this issue as answered!