Skip to content

Commit

Permalink
fix(django): improve getting psycopg3 connection info
Browse files Browse the repository at this point in the history
Fetch the few needed parameters manually instead of relying on `get_parameters()` which adds visible overhead due to excluding default values for parameters.
  • Loading branch information
nijel authored Sep 27, 2024
1 parent aa57373 commit c862f55
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sentry_sdk/integrations/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,14 @@ def _set_db_data(span, cursor_or_db):
connection_params = cursor_or_db.connection.get_dsn_parameters()
else:
try:
# psycopg3
connection_params = cursor_or_db.connection.info.get_parameters()
# psycopg3, only extract needed params as get_parameters
# can be slow because of the additional logic to filter out default
# values
connection_params = {
"dbname": cursor_or_db.connection.info.dbname,
"host": cursor_or_db.connection.info.host,
"port": cursor_or_db.connection.info.port,
}
except Exception:
connection_params = db.get_connection_params()

Expand Down

0 comments on commit c862f55

Please sign in to comment.