@@ -62,19 +62,19 @@ def trace_integration(
62
62
capture_parameters : bool = False ,
63
63
):
64
64
"""Integrate with DB API library.
65
- https://www.python.org/dev/peps/pep-0249/
66
-
67
- Args:
68
- connect_module: Module name where connect method is available.
69
- connect_method_name: The connect method name.
70
- database_component: Database driver name or database name "JDBI",
71
- "jdbc", "odbc", "postgreSQL".
72
- database_type: The Database type. For any SQL database, "sql".
73
- connection_attributes: Attribute names for database, port, host and
74
- user in Connection object.
75
- tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to
76
- use. If ommited the current configured one is used.
77
- capture_parameters: Configure if db.statement.parameters should be captured.
65
+ https://www.python.org/dev/peps/pep-0249/
66
+
67
+ Args:
68
+ connect_module: Module name where connect method is available.
69
+ connect_method_name: The connect method name.
70
+ database_component: Database driver name or database name "JDBI",
71
+ "jdbc", "odbc", "postgreSQL".
72
+ database_type: The Database type. For any SQL database, "sql".
73
+ connection_attributes: Attribute names for database, port, host and
74
+ user in Connection object.
75
+ tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to
76
+ use. If ommited the current configured one is used.
77
+ capture_parameters: Configure if db.statement.parameters should be captured.
78
78
"""
79
79
wrap_connect (
80
80
__name__ ,
@@ -101,18 +101,18 @@ def wrap_connect(
101
101
capture_parameters : bool = False ,
102
102
):
103
103
"""Integrate with DB API library.
104
- https://www.python.org/dev/peps/pep-0249/
105
-
106
- Args:
107
- tracer: The :class:`opentelemetry.trace.Tracer` to use.
108
- connect_module: Module name where connect method is available.
109
- connect_method_name: The connect method name.
110
- database_component: Database driver name or database name "JDBI",
111
- "jdbc", "odbc", "postgreSQL".
112
- database_type: The Database type. For any SQL database, "sql".
113
- connection_attributes: Attribute names for database, port, host and
114
- user in Connection object.
115
- capture_parameters: Configure if db.statement.parameters should be captured.
104
+ https://www.python.org/dev/peps/pep-0249/
105
+
106
+ Args:
107
+ tracer: The :class:`opentelemetry.trace.Tracer` to use.
108
+ connect_module: Module name where connect method is available.
109
+ connect_method_name: The connect method name.
110
+ database_component: Database driver name or database name "JDBI",
111
+ "jdbc", "odbc", "postgreSQL".
112
+ database_type: The Database type. For any SQL database, "sql".
113
+ connection_attributes: Attribute names for database, port, host and
114
+ user in Connection object.
115
+ capture_parameters: Configure if db.statement.parameters should be captured.
116
116
117
117
"""
118
118
@@ -143,14 +143,14 @@ def wrap_connect_(
143
143
144
144
145
145
def unwrap_connect (
146
- connect_module : typing .Callable [..., typing .Any ], connect_method_name : str ,
146
+ connect_module : typing .Callable [..., typing .Any ], connect_method_name : str
147
147
):
148
148
"""Disable integration with DB API library.
149
- https://www.python.org/dev/peps/pep-0249/
149
+ https://www.python.org/dev/peps/pep-0249/
150
150
151
- Args:
152
- connect_module: Module name where the connect method is available.
153
- connect_method_name: The connect method name.
151
+ Args:
152
+ connect_module: Module name where the connect method is available.
153
+ connect_method_name: The connect method name.
154
154
"""
155
155
unwrap (connect_module , connect_method_name )
156
156
@@ -251,8 +251,7 @@ def wrapped_connection(
251
251
args : typing .Tuple [typing .Any , typing .Any ],
252
252
kwargs : typing .Dict [typing .Any , typing .Any ],
253
253
):
254
- """Add object proxy to connection object.
255
- """
254
+ """Add object proxy to connection object."""
256
255
connection = connect_method (* args , ** kwargs )
257
256
self .get_connection_attributes (connection )
258
257
return get_traced_connection_proxy (connection , self )
@@ -278,6 +277,9 @@ def get_connection_attributes(self, connection):
278
277
self .database = self .database .decode (errors = "ignore" )
279
278
self .name += "." + self .database
280
279
user = self .connection_props .get ("user" )
280
+ # PyMySQL encodes this data
281
+ if user and isinstance (user , bytes ):
282
+ user = user .decode ()
281
283
if user is not None :
282
284
self .span_attributes ["db.user" ] = str (user )
283
285
host = self .connection_props .get ("host" )
@@ -325,8 +327,10 @@ def _populate_span(
325
327
span .set_attribute (
326
328
"component" , self ._db_api_integration .database_component
327
329
)
328
- span .set_attribute ("db.type" , self ._db_api_integration .database_type )
329
- span .set_attribute ("db.instance" , self ._db_api_integration .database )
330
+ span .set_attribute (
331
+ "db.system" , self ._db_api_integration .database_component
332
+ )
333
+ span .set_attribute ("db.name" , self ._db_api_integration .database )
330
334
span .set_attribute ("db.statement" , statement )
331
335
332
336
for (
@@ -344,9 +348,16 @@ def traced_execution(
344
348
* args : typing .Tuple [typing .Any , typing .Any ],
345
349
** kwargs : typing .Dict [typing .Any , typing .Any ]
346
350
):
351
+ name = ""
352
+ if args :
353
+ name = args [0 ]
354
+ elif self ._db_api_integration .database :
355
+ name = self ._db_api_integration .database
356
+ else :
357
+ name = self ._db_api_integration .name
347
358
348
359
with self ._db_api_integration .get_tracer ().start_as_current_span (
349
- self . _db_api_integration . name , kind = SpanKind .CLIENT
360
+ name , kind = SpanKind .CLIENT
350
361
) as span :
351
362
self ._populate_span (span , * args )
352
363
try :
0 commit comments