prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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.
  
  
  </issue>
  <code>
  [start of ddtrace/contrib/sqlite3/patch.py]
  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 of ddtrace/contrib/sqlite3/patch.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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)
  
verification_info: {"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"}]}