prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  psycopg2 cursor's __enter__ method is not patched to be traced
  See behavior here:
  
  ```python
  >>> import ddtrace
  >>> ddtrace.patch_all()
  >>> import psycopg2
  >>> conn = psycopg2.connect('postgresql://localhost')
  >>> print(type(conn.cursor()))
  <class 'ddtrace.contrib.dbapi.TracedCursor'>
  >>> with conn.cursor() as cur:
  ...     print(type(cur))
  <type 'psycopg2.extensions.cursor'>
  ```
  
  </issue>
  <code>
  [start of ddtrace/contrib/dbapi/__init__.py]
  1 """
  2 Generic dbapi tracing code.
  3 """
  4 
  5 # stdlib
  6 import logging
  7 
  8 # 3p
  9 import wrapt
  10 
  11 # project
  12 from ddtrace import Pin
  13 from ddtrace.ext import sql
  14 
  15 
  16 log = logging.getLogger(__name__)
  17 
  18 
  19 class TracedCursor(wrapt.ObjectProxy):
  20     """ TracedCursor wraps a psql cursor and traces it's queries. """
  21 
  22     _datadog_pin = None
  23     _datadog_name = None
  24 
  25     def __init__(self, cursor, pin):
  26         super(TracedCursor, self).__init__(cursor)
  27         self._datadog_pin = pin
  28         name = pin.app or 'sql'
  29         self._datadog_name = '%s.query' % name
  30 
  31     def executemany(self, query, *args, **kwargs):
  32         pin = self._datadog_pin
  33         if not pin or not pin.enabled():
  34             return self.__wrapped__.executemany(query, *args, **kwargs)
  35         service = pin.service
  36 
  37         # FIXME[matt] properly handle kwargs here. arg names can be different
  38         # with different libs.
  39         with pin.tracer.trace(self._datadog_name, service=service, resource=query) as s:
  40             s.span_type = sql.TYPE
  41             s.set_tag(sql.QUERY, query)
  42             s.set_tags(pin.tags)
  43             s.set_tag("sql.executemany", "true")
  44             try:
  45                 return self.__wrapped__.executemany(query, *args, **kwargs)
  46             finally:
  47                 s.set_metric("db.rowcount", self.rowcount)
  48 
  49     def execute(self, query, *args, **kwargs):
  50         pin = self._datadog_pin
  51         if not pin or not pin.enabled():
  52             return self.__wrapped__.execute(query, *args, **kwargs)
  53 
  54         service = pin.service
  55         with pin.tracer.trace(self._datadog_name, service=service, resource=query) as s:
  56             s.span_type = sql.TYPE
  57             s.set_tag(sql.QUERY, query)
  58             s.set_tags(pin.tags)
  59             try:
  60                 return self.__wrapped__.execute(query, *args, **kwargs)
  61             finally:
  62                 s.set_metric("db.rowcount", self.rowcount)
  63 
  64     def callproc(self, proc, args):
  65         pin = self._datadog_pin
  66         if not pin or not pin.enabled():
  67             return self.__wrapped__.callproc(proc, args)
  68 
  69         with pin.tracer.trace(self._datadog_name, service=pin.service, resource=proc) as s:
  70             s.span_type = sql.TYPE
  71             s.set_tag(sql.QUERY, proc)
  72             s.set_tags(pin.tags)
  73             try:
  74                 return self.__wrapped__.callproc(proc, args)
  75             finally:
  76                 s.set_metric("db.rowcount", self.rowcount)
  77 
  78 
  79 class TracedConnection(wrapt.ObjectProxy):
  80     """ TracedConnection wraps a Connection with tracing code. """
  81 
  82     _datadog_pin = None
  83 
  84     def __init__(self, conn):
  85         super(TracedConnection, self).__init__(conn)
  86         name = _get_vendor(conn)
  87         Pin(service=name, app=name).onto(self)
  88 
  89     def cursor(self, *args, **kwargs):
  90         cursor = self.__wrapped__.cursor(*args, **kwargs)
  91         pin = self._datadog_pin
  92         if not pin:
  93             return cursor
  94         return TracedCursor(cursor, pin)
  95 
  96 
  97 def _get_vendor(conn):
  98     """ Return the vendor (e.g postgres, mysql) of the given
  99         database.
  100     """
  101     try:
  102         name = _get_module_name(conn)
  103     except Exception:
  104         log.debug("couldnt parse module name", exc_info=True)
  105         name = "sql"
  106     return sql.normalize_vendor(name)
  107 
  108 def _get_module_name(conn):
  109     return conn.__class__.__module__.split('.')[0]
  110
  [end of ddtrace/contrib/dbapi/__init__.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/dbapi/__init__.py b/ddtrace/contrib/dbapi/__init__.py
  --- a/ddtrace/contrib/dbapi/__init__.py
  +++ b/ddtrace/contrib/dbapi/__init__.py
  @@ -75,6 +75,15 @@
               finally:
                   s.set_metric("db.rowcount", self.rowcount)
   
  +    def __enter__(self):
  +        # previous versions of the dbapi didn't support context managers. let's
  +        # reference the func that would be called to ensure that errors
  +        # messages will be the same.
  +        self.__wrapped__.__enter__
  +
  +        # and finally, yield the traced cursor.
  +        return self
  +
   
   class TracedConnection(wrapt.ObjectProxy):
       """ TracedConnection wraps a Connection with tracing code. """
  
verification_info: {"golden_diff": "diff --git a/ddtrace/contrib/dbapi/__init__.py b/ddtrace/contrib/dbapi/__init__.py\n--- a/ddtrace/contrib/dbapi/__init__.py\n+++ b/ddtrace/contrib/dbapi/__init__.py\n@@ -75,6 +75,15 @@\n             finally:\n                 s.set_metric(\"db.rowcount\", self.rowcount)\n \n+    def __enter__(self):\n+        # previous versions of the dbapi didn't support context managers. let's\n+        # reference the func that would be called to ensure that errors\n+        # messages will be the same.\n+        self.__wrapped__.__enter__\n+\n+        # and finally, yield the traced cursor.\n+        return self\n+\n \n class TracedConnection(wrapt.ObjectProxy):\n     \"\"\" TracedConnection wraps a Connection with tracing code. \"\"\"\n", "issue": "psycopg2 cursor's __enter__ method is not patched to be traced\nSee behavior here:\r\n\r\n```python\r\n>>> import ddtrace\r\n>>> ddtrace.patch_all()\r\n>>> import psycopg2\r\n>>> conn = psycopg2.connect('postgresql://localhost')\r\n>>> print(type(conn.cursor()))\r\n<class 'ddtrace.contrib.dbapi.TracedCursor'>\r\n>>> with conn.cursor() as cur:\r\n...     print(type(cur))\r\n<type 'psycopg2.extensions.cursor'>\r\n```\n", "before_files": [{"content": "\"\"\"\nGeneric dbapi tracing code.\n\"\"\"\n\n# stdlib\nimport logging\n\n# 3p\nimport wrapt\n\n# project\nfrom ddtrace import Pin\nfrom ddtrace.ext import sql\n\n\nlog = logging.getLogger(__name__)\n\n\nclass TracedCursor(wrapt.ObjectProxy):\n    \"\"\" TracedCursor wraps a psql cursor and traces it's queries. \"\"\"\n\n    _datadog_pin = None\n    _datadog_name = None\n\n    def __init__(self, cursor, pin):\n        super(TracedCursor, self).__init__(cursor)\n        self._datadog_pin = pin\n        name = pin.app or 'sql'\n        self._datadog_name = '%s.query' % name\n\n    def executemany(self, query, *args, **kwargs):\n        pin = self._datadog_pin\n        if not pin or not pin.enabled():\n            return self.__wrapped__.executemany(query, *args, **kwargs)\n        service = pin.service\n\n        # FIXME[matt] properly handle kwargs here. arg names can be different\n        # with different libs.\n        with pin.tracer.trace(self._datadog_name, service=service, resource=query) as s:\n            s.span_type = sql.TYPE\n            s.set_tag(sql.QUERY, query)\n            s.set_tags(pin.tags)\n            s.set_tag(\"sql.executemany\", \"true\")\n            try:\n                return self.__wrapped__.executemany(query, *args, **kwargs)\n            finally:\n                s.set_metric(\"db.rowcount\", self.rowcount)\n\n    def execute(self, query, *args, **kwargs):\n        pin = self._datadog_pin\n        if not pin or not pin.enabled():\n            return self.__wrapped__.execute(query, *args, **kwargs)\n\n        service = pin.service\n        with pin.tracer.trace(self._datadog_name, service=service, resource=query) as s:\n            s.span_type = sql.TYPE\n            s.set_tag(sql.QUERY, query)\n            s.set_tags(pin.tags)\n            try:\n                return self.__wrapped__.execute(query, *args, **kwargs)\n            finally:\n                s.set_metric(\"db.rowcount\", self.rowcount)\n\n    def callproc(self, proc, args):\n        pin = self._datadog_pin\n        if not pin or not pin.enabled():\n            return self.__wrapped__.callproc(proc, args)\n\n        with pin.tracer.trace(self._datadog_name, service=pin.service, resource=proc) as s:\n            s.span_type = sql.TYPE\n            s.set_tag(sql.QUERY, proc)\n            s.set_tags(pin.tags)\n            try:\n                return self.__wrapped__.callproc(proc, args)\n            finally:\n                s.set_metric(\"db.rowcount\", self.rowcount)\n\n\nclass TracedConnection(wrapt.ObjectProxy):\n    \"\"\" TracedConnection wraps a Connection with tracing code. \"\"\"\n\n    _datadog_pin = None\n\n    def __init__(self, conn):\n        super(TracedConnection, self).__init__(conn)\n        name = _get_vendor(conn)\n        Pin(service=name, app=name).onto(self)\n\n    def cursor(self, *args, **kwargs):\n        cursor = self.__wrapped__.cursor(*args, **kwargs)\n        pin = self._datadog_pin\n        if not pin:\n            return cursor\n        return TracedCursor(cursor, pin)\n\n\ndef _get_vendor(conn):\n    \"\"\" Return the vendor (e.g postgres, mysql) of the given\n        database.\n    \"\"\"\n    try:\n        name = _get_module_name(conn)\n    except Exception:\n        log.debug(\"couldnt parse module name\", exc_info=True)\n        name = \"sql\"\n    return sql.normalize_vendor(name)\n\ndef _get_module_name(conn):\n    return conn.__class__.__module__.split('.')[0]\n", "path": "ddtrace/contrib/dbapi/__init__.py"}]}