prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  TracePlugin not working for bottle + python 2.7.x
  Hi, we have a backend using python 2.7.x, Im integrating Datadog APM following the documentation and I have the following error:
  ```
  Traceback (most recent call last):
    File "/usr/local/lib/python2.7/site-packages/bottle.py", line 764, in _handle
      return route.call(**args)
    File "/usr/local/lib/python2.7/site-packages/bottle.py", line 1575, in wrapper
      rv = callback(*a, **ka)
    File "/usr/local/lib/python2.7/site-packages/ddtrace/contrib/bottle/trace.py", line 32, in wrapped
      resource = "%s %s" % (request.method, request.route.rule)
    File "/usr/local/lib/python2.7/site-packages/bottle.py", line 1237, in __getattr__
      raise AttributeError('Attribute %r not defined.' % name)
  ```
  
  when I go to trace.py line 32, I find this:
  `resource = "%s %s" % (request.method, request.route.rule)`
  
  somehow request.route doesn't exist, I think that probably is related to a different python or bottle version being used on our end.
  Anyway `route` is already provided as a parameter for this method (`TracePlugin.apply(self, callback, route):`) so there's no need to call `request.route.rule`, you can call `route.rule` instead,
  `resource = "%s %s" % (request.method, route.rule)`
  
  Otherwise let me know if you have more details about this error and what's the right way to solve it,
  thanks
  
  
  </issue>
  <code>
  [start of ddtrace/contrib/bottle/trace.py]
  1 
  2 # 3p
  3 from bottle import response, request
  4 
  5 # stdlib
  6 import ddtrace
  7 from ddtrace.ext import http, AppTypes
  8 
  9 # project
  10 from ...propagation.http import HTTPPropagator
  11 
  12 class TracePlugin(object):
  13 
  14     name = 'trace'
  15     api = 2
  16 
  17     def __init__(self, service="bottle", tracer=None, distributed_tracing=None):
  18         self.service = service
  19         self.tracer = tracer or ddtrace.tracer
  20         self.tracer.set_service_info(
  21             service=service,
  22             app="bottle",
  23             app_type=AppTypes.web)
  24         self.distributed_tracing = distributed_tracing
  25 
  26     def apply(self, callback, route):
  27 
  28         def wrapped(*args, **kwargs):
  29             if not self.tracer or not self.tracer.enabled:
  30                 return callback(*args, **kwargs)
  31 
  32             resource = "%s %s" % (request.method, request.route.rule)
  33 
  34             # Propagate headers such as x-datadog-trace-id.
  35             if self.distributed_tracing:
  36                 propagator = HTTPPropagator()
  37                 context = propagator.extract(request.headers)
  38                 if context.trace_id:
  39                     self.tracer.context_provider.activate(context)
  40 
  41             with self.tracer.trace("bottle.request", service=self.service, resource=resource) as s:
  42                 code = 0
  43                 try:
  44                     return callback(*args, **kwargs)
  45                 except Exception:
  46                     # bottle doesn't always translate unhandled exceptions, so
  47                     # we mark it here.
  48                     code = 500
  49                     raise
  50                 finally:
  51                     s.set_tag(http.STATUS_CODE, code or response.status_code)
  52                     s.set_tag(http.URL, request.path)
  53                     s.set_tag(http.METHOD, request.method)
  54 
  55         return wrapped
  56
  [end of ddtrace/contrib/bottle/trace.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/bottle/trace.py b/ddtrace/contrib/bottle/trace.py
  --- a/ddtrace/contrib/bottle/trace.py
  +++ b/ddtrace/contrib/bottle/trace.py
  @@ -1,4 +1,3 @@
  -
   # 3p
   from bottle import response, request
   
  @@ -10,18 +9,18 @@
   from ...propagation.http import HTTPPropagator
   
   class TracePlugin(object):
  -
       name = 'trace'
       api = 2
   
  -    def __init__(self, service="bottle", tracer=None, distributed_tracing=None):
  +    def __init__(self, service='bottle', tracer=None, distributed_tracing=None):
           self.service = service
           self.tracer = tracer or ddtrace.tracer
  +        self.distributed_tracing = distributed_tracing
           self.tracer.set_service_info(
               service=service,
  -            app="bottle",
  -            app_type=AppTypes.web)
  -        self.distributed_tracing = distributed_tracing
  +            app='bottle',
  +            app_type=AppTypes.web,
  +        )
   
       def apply(self, callback, route):
   
  @@ -29,7 +28,7 @@
               if not self.tracer or not self.tracer.enabled:
                   return callback(*args, **kwargs)
   
  -            resource = "%s %s" % (request.method, request.route.rule)
  +            resource = '{} {}'.format(request.method, route.rule)
   
               # Propagate headers such as x-datadog-trace-id.
               if self.distributed_tracing:
  @@ -38,7 +37,7 @@
                   if context.trace_id:
                       self.tracer.context_provider.activate(context)
   
  -            with self.tracer.trace("bottle.request", service=self.service, resource=resource) as s:
  +            with self.tracer.trace('bottle.request', service=self.service, resource=resource) as s:
                   code = 0
                   try:
                       return callback(*args, **kwargs)
  
