def patch_conn(conn, traced_conn_cls=dbapi.TracedConnection):
""" Wrap will patch the instance so that it's queries are traced."""
# ensure we've patched extensions (this is idempotent) in
# case we're only tracing some connections.
_patch_extensions(_psycopg2_extensions)
c = traced_conn_cls(conn)
# fetch tags from the dsn
dsn = sql.parse_pg_dsn(conn.dsn)
tags = {
net.TARGET_HOST: dsn.get("host"),
net.TARGET_PORT: dsn.get("port"),
db.NAME: dsn.get("dbname"),
db.USER: dsn.get("user"),
"db.application" : dsn.get("application_name"),
}
Pin(
service="postgres",
app="postgres",
app_type="db",
tags=tags).onto(c)
return c
评论列表
文章目录