77
88
99def patch ():
10-
1110 wrapt .wrap_function_wrapper (
1211 'psycopg2' ,
1312 'connect' ,
@@ -23,6 +22,10 @@ def patch():
2322 'quote_ident' ,
2423 _xray_register_type_fix
2524 )
25+
26+ # We should in general not patch internal methods (pyscopg2._json.register_type in this case).
27+ # But there isn't a better workaround than this for the time being.
28+ # Please see the GH issue for details: https://github.com/aws/aws-xray-sdk-python/issues/243
2629 wrapt .wrap_function_wrapper (
2730 'psycopg2._json' ,
2831 'register_type' ,
@@ -31,9 +34,8 @@ def patch():
3134
3235
3336def _xray_traced_connect (wrapped , instance , args , kwargs ):
34-
3537 conn = wrapped (* args , ** kwargs )
36- parameterized_dsn = { c [0 ]: c [- 1 ] for c in map (methodcaller ('split' , '=' ), conn .dsn .split (' ' ))}
38+ parameterized_dsn = {c [0 ]: c [- 1 ] for c in map (methodcaller ('split' , '=' ), conn .dsn .split (' ' ))}
3739 meta = {
3840 'database_type' : 'PostgreSQL' ,
3941 'url' : 'postgresql://{}@{}:{}/{}' .format (
@@ -49,6 +51,7 @@ def _xray_traced_connect(wrapped, instance, args, kwargs):
4951
5052 return XRayTracedConn (conn , meta )
5153
54+
5255def _xray_register_type_fix (wrapped , instance , args , kwargs ):
5356 """Send the actual connection or curser to register type."""
5457 our_args = list (copy .copy (args ))
0 commit comments