1- """Provides classes to instrument dbapi2 providers
2-
3- https://www.python.org/dev/peps/pep-0249/
4- """
51# BSD 3-Clause License
62#
73# Copyright (c) 2019, Elasticsearch BV
3228# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3329# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3430
31+ """Provides classes to instrument dbapi2 providers
32+
33+ https://www.python.org/dev/peps/pep-0249/
34+ """
35+
3536import re
3637
3738from elasticapm .instrumentation .packages .base import AbstractInstrumentedModule
@@ -197,6 +198,10 @@ def extract_signature(sql):
197198class CursorProxy (wrapt .ObjectProxy ):
198199 provider_name = None
199200
201+ def __init__ (self , wrapped , destination_info = None ):
202+ super (CursorProxy , self ).__init__ (wrapped )
203+ self ._self_destination_info = destination_info
204+
200205 def callproc (self , procname , params = None ):
201206 return self ._trace_sql (self .__wrapped__ .callproc , procname , params , action = EXEC_ACTION )
202207
@@ -224,7 +229,7 @@ def _trace_sql(self, method, sql, params, action=QUERY_ACTION):
224229 span_type = "db" ,
225230 span_subtype = self .provider_name ,
226231 span_action = action ,
227- extra = {"db" : {"type" : "sql" , "statement" : sql_string }},
232+ extra = {"db" : {"type" : "sql" , "statement" : sql_string }, "destination" : self . _self_destination_info },
228233 skip_frames = 1 ,
229234 ):
230235 if params is None :
@@ -239,8 +244,12 @@ def extract_signature(self, sql):
239244class ConnectionProxy (wrapt .ObjectProxy ):
240245 cursor_proxy = CursorProxy
241246
247+ def __init__ (self , wrapped , destination_info = None ):
248+ super (ConnectionProxy , self ).__init__ (wrapped )
249+ self ._self_destination_info = destination_info
250+
242251 def cursor (self , * args , ** kwargs ):
243- return self .cursor_proxy (self .__wrapped__ .cursor (* args , ** kwargs ))
252+ return self .cursor_proxy (self .__wrapped__ .cursor (* args , ** kwargs ), self . _self_destination_info )
244253
245254
246255class DbApi2Instrumentation (AbstractInstrumentedModule ):
0 commit comments