We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Cannot call sqlite3.backup(db) on a TracedSQLite object
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.

### Which version of dd-trace-py are you using?
1.5.0
### Which version of pip are you using?
21.1.1
_ddtrace requires pip>=18 to install one of our pre-built wheels_

### Which version of the libraries are you using?

You can copy/paste the output of `pip freeze` here.

```
ddtrace==1.5.0
```

### How can we reproduce your problem?

```
from ddtrace import config, patch_all
import sqlite3

config.env = "test"  # the environment the application is in
config.service = "app"  # name of your application
config.version = "v1"  # version of your application
patch_all()

src = sqlite3.connect("1.db")
dst = sqlite3.connect("2.db")
with dst:
    src.backup(dst, pages=1)
dst.close()
src.close()
```

### What is the result that you get?

The following TypeError
```
TypeError: backup() argument 1 must be sqlite3.Connection, not TracedSQLite
```

### What is the result that you expected?

The function should succeed without error.


--- 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/sqlite3/patch.py`
Content:
```
1 import os
2 import sqlite3
3 import sqlite3.dbapi2
4 
5 from ddtrace import config
6 from ddtrace.vendor import wrapt
7 
8 from ...contrib.dbapi import FetchTracedCursor
9 from ...contrib.dbapi import TracedConnection
10 from ...contrib.dbapi import TracedCursor
11 from ...internal.utils.formats import asbool
12 from ...pin import Pin
13 
14 
15 # Original connect method
16 _connect = sqlite3.connect
17 
18 config._add(
19     "sqlite",
20     dict(
21         _default_service="sqlite",
22         _dbapi_span_name_prefix="sqlite",
23         trace_fetch_methods=asbool(os.getenv("DD_SQLITE_TRACE_FETCH_METHODS", default=False)),
24     ),
25 )
26 
27 
28 def patch():
29     wrapped = wrapt.FunctionWrapper(_connect, traced_connect)
30 
31     setattr(sqlite3, "connect", wrapped)
32     setattr(sqlite3.dbapi2, "connect", wrapped)
33 
34 
35 def unpatch():
36     sqlite3.connect = _connect
37     sqlite3.dbapi2.connect = _connect
38 
39 
40 def traced_connect(func, _, args, kwargs):
41     conn = func(*args, **kwargs)
42     return patch_conn(conn)
43 
44 
45 def patch_conn(conn):
46     wrapped = TracedSQLite(conn)
47     Pin().onto(wrapped)
48     return wrapped
49 
50 
51 class TracedSQLiteCursor(TracedCursor):
52     def executemany(self, *args, **kwargs):
53         # DEV: SQLite3 Cursor.execute always returns back the cursor instance
54         super(TracedSQLiteCursor, self).executemany(*args, **kwargs)
55         return self
56 
57     def execute(self, *args, **kwargs):
58         # DEV: SQLite3 Cursor.execute always returns back the cursor instance
59         super(TracedSQLiteCursor, self).execute(*args, **kwargs)
60         return self
61 
62 
63 class TracedSQLiteFetchCursor(TracedSQLiteCursor, FetchTracedCursor):
64     pass
65 
66 
67 class TracedSQLite(TracedConnection):
68     def __init__(self, conn, pin=None, cursor_cls=None):
69         if not cursor_cls:
70             # Do not trace `fetch*` methods by default
71             cursor_cls = TracedSQLiteFetchCursor if config.sqlite.trace_fetch_methods else TracedSQLiteCursor
72 
73             super(TracedSQLite, self).__init__(conn, pin=pin, cfg=config.sqlite, cursor_cls=cursor_cls)
74 
75     def execute(self, *args, **kwargs):
76         # sqlite has a few extra sugar functions
77         return self.cursor().execute(*args, **kwargs)
78
```
--- 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()

```

diff --git a/ddtrace/contrib/sqlite3/patch.py b/ddtrace/contrib/sqlite3/patch.py
--- a/ddtrace/contrib/sqlite3/patch.py
+++ b/ddtrace/contrib/sqlite3/patch.py
@@ -1,6 +1,7 @@
 import os
 import sqlite3
 import sqlite3.dbapi2
+import sys
 
 from ddtrace import config
 from ddtrace.vendor import wrapt
@@ -75,3 +76,13 @@
     def execute(self, *args, **kwargs):
         # sqlite has a few extra sugar functions
         return self.cursor().execute(*args, **kwargs)
+
+    # backup was added in Python 3.7
+    if sys.version_info >= (3, 7, 0):
+
+        def backup(self, target, *args, **kwargs):
+            # sqlite3 checks the type of `target`, it cannot be a wrapped connection
+            # https://github.com/python/cpython/blob/4652093e1b816b78e9a585d671a807ce66427417/Modules/_sqlite/connection.c#L1897-L1899
+            if isinstance(target, TracedConnection):
+                target = target.__wrapped__
+            return self.__wrapped__.backup(target, *args, **kwargs)

{"golden_diff": "diff --git a/ddtrace/contrib/sqlite3/patch.py b/ddtrace/contrib/sqlite3/patch.py\n--- a/ddtrace/contrib/sqlite3/patch.py\n+++ b/ddtrace/contrib/sqlite3/patch.py\n@@ -1,6 +1,7 @@\n import os\n import sqlite3\n import sqlite3.dbapi2\n+import sys\n \n from ddtrace import config\n from ddtrace.vendor import wrapt\n@@ -75,3 +76,13 @@\n     def execute(self, *args, **kwargs):\n         # sqlite has a few extra sugar functions\n         return self.cursor().execute(*args, **kwargs)\n+\n+    # backup was added in Python 3.7\n+    if sys.version_info >= (3, 7, 0):\n+\n+        def backup(self, target, *args, **kwargs):\n+            # sqlite3 checks the type of `target`, it cannot be a wrapped connection\n+            # https://github.com/python/cpython/blob/4652093e1b816b78e9a585d671a807ce66427417/Modules/_sqlite/connection.c#L1897-L1899\n+            if isinstance(target, TracedConnection):\n+                target = target.__wrapped__\n+            return self.__wrapped__.backup(target, *args, **kwargs)\n", "issue": "Cannot call sqlite3.backup(db) on a TracedSQLite object\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### Which version of dd-trace-py are you using?\r\n1.5.0\r\n### Which version of pip are you using?\r\n21.1.1\r\n_ddtrace requires pip>=18 to install one of our pre-built wheels_\r\n\r\n### Which version of the libraries are you using?\r\n\r\nYou can copy/paste the output of `pip freeze` here.\r\n\r\n```\r\nddtrace==1.5.0\r\n```\r\n\r\n### How can we reproduce your problem?\r\n\r\n```\r\nfrom ddtrace import config, patch_all\r\nimport sqlite3\r\n\r\nconfig.env = \"test\"  # the environment the application is in\r\nconfig.service = \"app\"  # name of your application\r\nconfig.version = \"v1\"  # version of your application\r\npatch_all()\r\n\r\nsrc = sqlite3.connect(\"1.db\")\r\ndst = sqlite3.connect(\"2.db\")\r\nwith dst:\r\n    src.backup(dst, pages=1)\r\ndst.close()\r\nsrc.close()\r\n```\r\n\r\n### What is the result that you get?\r\n\r\nThe following TypeError\r\n```\r\nTypeError: backup() argument 1 must be sqlite3.Connection, not TracedSQLite\r\n```\r\n\r\n### What is the result that you expected?\r\n\r\nThe function should succeed without error.\r\n\n", "before_files": [{"content": "import os\nimport sqlite3\nimport sqlite3.dbapi2\n\nfrom ddtrace import config\nfrom ddtrace.vendor import wrapt\n\nfrom ...contrib.dbapi import FetchTracedCursor\nfrom ...contrib.dbapi import TracedConnection\nfrom ...contrib.dbapi import TracedCursor\nfrom ...internal.utils.formats import asbool\nfrom ...pin import Pin\n\n\n# Original connect method\n_connect = sqlite3.connect\n\nconfig._add(\n    \"sqlite\",\n    dict(\n        _default_service=\"sqlite\",\n        _dbapi_span_name_prefix=\"sqlite\",\n        trace_fetch_methods=asbool(os.getenv(\"DD_SQLITE_TRACE_FETCH_METHODS\", default=False)),\n    ),\n)\n\n\ndef patch():\n    wrapped = wrapt.FunctionWrapper(_connect, traced_connect)\n\n    setattr(sqlite3, \"connect\", wrapped)\n    setattr(sqlite3.dbapi2, \"connect\", wrapped)\n\n\ndef unpatch():\n    sqlite3.connect = _connect\n    sqlite3.dbapi2.connect = _connect\n\n\ndef traced_connect(func, _, args, kwargs):\n    conn = func(*args, **kwargs)\n    return patch_conn(conn)\n\n\ndef patch_conn(conn):\n    wrapped = TracedSQLite(conn)\n    Pin().onto(wrapped)\n    return wrapped\n\n\nclass TracedSQLiteCursor(TracedCursor):\n    def executemany(self, *args, **kwargs):\n        # DEV: SQLite3 Cursor.execute always returns back the cursor instance\n        super(TracedSQLiteCursor, self).executemany(*args, **kwargs)\n        return self\n\n    def execute(self, *args, **kwargs):\n        # DEV: SQLite3 Cursor.execute always returns back the cursor instance\n        super(TracedSQLiteCursor, self).execute(*args, **kwargs)\n        return self\n\n\nclass TracedSQLiteFetchCursor(TracedSQLiteCursor, FetchTracedCursor):\n    pass\n\n\nclass TracedSQLite(TracedConnection):\n    def __init__(self, conn, pin=None, cursor_cls=None):\n        if not cursor_cls:\n            # Do not trace `fetch*` methods by default\n            cursor_cls = TracedSQLiteFetchCursor if config.sqlite.trace_fetch_methods else TracedSQLiteCursor\n\n            super(TracedSQLite, self).__init__(conn, pin=pin, cfg=config.sqlite, cursor_cls=cursor_cls)\n\n    def execute(self, *args, **kwargs):\n        # sqlite has a few extra sugar functions\n        return self.cursor().execute(*args, **kwargs)\n", "path": "ddtrace/contrib/sqlite3/patch.py"}], "after_files": [{"content": "import os\nimport sqlite3\nimport sqlite3.dbapi2\nimport sys\n\nfrom ddtrace import config\nfrom ddtrace.vendor import wrapt\n\nfrom ...contrib.dbapi import FetchTracedCursor\nfrom ...contrib.dbapi import TracedConnection\nfrom ...contrib.dbapi import TracedCursor\nfrom ...internal.utils.formats import asbool\nfrom ...pin import Pin\n\n\n# Original connect method\n_connect = sqlite3.connect\n\nconfig._add(\n    \"sqlite\",\n    dict(\n        _default_service=\"sqlite\",\n        _dbapi_span_name_prefix=\"sqlite\",\n        trace_fetch_methods=asbool(os.getenv(\"DD_SQLITE_TRACE_FETCH_METHODS\", default=False)),\n    ),\n)\n\n\ndef patch():\n    wrapped = wrapt.FunctionWrapper(_connect, traced_connect)\n\n    setattr(sqlite3, \"connect\", wrapped)\n    setattr(sqlite3.dbapi2, \"connect\", wrapped)\n\n\ndef unpatch():\n    sqlite3.connect = _connect\n    sqlite3.dbapi2.connect = _connect\n\n\ndef traced_connect(func, _, args, kwargs):\n    conn = func(*args, **kwargs)\n    return patch_conn(conn)\n\n\ndef patch_conn(conn):\n    wrapped = TracedSQLite(conn)\n    Pin().onto(wrapped)\n    return wrapped\n\n\nclass TracedSQLiteCursor(TracedCursor):\n    def executemany(self, *args, **kwargs):\n        # DEV: SQLite3 Cursor.execute always returns back the cursor instance\n        super(TracedSQLiteCursor, self).executemany(*args, **kwargs)\n        return self\n\n    def execute(self, *args, **kwargs):\n        # DEV: SQLite3 Cursor.execute always returns back the cursor instance\n        super(TracedSQLiteCursor, self).execute(*args, **kwargs)\n        return self\n\n\nclass TracedSQLiteFetchCursor(TracedSQLiteCursor, FetchTracedCursor):\n    pass\n\n\nclass TracedSQLite(TracedConnection):\n    def __init__(self, conn, pin=None, cursor_cls=None):\n        if not cursor_cls:\n            # Do not trace `fetch*` methods by default\n            cursor_cls = TracedSQLiteFetchCursor if config.sqlite.trace_fetch_methods else TracedSQLiteCursor\n\n            super(TracedSQLite, self).__init__(conn, pin=pin, cfg=config.sqlite, cursor_cls=cursor_cls)\n\n    def execute(self, *args, **kwargs):\n        # sqlite has a few extra sugar functions\n        return self.cursor().execute(*args, **kwargs)\n\n    # backup was added in Python 3.7\n    if sys.version_info >= (3, 7, 0):\n\n        def backup(self, target, *args, **kwargs):\n            # sqlite3 checks the type of `target`, it cannot be a wrapped connection\n            # https://github.com/python/cpython/blob/4652093e1b816b78e9a585d671a807ce66427417/Modules/_sqlite/connection.c#L1897-L1899\n            if isinstance(target, TracedConnection):\n                target = target.__wrapped__\n            return self.__wrapped__.backup(target, *args, **kwargs)\n", "path": "ddtrace/contrib/sqlite3/patch.py"}]}