prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Instrumenting ambiguity: Integrate with SQLAlchemy or not when underlying psycopg2 used
  <!--
  Thanks for taking the time for reporting an issue!
  
  Before reporting an issue on dd-trace-py, please be sure to provide all
  necessary information.
  
  If you're hitting a bug, make sure that you're using the latest version of this
  library.
  -->
  
  ### Summary of problem
  
  It's not immediately clear from documentation if going through the trouble of patching and instrumenting SQLAlchemy provides any additional details over the auto-instrumented psycopg2 via `ddtrace-run`.
  
  I currently have a Flask app using SQLAlchemy by hand (not Flask-SQLAlchemy) which connects to a Postgres database via psycopg2. Running my app with `ddtrace-run` in gunicorn successfully reports the Flask and Postgres services to APM. However upon seeing that ddtrace additionally has an [integration to SQLAlchemy](https://ddtrace.readthedocs.io/en/v1.7.1/integrations.html#sqlalchemy), I'm curious if it provides any added benefit on top of the auto instrumentation. Is it meant to be complimentary? Or is it meant to be an alternative/replacement mechanism for instrumenting the database/what psycopg2 integration would report.
  
  I ending up debugging into `ddtrace.contrib.sqlalchemy.engine.EngineTracer` in my application to see what `Pin.get_from(self.engine)` would report without any overrides. It gave me:
  
  ```
  Pin(service=postgres, tags=None, tracer=<ddtrace.tracer.Tracer object at 0xffff8bf3e580>)
  ```
  
  which leads me to believe manual patching and integrating with SQLAlchemy is redundant if I'm using pscopg2 and `ddtrace-run`. Eyeballing the `EngineTracer` source code _appears_ to indicate it adds no additional benefit over psychopg2's auto-instrumentation.
  
  Documentation should be updated (hell, I'd love a confirmatory answer here 😃 ) on whether or not one should even bother going to the trouble of manually patching SQLAlchemy in this context if they already have/use/configure SQLAlchemy's engine to connect to a postgres DB provided by psycopg2. Something to the effect, in SQLAlchemy's section:
  
  > # SQLAlchemy
  > 
  > Integrating with SQLAlchemy is not necessary if you're integrating psycopg and SQLAlchemy connects to a Postgres database.
  >
  > To trace sqlalchemy queries, add instrumentation to the engine class using the patch method that must be called before importing sqlalchemy:
  > ...
  
  ### Which version of dd-trace-py are you using?
  
  1.7.1
  
  ### Which version of pip are you using?
  
  22.3.1
  
  ### Which libraries and their versions are you using?
  
  ```
  Flask==1.1.1
  SQLAlchemy==1.3.11
  ddtrace==1.7.1
  psycopg2-binary==2.9.1
  ```
  
  ### How can we reproduce your problem?
  
  N/A
  
  ### What is the result that you get?
  
  N/A
  
  ### What is the result that you expected?
  
  N/A
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `ddtrace/contrib/sqlalchemy/__init__.py`
  Content:
  ```
  1 """
  2 To trace sqlalchemy queries, add instrumentation to the engine class
  3 using the patch method that **must be called before** importing sqlalchemy::
  4 
  5     # patch before importing `create_engine`
  6     from ddtrace import Pin, patch
  7     patch(sqlalchemy=True)
  8 
  9     # use SQLAlchemy as usual
  10     from sqlalchemy import create_engine
  11 
  12     engine = create_engine('sqlite:///:memory:')
  13     engine.connect().execute("SELECT COUNT(*) FROM users")
  14 
  15     # Use a PIN to specify metadata related to this engine
  16     Pin.override(engine, service='replica-db')
  17 """
  18 from ...internal.utils.importlib import require_modules
  19 
  20 
  21 required_modules = ["sqlalchemy", "sqlalchemy.event"]
  22 
  23 with require_modules(required_modules) as missing_modules:
  24     if not missing_modules:
  25         from .engine import trace_engine
  26         from .patch import patch
  27         from .patch import unpatch
  28 
  29         __all__ = ["trace_engine", "patch", "unpatch"]
  30
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/ddtrace/contrib/sqlalchemy/__init__.py b/ddtrace/contrib/sqlalchemy/__init__.py
  --- a/ddtrace/contrib/sqlalchemy/__init__.py
  +++ b/ddtrace/contrib/sqlalchemy/__init__.py
  @@ -1,4 +1,8 @@
   """
  +Enabling the SQLAlchemy integration is only necessary if there is no
  +instrumentation available or enabled for the underlying database engine (e.g.
  +pymysql, psycopg, mysql-connector, etc.).
  +
   To trace sqlalchemy queries, add instrumentation to the engine class
   using the patch method that **must be called before** importing sqlalchemy::
  
verification_info: {"golden_diff": "diff --git a/ddtrace/contrib/sqlalchemy/__init__.py b/ddtrace/contrib/sqlalchemy/__init__.py\n--- a/ddtrace/contrib/sqlalchemy/__init__.py\n+++ b/ddtrace/contrib/sqlalchemy/__init__.py\n@@ -1,4 +1,8 @@\n \"\"\"\n+Enabling the SQLAlchemy integration is only necessary if there is no\n+instrumentation available or enabled for the underlying database engine (e.g.\n+pymysql, psycopg, mysql-connector, etc.).\n+\n To trace sqlalchemy queries, add instrumentation to the engine class\n using the patch method that **must be called before** importing sqlalchemy::\n", "issue": "Instrumenting ambiguity: Integrate with SQLAlchemy or not when underlying psycopg2 used\n<!--\r\nThanks for taking the time for reporting an issue!\r\n\r\nBefore reporting an issue on dd-trace-py, please be sure to provide all\r\nnecessary information.\r\n\r\nIf you're hitting a bug, make sure that you're using the latest version of this\r\nlibrary.\r\n-->\r\n\r\n### Summary of problem\r\n\r\nIt's not immediately clear from documentation if going through the trouble of patching and instrumenting SQLAlchemy provides any additional details over the auto-instrumented psycopg2 via `ddtrace-run`.\r\n\r\nI currently have a Flask app using SQLAlchemy by hand (not Flask-SQLAlchemy) which connects to a Postgres database via psycopg2. Running my app with `ddtrace-run` in gunicorn successfully reports the Flask and Postgres services to APM. However upon seeing that ddtrace additionally has an [integration to SQLAlchemy](https://ddtrace.readthedocs.io/en/v1.7.1/integrations.html#sqlalchemy), I'm curious if it provides any added benefit on top of the auto instrumentation. Is it meant to be complimentary? Or is it meant to be an alternative/replacement mechanism for instrumenting the database/what psycopg2 integration would report.\r\n\r\nI ending up debugging into `ddtrace.contrib.sqlalchemy.engine.EngineTracer` in my application to see what `Pin.get_from(self.engine)` would report without any overrides. It gave me:\r\n\r\n```\r\nPin(service=postgres, tags=None, tracer=<ddtrace.tracer.Tracer object at 0xffff8bf3e580>)\r\n```\r\n\r\nwhich leads me to believe manual patching and integrating with SQLAlchemy is redundant if I'm using pscopg2 and `ddtrace-run`. Eyeballing the `EngineTracer` source code _appears_ to indicate it adds no additional benefit over psychopg2's auto-instrumentation.\r\n\r\nDocumentation should be updated (hell, I'd love a confirmatory answer here \ud83d\ude03 ) on whether or not one should even bother going to the trouble of manually patching SQLAlchemy in this context if they already have/use/configure SQLAlchemy's engine to connect to a postgres DB provided by psycopg2. Something to the effect, in SQLAlchemy's section:\r\n\r\n> # SQLAlchemy\r\n> \r\n> Integrating with SQLAlchemy is not necessary if you're integrating psycopg and SQLAlchemy connects to a Postgres database.\r\n>\r\n> To trace sqlalchemy queries, add instrumentation to the engine class using the patch method that must be called before importing sqlalchemy:\r\n> ...\r\n\r\n### Which version of dd-trace-py are you using?\r\n\r\n1.7.1\r\n\r\n### Which version of pip are you using?\r\n\r\n22.3.1\r\n\r\n### Which libraries and their versions are you using?\r\n\r\n```\r\nFlask==1.1.1\r\nSQLAlchemy==1.3.11\r\nddtrace==1.7.1\r\npsycopg2-binary==2.9.1\r\n```\r\n\r\n### How can we reproduce your problem?\r\n\r\nN/A\r\n\r\n### What is the result that you get?\r\n\r\nN/A\r\n\r\n### What is the result that you expected?\r\n\r\nN/A\n", "before_files": [{"content": "\"\"\"\nTo trace sqlalchemy queries, add instrumentation to the engine class\nusing the patch method that **must be called before** importing sqlalchemy::\n\n    # patch before importing `create_engine`\n    from ddtrace import Pin, patch\n    patch(sqlalchemy=True)\n\n    # use SQLAlchemy as usual\n    from sqlalchemy import create_engine\n\n    engine = create_engine('sqlite:///:memory:')\n    engine.connect().execute(\"SELECT COUNT(*) FROM users\")\n\n    # Use a PIN to specify metadata related to this engine\n    Pin.override(engine, service='replica-db')\n\"\"\"\nfrom ...internal.utils.importlib import require_modules\n\n\nrequired_modules = [\"sqlalchemy\", \"sqlalchemy.event\"]\n\nwith require_modules(required_modules) as missing_modules:\n    if not missing_modules:\n        from .engine import trace_engine\n        from .patch import patch\n        from .patch import unpatch\n\n        __all__ = [\"trace_engine\", \"patch\", \"unpatch\"]\n", "path": "ddtrace/contrib/sqlalchemy/__init__.py"}], "after_files": [{"content": "\"\"\"\nEnabling the SQLAlchemy integration is only necessary if there is no\ninstrumentation available or enabled for the underlying database engine (e.g.\npymysql, psycopg, mysql-connector, etc.).\n\nTo trace sqlalchemy queries, add instrumentation to the engine class\nusing the patch method that **must be called before** importing sqlalchemy::\n\n    # patch before importing `create_engine`\n    from ddtrace import Pin, patch\n    patch(sqlalchemy=True)\n\n    # use SQLAlchemy as usual\n    from sqlalchemy import create_engine\n\n    engine = create_engine('sqlite:///:memory:')\n    engine.connect().execute(\"SELECT COUNT(*) FROM users\")\n\n    # Use a PIN to specify metadata related to this engine\n    Pin.override(engine, service='replica-db')\n\"\"\"\nfrom ...internal.utils.importlib import require_modules\n\n\nrequired_modules = [\"sqlalchemy\", \"sqlalchemy.event\"]\n\nwith require_modules(required_modules) as missing_modules:\n    if not missing_modules:\n        from .engine import trace_engine\n        from .patch import patch\n        from .patch import unpatch\n\n        __all__ = [\"trace_engine\", \"patch\", \"unpatch\"]\n", "path": "ddtrace/contrib/sqlalchemy/__init__.py"}]}