verification_info: {"golden_diff": "diff --git a/ddtrace/contrib/bottle/trace.py b/ddtrace/contrib/bottle/trace.py\n--- a/ddtrace/contrib/bottle/trace.py\n+++ b/ddtrace/contrib/bottle/trace.py\n@@ -1,4 +1,3 @@\n-\n # 3p\n from bottle import response, request\n \n@@ -10,18 +9,18 @@\n from ...propagation.http import HTTPPropagator\n \n class TracePlugin(object):\n-\n     name = 'trace'\n     api = 2\n \n-    def __init__(self, service=\"bottle\", tracer=None, distributed_tracing=None):\n+    def __init__(self, service='bottle', tracer=None, distributed_tracing=None):\n         self.service = service\n         self.tracer = tracer or ddtrace.tracer\n+        self.distributed_tracing = distributed_tracing\n         self.tracer.set_service_info(\n             service=service,\n-            app=\"bottle\",\n-            app_type=AppTypes.web)\n-        self.distributed_tracing = distributed_tracing\n+            app='bottle',\n+            app_type=AppTypes.web,\n+        )\n \n     def apply(self, callback, route):\n \n@@ -29,7 +28,7 @@\n             if not self.tracer or not self.tracer.enabled:\n                 return callback(*args, **kwargs)\n \n-            resource = \"%s %s\" % (request.method, request.route.rule)\n+            resource = '{} {}'.format(request.method, route.rule)\n \n             # Propagate headers such as x-datadog-trace-id.\n             if self.distributed_tracing:\n@@ -38,7 +37,7 @@\n                 if context.trace_id:\n                     self.tracer.context_provider.activate(context)\n \n-            with self.tracer.trace(\"bottle.request\", service=self.service, resource=resource) as s:\n+            with self.tracer.trace('bottle.request', service=self.service, resource=resource) as s:\n                 code = 0\n                 try:\n                     return callback(*args, **kwargs)\n", "issue": "TracePlugin not working for bottle + python 2.7.x\nHi, we have a backend using python 2.7.x, Im integrating Datadog APM following the documentation and I have the following error:\r\n```\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python2.7/site-packages/bottle.py\", line 764, in _handle\r\n    return route.call(**args)\r\n  File \"/usr/local/lib/python2.7/site-packages/bottle.py\", line 1575, in wrapper\r\n    rv = callback(*a, **ka)\r\n  File \"/usr/local/lib/python2.7/site-packages/ddtrace/contrib/bottle/trace.py\", line 32, in wrapped\r\n    resource = \"%s %s\" % (request.method, request.route.rule)\r\n  File \"/usr/local/lib/python2.7/site-packages/bottle.py\", line 1237, in __getattr__\r\n    raise AttributeError('Attribute %r not defined.' % name)\r\n```\r\n\r\nwhen I go to trace.py line 32, I find this:\r\n`resource = \"%s %s\" % (request.method, request.route.rule)`\r\n\r\nsomehow request.route doesn't exist, I think that probably is related to a different python or bottle version being used on our end.\r\nAnyway `route` is already provided as a parameter for this method (`TracePlugin.apply(self, callback, route):`) so there's no need to call `request.route.rule`, you can call `route.rule` instead,\r\n`resource = \"%s %s\" % (request.method, route.rule)`\r\n\r\nOtherwise let me know if you have more details about this error and what's the right way to solve it,\r\nthanks\r\n\n", "before_files": [{"content": "\n# 3p\nfrom bottle import response, request\n\n# stdlib\nimport ddtrace\nfrom ddtrace.ext import http, AppTypes\n\n# project\nfrom ...propagation.http import HTTPPropagator\n\nclass TracePlugin(object):\n\n    name = 'trace'\n    api = 2\n\n    def __init__(self, service=\"bottle\", tracer=None, distributed_tracing=None):\n        self.service = service\n        self.tracer = tracer or ddtrace.tracer\n        self.tracer.set_service_info(\n            service=service,\n            app=\"bottle\",\n            app_type=AppTypes.web)\n        self.distributed_tracing = distributed_tracing\n\n    def apply(self, callback, route):\n\n        def wrapped(*args, **kwargs):\n            if not self.tracer or not self.tracer.enabled:\n                return callback(*args, **kwargs)\n\n            resource = \"%s %s\" % (request.method, request.route.rule)\n\n            # Propagate headers such as x-datadog-trace-id.\n            if self.distributed_tracing:\n                propagator = HTTPPropagator()\n                context = propagator.extract(request.headers)\n                if context.trace_id:\n                    self.tracer.context_provider.activate(context)\n\n            with self.tracer.trace(\"bottle.request\", service=self.service, resource=resource) as s:\n                code = 0\n                try:\n                    return callback(*args, **kwargs)\n                except Exception:\n                    # bottle doesn't always translate unhandled exceptions, so\n                    # we mark it here.\n                    code = 500\n                    raise\n                finally:\n                    s.set_tag(http.STATUS_CODE, code or response.status_code)\n                    s.set_tag(http.URL, request.path)\n                    s.set_tag(http.METHOD, request.method)\n\n        return wrapped\n", "path": "ddtrace/contrib/bottle/trace.py"}]}