Closed jtremesay-sereema closed 12 months ago
Thanks for the report @jtremesay-sereema! As far as I can tell the only Django-related change we introduced in 1.29.* was adding DB connection data to spans, so that would be the first thing for us to check.
I don't think there's any insight to be gained by testing lower 1.29.* versions as 1.29.2 is just 1.29.0 with a broken feature rolled back.
As far as I know there is no way to opt out of collecting the DB connection data, so the best way to work around this for now is to stay on 1.28.1 while we investigate.
I may have a clue.
In 1.29.X, you do a lot of get_connection_params()
(once per sql query).
Unfortunately, we have our own DatabaseWrapper that do some magic stuff in the get_connection_params()
method to work with AWS RDS IAM Authentification:
from pathlib import Path
import boto3
from django.db.backends.postgresql import base
SSL_ROOT_CERT = Path(__file__).parent / "rds-ca.pem"
class DatabaseWrapper(base.DatabaseWrapper):
def get_connection_params(self):
params = super().get_connection_params()
params["sslmode"] = "verify-full"
params["sslrootcert"] = SSL_ROOT_CERT
aws_region = params.pop("region", None)
rds_client = boto3.client("rds", region_name=aws_region)
params["password"] = rds_client.generate_db_auth_token(
DBHostname=params["host"], DBUsername=params["user"], Port=params.get("port", 5432)
)
return params
Yes, that definitely looks related. I think we need to reevaluate if calling get_connection_params()
every time to get the connection params is the right way to go. I'd hope there is a way to get them from the connection directly -- we need to investigate.
We tried with sentry-sdk 1.30.0 and we still have the performance issue.
Apologies @jtremesay-sereema, we missed this! Reopening the issue.
I think I know why the fix didn't work for you -- you're on a recent Django version with psycopg (i.e., psycopg 3). The fix we implemented would've worked for psycopg2 only, which is now deprecated as PG backend in Django. So this will need a different solution.
How do you use Sentry?
Sentry Saas (sentry.io)
Version
1.29.2
Steps to Reproduce
Upgrade Sentry from 1.28.1 to 1.29.2
Expected Result
No performance issue when upgrading from Sentry 1.28.1 to 1.29.2.
Actual Result
After upgrading the Sentry SDK from 1.28.1 to 1.29.2 in our ASGI Django app, we started to notice a huge performance isssue:
Reverting to 1.28.1 fix the issue. I’m too lazy to test 1.29.1.
Unfortunately, we don’t have any logs or errors.
Funny behaviour: when we tests our views on the prod using the request mocker of Django (https://docs.djangoproject.com/en/4.2/topics/testing/advanced/#the-request-factory), the runtime is normal. But when we try with an actual HTTP request, we have the performance issue. So maybe an issue between the Sentry lib and the network/middleware layers of Django?
List and version of our deps :
I will try to gather more useful information.