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
91import logging
102
11- # project
123from ... import compat
134from ...ext import http , errors , AppTypes
145from ...propagation .http import HTTPPropagator
156
16- # 3p
177import flask .templating
188from flask import g , request , signals
199
@@ -28,7 +18,7 @@ class TraceMiddleware(object):
2818
2919 def __init__ (self , app , tracer , service = "flask" , use_signals = True , distributed_tracing = False ):
3020 self .app = app
31- self . app . logger . info ( " initializing trace middleware" )
21+ log . debug ( 'flask: initializing trace middleware' )
3222
3323 self ._tracer = tracer
3424 self ._service = service
@@ -50,7 +40,7 @@ def __init__(self, app, tracer, service="flask", use_signals=True, distributed_t
5040 # are caught and handled in custom user code.
5141 # See https://github.com/DataDog/dd-trace-py/issues/390
5242 if use_signals and not signals .signals_available :
53- self . app . logger . info (_blinker_not_installed_msg )
43+ log . debug (_blinker_not_installed_msg )
5444 self .use_signals = use_signals and signals .signals_available
5545 timing_signals = {
5646 'got_request_exception' : self ._request_exception ,
@@ -88,7 +78,7 @@ def _after_request(self, response):
8878 try :
8979 self ._process_response (response )
9080 except Exception :
91- self . app . logger . exception ( " error tracing response" )
81+ log . debug ( 'flask: error tracing response' , exc_info = True )
9282 return response
9383
9484 def _teardown_request (self , exception ):
@@ -104,7 +94,7 @@ def _teardown_request(self, exception):
10494 try :
10595 self ._finish_span (span , exception = exception )
10696 except Exception :
107- self . app . logger . exception ( " error finishing span" )
97+ log . debug ( 'flask: error finishing span' , exc_info = True )
10898
10999 def _start_span (self ):
110100 if self ._use_distributed_tracing :
@@ -120,7 +110,7 @@ def _start_span(self):
120110 span_type = http .TYPE ,
121111 )
122112 except Exception :
123- self . app . logger . exception ( " error tracing request" )
113+ log . debug ( 'flask: error tracing request' , exc_info = True )
124114
125115 def _process_response (self , response ):
126116 span = getattr (g , 'flask_datadog_span' , None )
0 commit comments