o
    iix                     @   s   d dl mZ d dlmZ d dlmZmZ d dlmZ zd dl	m
Z
 W n ey-   edw er<d dlmZ d dlmZ d	d
 ZdS )    )absolute_import)TYPE_CHECKING)cache_statementshould_run_explain_plan)DidNotEnable)textzSQLAlchemy not installed.)Any)Spanc           	      C   s~   |   dsdS t||sdS |ddrdnd}d| | | }|t|}dd	 |D }| d
| t|| dS )aB  
    Run EXPLAIN or EXPLAIN ANALYZE on the given statement and attach the explain plan to the span data.

    Usage:
    ```
    sentry_sdk.init(
        dsn="...",
        _experiments={
            "attach_explain_plans": {
                "explain_cache_size": 1000,  # Run explain plan for the 1000 most run queries
                "explain_cache_timeout_seconds": 60 * 60 * 24,  # Run the explain plan for each statement only every 24 hours
                "use_explain_analyze": True,  # Run "explain analyze" instead of only "explain"
            }
        }
    ```
    SELECTNuse_explain_analyzeFANALYZE zEXPLAIN %s c                 S   s   g | ]}|qS  r   ).0rowr   r   d/var/www/html/pca-backend/venv/lib/python3.10/site-packages/sentry_sdk/db/explain_plan/sqlalchemy.py
<listcomp>.   s    z/attach_explain_plan_to_span.<locals>.<listcomp>zdb.explain_plan)	stripupper
startswithr   getexecuter   set_datar   )	span
connection	statement
parametersoptionsanalyzeexplain_statementresultexplain_planr   r   r   attach_explain_plan_to_span   s   
r"   N)
__future__r   sentry_sdk.constsr   sentry_sdk.db.explain_planr   r   sentry_sdk.integrationsr   sqlalchemy.sqlr   ImportErrortypingr   sentry_sdk.tracingr	   r"   r   r   r   r   <module>   s    