Skip to content

PostgreSQL getting connection info slowing down tracing #3573

@nijel

Description

@nijel

How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.14.0

Steps to Reproduce

  1. Use sentry-sdk with Django integration.
  2. Profile a view with doing several SQL queries.
  3. Notice there is expanduser shown on top of “Slowest Application Functions” in Sentry.

Expected Result

We don't invoke expanduser at all, so it should not be there. Definitely it should not be on top of the list, taking more time than template rendering.

Actual Result

expanduser being identified by Sentry as the slowest thing on this view:

Image

Profile trace:

Image

This seems to be invoked for each SQLCompiler.execute_sql invocation, so for every SQL query.

It is invoked from here:

connection_params = cursor_or_db.connection.info.get_parameters()

The expanduser then comes from psycopg3 via Path.home():

https://github.com/psycopg/psycopg/blob/af5bfa0ec2690571033e38205a98cfc8c6287134/psycopg/psycopg/_connection_info.py#L86

Metadata

Metadata

Labels

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions