We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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


--- 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/bottle/trace.py`
Content:
```
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 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/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)

{"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"}], "after_files": [{"content": "# 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    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.distributed_tracing = distributed_tracing\n        self.tracer.set_service_info(\n            service=service,\n            app='bottle',\n            app_type=AppTypes.web,\n        )\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 = '{} {}'.format(request.method, 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"}]}