We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
DDtrace Flask middleware logging as flask instead of ddtrace
Here:
https://github.com/DataDog/dd-trace-py/blob/master/ddtrace/contrib/flask/middleware.py#L31

You attach to flask's logger and log that line. Could you log it as ddtrace (using log.info) instead so that we can configure ddtrace's log handlers appropriately without having to create custom log filters?

--- 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/flask/middleware.py`
Content:
```
1 """
2 Datadog tracing code for flask.
3 
4 Installing the blinker library will allow the tracing middleware to collect
5 more exception info.
6 """
7 
8 # stdlib
9 import logging
10 
11 # project
12 from ... import compat
13 from ...ext import http, errors, AppTypes
14 from ...propagation.http import HTTPPropagator
15 
16 # 3p
17 import flask.templating
18 from flask import g, request, signals
19 
20 
21 log = logging.getLogger(__name__)
22 
23 
24 SPAN_NAME = 'flask.request'
25 
26 
27 class TraceMiddleware(object):
28 
29     def __init__(self, app, tracer, service="flask", use_signals=True, distributed_tracing=False):
30         self.app = app
31         self.app.logger.info("initializing trace middleware")
32 
33         self._tracer = tracer
34         self._service = service
35         self._use_distributed_tracing = distributed_tracing
36         self.use_signals = use_signals
37 
38         self._tracer.set_service_info(
39             service=service,
40             app="flask",
41             app_type=AppTypes.web,
42         )
43 
44         # Install hooks which time requests.
45         self.app.before_request(self._before_request)
46         self.app.after_request(self._after_request)
47         self.app.teardown_request(self._teardown_request)
48 
49         # Add exception handling signals. This will annotate exceptions that
50         # are caught and handled in custom user code.
51         # See https://github.com/DataDog/dd-trace-py/issues/390
52         if use_signals and not signals.signals_available:
53             self.app.logger.info(_blinker_not_installed_msg)
54         self.use_signals = use_signals and signals.signals_available
55         timing_signals = {
56             'got_request_exception': self._request_exception,
57         }
58         self._receivers = []
59         if self.use_signals and _signals_exist(timing_signals):
60             self._connect(timing_signals)
61 
62         _patch_render(tracer)
63 
64     def _connect(self, signal_to_handler):
65         connected = True
66         for name, handler in signal_to_handler.items():
67             s = getattr(signals, name, None)
68             if not s:
69                 connected = False
70                 log.warn("trying to instrument missing signal %s", name)
71                 continue
72             # we should connect to the signal without using weak references
73             # otherwise they will be garbage collected and our handlers
74             # will be disconnected after the first call; for more details check:
75             # https://github.com/jek/blinker/blob/207446f2d97/blinker/base.py#L106-L108
76             s.connect(handler, sender=self.app, weak=False)
77             self._receivers.append(handler)
78         return connected
79 
80     def _before_request(self):
81         """ Starts tracing the current request and stores it in the global
82             request object.
83         """
84         self._start_span()
85 
86     def _after_request(self, response):
87         """ Runs after the server can process a response. """
88         try:
89             self._process_response(response)
90         except Exception:
91             self.app.logger.exception("error tracing response")
92         return response
93 
94     def _teardown_request(self, exception):
95         """ Runs at the end of a request. If there's an unhandled exception, it
96             will be passed in.
97         """
98         # when we teardown the span, ensure we have a clean slate.
99         span = getattr(g, 'flask_datadog_span', None)
100         setattr(g, 'flask_datadog_span', None)
101         if not span:
102             return
103 
104         try:
105             self._finish_span(span, exception=exception)
106         except Exception:
107             self.app.logger.exception("error finishing span")
108 
109     def _start_span(self):
110         if self._use_distributed_tracing:
111             propagator = HTTPPropagator()
112             context = propagator.extract(request.headers)
113             # Only need to active the new context if something was propagated
114             if context.trace_id:
115                 self._tracer.context_provider.activate(context)
116         try:
117             g.flask_datadog_span = self._tracer.trace(
118                 SPAN_NAME,
119                 service=self._service,
120                 span_type=http.TYPE,
121             )
122         except Exception:
123             self.app.logger.exception("error tracing request")
124 
125     def _process_response(self, response):
126         span = getattr(g, 'flask_datadog_span', None)
127         if not (span and span.sampled):
128             return
129 
130         code = response.status_code if response else ''
131         span.set_tag(http.STATUS_CODE, code)
132 
133     def _request_exception(self, *args, **kwargs):
134         exception = kwargs.get("exception", None)
135         span = getattr(g, 'flask_datadog_span', None)
136         if span and exception:
137             _set_error_on_span(span, exception)
138 
139     def _finish_span(self, span, exception=None):
140         if not span or not span.sampled:
141             return
142 
143         code = span.get_tag(http.STATUS_CODE) or 0
144         try:
145             code = int(code)
146         except Exception:
147             code = 0
148 
149         if exception:
150             # if the request has already had a code set, don't override it.
151             code = code or 500
152             _set_error_on_span(span, exception)
153 
154         # the endpoint that matched the request is None if an exception
155         # happened so we fallback to a common resource
156         span.error = 0 if code < 500 else 1
157 
158         # the request isn't guaranteed to exist here, so only use it carefully.
159         method = ''
160         endpoint = ''
161         url = ''
162         if request:
163             method = request.method
164             endpoint = request.endpoint or code
165             url = request.base_url or ''
166 
167         # Let users specify their own resource in middleware if they so desire.
168         # See case https://github.com/DataDog/dd-trace-py/issues/353
169         if span.resource == SPAN_NAME:
170             resource = endpoint or code
171             span.resource = compat.to_unicode(resource).lower()
172 
173         span.set_tag(http.URL, compat.to_unicode(url))
174         span.set_tag(http.STATUS_CODE, code)
175         span.set_tag(http.METHOD, method)
176         span.finish()
177 
178 def _set_error_on_span(span, exception):
179     # The 3 next lines might not be strictly required, since `set_traceback`
180     # also get the exception from the sys.exc_info (and fill the error meta).
181     # Since we aren't sure it always work/for insuring no BC break, keep
182     # these lines which get overridden anyway.
183     span.set_tag(errors.ERROR_TYPE, type(exception))
184     span.set_tag(errors.ERROR_MSG, exception)
185     # The provided `exception` object doesn't have a stack trace attached,
186     # so attach the stack trace with `set_traceback`.
187     span.set_traceback()
188 
189 def _patch_render(tracer):
190     """ patch flask's render template methods with the given tracer. """
191     # fall back to patching  global method
192     _render = flask.templating._render
193 
194     def _traced_render(template, context, app):
195         with tracer.trace('flask.template') as span:
196             span.span_type = http.TEMPLATE
197             span.set_tag("flask.template", template.name or "string")
198             return _render(template, context, app)
199 
200     flask.templating._render = _traced_render
201 
202 
203 def _signals_exist(names):
204     """ Return true if all of the given signals exist in this version of flask.
205     """
206     return all(getattr(signals, n, False) for n in names)
207 
208 
209 _blinker_not_installed_msg = (
210     "please install blinker to use flask signals. "
211     "http://flask.pocoo.org/docs/0.11/signals/"
212 )
213
```
--- 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/flask/middleware.py b/ddtrace/contrib/flask/middleware.py
--- a/ddtrace/contrib/flask/middleware.py
+++ b/ddtrace/contrib/flask/middleware.py
@@ -1,19 +1,9 @@
-"""
-Datadog tracing code for flask.
-
-Installing the blinker library will allow the tracing middleware to collect
-more exception info.
-"""
-
-# stdlib
 import logging
 
-# project
 from ... import compat
 from ...ext import http, errors, AppTypes
 from ...propagation.http import HTTPPropagator
 
-# 3p
 import flask.templating
 from flask import g, request, signals
 
@@ -28,7 +18,7 @@
 
     def __init__(self, app, tracer, service="flask", use_signals=True, distributed_tracing=False):
         self.app = app
-        self.app.logger.info("initializing trace middleware")
+        log.debug('flask: initializing trace middleware')
 
         self._tracer = tracer
         self._service = service
@@ -50,7 +40,7 @@
         # are caught and handled in custom user code.
         # See https://github.com/DataDog/dd-trace-py/issues/390
         if use_signals and not signals.signals_available:
-            self.app.logger.info(_blinker_not_installed_msg)
+            log.debug(_blinker_not_installed_msg)
         self.use_signals = use_signals and signals.signals_available
         timing_signals = {
             'got_request_exception': self._request_exception,
@@ -88,7 +78,7 @@
         try:
             self._process_response(response)
         except Exception:
-            self.app.logger.exception("error tracing response")
+            log.debug('flask: error tracing response', exc_info=True)
         return response
 
     def _teardown_request(self, exception):
@@ -104,7 +94,7 @@
         try:
             self._finish_span(span, exception=exception)
         except Exception:
-            self.app.logger.exception("error finishing span")
+            log.debug('flask: error finishing span', exc_info=True)
 
     def _start_span(self):
         if self._use_distributed_tracing:
@@ -120,7 +110,7 @@
                 span_type=http.TYPE,
             )
         except Exception:
-            self.app.logger.exception("error tracing request")
+            log.debug('flask: error tracing request', exc_info=True)
 
     def _process_response(self, response):
         span = getattr(g, 'flask_datadog_span', None)

{"golden_diff": "diff --git a/ddtrace/contrib/flask/middleware.py b/ddtrace/contrib/flask/middleware.py\n--- a/ddtrace/contrib/flask/middleware.py\n+++ b/ddtrace/contrib/flask/middleware.py\n@@ -1,19 +1,9 @@\n-\"\"\"\n-Datadog tracing code for flask.\n-\n-Installing the blinker library will allow the tracing middleware to collect\n-more exception info.\n-\"\"\"\n-\n-# stdlib\n import logging\n \n-# project\n from ... import compat\n from ...ext import http, errors, AppTypes\n from ...propagation.http import HTTPPropagator\n \n-# 3p\n import flask.templating\n from flask import g, request, signals\n \n@@ -28,7 +18,7 @@\n \n     def __init__(self, app, tracer, service=\"flask\", use_signals=True, distributed_tracing=False):\n         self.app = app\n-        self.app.logger.info(\"initializing trace middleware\")\n+        log.debug('flask: initializing trace middleware')\n \n         self._tracer = tracer\n         self._service = service\n@@ -50,7 +40,7 @@\n         # are caught and handled in custom user code.\n         # See https://github.com/DataDog/dd-trace-py/issues/390\n         if use_signals and not signals.signals_available:\n-            self.app.logger.info(_blinker_not_installed_msg)\n+            log.debug(_blinker_not_installed_msg)\n         self.use_signals = use_signals and signals.signals_available\n         timing_signals = {\n             'got_request_exception': self._request_exception,\n@@ -88,7 +78,7 @@\n         try:\n             self._process_response(response)\n         except Exception:\n-            self.app.logger.exception(\"error tracing response\")\n+            log.debug('flask: error tracing response', exc_info=True)\n         return response\n \n     def _teardown_request(self, exception):\n@@ -104,7 +94,7 @@\n         try:\n             self._finish_span(span, exception=exception)\n         except Exception:\n-            self.app.logger.exception(\"error finishing span\")\n+            log.debug('flask: error finishing span', exc_info=True)\n \n     def _start_span(self):\n         if self._use_distributed_tracing:\n@@ -120,7 +110,7 @@\n                 span_type=http.TYPE,\n             )\n         except Exception:\n-            self.app.logger.exception(\"error tracing request\")\n+            log.debug('flask: error tracing request', exc_info=True)\n \n     def _process_response(self, response):\n         span = getattr(g, 'flask_datadog_span', None)\n", "issue": "DDtrace Flask middleware logging as flask instead of ddtrace\nHere:\r\nhttps://github.com/DataDog/dd-trace-py/blob/master/ddtrace/contrib/flask/middleware.py#L31\r\n\r\nYou attach to flask's logger and log that line. Could you log it as ddtrace (using log.info) instead so that we can configure ddtrace's log handlers appropriately without having to create custom log filters?\n", "before_files": [{"content": "\"\"\"\nDatadog tracing code for flask.\n\nInstalling the blinker library will allow the tracing middleware to collect\nmore exception info.\n\"\"\"\n\n# stdlib\nimport logging\n\n# project\nfrom ... import compat\nfrom ...ext import http, errors, AppTypes\nfrom ...propagation.http import HTTPPropagator\n\n# 3p\nimport flask.templating\nfrom flask import g, request, signals\n\n\nlog = logging.getLogger(__name__)\n\n\nSPAN_NAME = 'flask.request'\n\n\nclass TraceMiddleware(object):\n\n    def __init__(self, app, tracer, service=\"flask\", use_signals=True, distributed_tracing=False):\n        self.app = app\n        self.app.logger.info(\"initializing trace middleware\")\n\n        self._tracer = tracer\n        self._service = service\n        self._use_distributed_tracing = distributed_tracing\n        self.use_signals = use_signals\n\n        self._tracer.set_service_info(\n            service=service,\n            app=\"flask\",\n            app_type=AppTypes.web,\n        )\n\n        # Install hooks which time requests.\n        self.app.before_request(self._before_request)\n        self.app.after_request(self._after_request)\n        self.app.teardown_request(self._teardown_request)\n\n        # Add exception handling signals. This will annotate exceptions that\n        # are caught and handled in custom user code.\n        # See https://github.com/DataDog/dd-trace-py/issues/390\n        if use_signals and not signals.signals_available:\n            self.app.logger.info(_blinker_not_installed_msg)\n        self.use_signals = use_signals and signals.signals_available\n        timing_signals = {\n            'got_request_exception': self._request_exception,\n        }\n        self._receivers = []\n        if self.use_signals and _signals_exist(timing_signals):\n            self._connect(timing_signals)\n\n        _patch_render(tracer)\n\n    def _connect(self, signal_to_handler):\n        connected = True\n        for name, handler in signal_to_handler.items():\n            s = getattr(signals, name, None)\n            if not s:\n                connected = False\n                log.warn(\"trying to instrument missing signal %s\", name)\n                continue\n            # we should connect to the signal without using weak references\n            # otherwise they will be garbage collected and our handlers\n            # will be disconnected after the first call; for more details check:\n            # https://github.com/jek/blinker/blob/207446f2d97/blinker/base.py#L106-L108\n            s.connect(handler, sender=self.app, weak=False)\n            self._receivers.append(handler)\n        return connected\n\n    def _before_request(self):\n        \"\"\" Starts tracing the current request and stores it in the global\n            request object.\n        \"\"\"\n        self._start_span()\n\n    def _after_request(self, response):\n        \"\"\" Runs after the server can process a response. \"\"\"\n        try:\n            self._process_response(response)\n        except Exception:\n            self.app.logger.exception(\"error tracing response\")\n        return response\n\n    def _teardown_request(self, exception):\n        \"\"\" Runs at the end of a request. If there's an unhandled exception, it\n            will be passed in.\n        \"\"\"\n        # when we teardown the span, ensure we have a clean slate.\n        span = getattr(g, 'flask_datadog_span', None)\n        setattr(g, 'flask_datadog_span', None)\n        if not span:\n            return\n\n        try:\n            self._finish_span(span, exception=exception)\n        except Exception:\n            self.app.logger.exception(\"error finishing span\")\n\n    def _start_span(self):\n        if self._use_distributed_tracing:\n            propagator = HTTPPropagator()\n            context = propagator.extract(request.headers)\n            # Only need to active the new context if something was propagated\n            if context.trace_id:\n                self._tracer.context_provider.activate(context)\n        try:\n            g.flask_datadog_span = self._tracer.trace(\n                SPAN_NAME,\n                service=self._service,\n                span_type=http.TYPE,\n            )\n        except Exception:\n            self.app.logger.exception(\"error tracing request\")\n\n    def _process_response(self, response):\n        span = getattr(g, 'flask_datadog_span', None)\n        if not (span and span.sampled):\n            return\n\n        code = response.status_code if response else ''\n        span.set_tag(http.STATUS_CODE, code)\n\n    def _request_exception(self, *args, **kwargs):\n        exception = kwargs.get(\"exception\", None)\n        span = getattr(g, 'flask_datadog_span', None)\n        if span and exception:\n            _set_error_on_span(span, exception)\n\n    def _finish_span(self, span, exception=None):\n        if not span or not span.sampled:\n            return\n\n        code = span.get_tag(http.STATUS_CODE) or 0\n        try:\n            code = int(code)\n        except Exception:\n            code = 0\n\n        if exception:\n            # if the request has already had a code set, don't override it.\n            code = code or 500\n            _set_error_on_span(span, exception)\n\n        # the endpoint that matched the request is None if an exception\n        # happened so we fallback to a common resource\n        span.error = 0 if code < 500 else 1\n\n        # the request isn't guaranteed to exist here, so only use it carefully.\n        method = ''\n        endpoint = ''\n        url = ''\n        if request:\n            method = request.method\n            endpoint = request.endpoint or code\n            url = request.base_url or ''\n\n        # Let users specify their own resource in middleware if they so desire.\n        # See case https://github.com/DataDog/dd-trace-py/issues/353\n        if span.resource == SPAN_NAME:\n            resource = endpoint or code\n            span.resource = compat.to_unicode(resource).lower()\n\n        span.set_tag(http.URL, compat.to_unicode(url))\n        span.set_tag(http.STATUS_CODE, code)\n        span.set_tag(http.METHOD, method)\n        span.finish()\n\ndef _set_error_on_span(span, exception):\n    # The 3 next lines might not be strictly required, since `set_traceback`\n    # also get the exception from the sys.exc_info (and fill the error meta).\n    # Since we aren't sure it always work/for insuring no BC break, keep\n    # these lines which get overridden anyway.\n    span.set_tag(errors.ERROR_TYPE, type(exception))\n    span.set_tag(errors.ERROR_MSG, exception)\n    # The provided `exception` object doesn't have a stack trace attached,\n    # so attach the stack trace with `set_traceback`.\n    span.set_traceback()\n\ndef _patch_render(tracer):\n    \"\"\" patch flask's render template methods with the given tracer. \"\"\"\n    # fall back to patching  global method\n    _render = flask.templating._render\n\n    def _traced_render(template, context, app):\n        with tracer.trace('flask.template') as span:\n            span.span_type = http.TEMPLATE\n            span.set_tag(\"flask.template\", template.name or \"string\")\n            return _render(template, context, app)\n\n    flask.templating._render = _traced_render\n\n\ndef _signals_exist(names):\n    \"\"\" Return true if all of the given signals exist in this version of flask.\n    \"\"\"\n    return all(getattr(signals, n, False) for n in names)\n\n\n_blinker_not_installed_msg = (\n    \"please install blinker to use flask signals. \"\n    \"http://flask.pocoo.org/docs/0.11/signals/\"\n)\n", "path": "ddtrace/contrib/flask/middleware.py"}], "after_files": [{"content": "import logging\n\nfrom ... import compat\nfrom ...ext import http, errors, AppTypes\nfrom ...propagation.http import HTTPPropagator\n\nimport flask.templating\nfrom flask import g, request, signals\n\n\nlog = logging.getLogger(__name__)\n\n\nSPAN_NAME = 'flask.request'\n\n\nclass TraceMiddleware(object):\n\n    def __init__(self, app, tracer, service=\"flask\", use_signals=True, distributed_tracing=False):\n        self.app = app\n        log.debug('flask: initializing trace middleware')\n\n        self._tracer = tracer\n        self._service = service\n        self._use_distributed_tracing = distributed_tracing\n        self.use_signals = use_signals\n\n        self._tracer.set_service_info(\n            service=service,\n            app=\"flask\",\n            app_type=AppTypes.web,\n        )\n\n        # Install hooks which time requests.\n        self.app.before_request(self._before_request)\n        self.app.after_request(self._after_request)\n        self.app.teardown_request(self._teardown_request)\n\n        # Add exception handling signals. This will annotate exceptions that\n        # are caught and handled in custom user code.\n        # See https://github.com/DataDog/dd-trace-py/issues/390\n        if use_signals and not signals.signals_available:\n            log.debug(_blinker_not_installed_msg)\n        self.use_signals = use_signals and signals.signals_available\n        timing_signals = {\n            'got_request_exception': self._request_exception,\n        }\n        self._receivers = []\n        if self.use_signals and _signals_exist(timing_signals):\n            self._connect(timing_signals)\n\n        _patch_render(tracer)\n\n    def _connect(self, signal_to_handler):\n        connected = True\n        for name, handler in signal_to_handler.items():\n            s = getattr(signals, name, None)\n            if not s:\n                connected = False\n                log.warn(\"trying to instrument missing signal %s\", name)\n                continue\n            # we should connect to the signal without using weak references\n            # otherwise they will be garbage collected and our handlers\n            # will be disconnected after the first call; for more details check:\n            # https://github.com/jek/blinker/blob/207446f2d97/blinker/base.py#L106-L108\n            s.connect(handler, sender=self.app, weak=False)\n            self._receivers.append(handler)\n        return connected\n\n    def _before_request(self):\n        \"\"\" Starts tracing the current request and stores it in the global\n            request object.\n        \"\"\"\n        self._start_span()\n\n    def _after_request(self, response):\n        \"\"\" Runs after the server can process a response. \"\"\"\n        try:\n            self._process_response(response)\n        except Exception:\n            log.debug('flask: error tracing response', exc_info=True)\n        return response\n\n    def _teardown_request(self, exception):\n        \"\"\" Runs at the end of a request. If there's an unhandled exception, it\n            will be passed in.\n        \"\"\"\n        # when we teardown the span, ensure we have a clean slate.\n        span = getattr(g, 'flask_datadog_span', None)\n        setattr(g, 'flask_datadog_span', None)\n        if not span:\n            return\n\n        try:\n            self._finish_span(span, exception=exception)\n        except Exception:\n            log.debug('flask: error finishing span', exc_info=True)\n\n    def _start_span(self):\n        if self._use_distributed_tracing:\n            propagator = HTTPPropagator()\n            context = propagator.extract(request.headers)\n            # Only need to active the new context if something was propagated\n            if context.trace_id:\n                self._tracer.context_provider.activate(context)\n        try:\n            g.flask_datadog_span = self._tracer.trace(\n                SPAN_NAME,\n                service=self._service,\n                span_type=http.TYPE,\n            )\n        except Exception:\n            log.debug('flask: error tracing request', exc_info=True)\n\n    def _process_response(self, response):\n        span = getattr(g, 'flask_datadog_span', None)\n        if not (span and span.sampled):\n            return\n\n        code = response.status_code if response else ''\n        span.set_tag(http.STATUS_CODE, code)\n\n    def _request_exception(self, *args, **kwargs):\n        exception = kwargs.get(\"exception\", None)\n        span = getattr(g, 'flask_datadog_span', None)\n        if span and exception:\n            _set_error_on_span(span, exception)\n\n    def _finish_span(self, span, exception=None):\n        if not span or not span.sampled:\n            return\n\n        code = span.get_tag(http.STATUS_CODE) or 0\n        try:\n            code = int(code)\n        except Exception:\n            code = 0\n\n        if exception:\n            # if the request has already had a code set, don't override it.\n            code = code or 500\n            _set_error_on_span(span, exception)\n\n        # the endpoint that matched the request is None if an exception\n        # happened so we fallback to a common resource\n        span.error = 0 if code < 500 else 1\n\n        # the request isn't guaranteed to exist here, so only use it carefully.\n        method = ''\n        endpoint = ''\n        url = ''\n        if request:\n            method = request.method\n            endpoint = request.endpoint or code\n            url = request.base_url or ''\n\n        # Let users specify their own resource in middleware if they so desire.\n        # See case https://github.com/DataDog/dd-trace-py/issues/353\n        if span.resource == SPAN_NAME:\n            resource = endpoint or code\n            span.resource = compat.to_unicode(resource).lower()\n\n        span.set_tag(http.URL, compat.to_unicode(url))\n        span.set_tag(http.STATUS_CODE, code)\n        span.set_tag(http.METHOD, method)\n        span.finish()\n\ndef _set_error_on_span(span, exception):\n    # The 3 next lines might not be strictly required, since `set_traceback`\n    # also get the exception from the sys.exc_info (and fill the error meta).\n    # Since we aren't sure it always work/for insuring no BC break, keep\n    # these lines which get overridden anyway.\n    span.set_tag(errors.ERROR_TYPE, type(exception))\n    span.set_tag(errors.ERROR_MSG, exception)\n    # The provided `exception` object doesn't have a stack trace attached,\n    # so attach the stack trace with `set_traceback`.\n    span.set_traceback()\n\ndef _patch_render(tracer):\n    \"\"\" patch flask's render template methods with the given tracer. \"\"\"\n    # fall back to patching  global method\n    _render = flask.templating._render\n\n    def _traced_render(template, context, app):\n        with tracer.trace('flask.template') as span:\n            span.span_type = http.TEMPLATE\n            span.set_tag(\"flask.template\", template.name or \"string\")\n            return _render(template, context, app)\n\n    flask.templating._render = _traced_render\n\n\ndef _signals_exist(names):\n    \"\"\" Return true if all of the given signals exist in this version of flask.\n    \"\"\"\n    return all(getattr(signals, n, False) for n in names)\n\n\n_blinker_not_installed_msg = (\n    \"please install blinker to use flask signals. \"\n    \"http://flask.pocoo.org/docs/0.11/signals/\"\n)\n", "path": "ddtrace/contrib/flask/middleware.py"}]}