@@ -196,20 +196,18 @@ class object, used to create cursors (keyword only)
196196 # PEP-249 requires autocommit to be initially off
197197 autocommit = kwargs2 .pop ("autocommit" , False )
198198
199+ self ._set_attributes (* args , ** kwargs2 )
199200 super ().__init__ (* args , ** kwargs2 )
201+
200202 self .cursorclass = cursorclass
201203 self .encoders = {
202204 k : v
203205 for k , v in conv .items ()
204206 if type (k ) is not int # noqa: E721
205207 }
206-
207- self .database = kwargs2 .get ("database" , "" )
208-
209208 self ._server_version = tuple (
210209 [numeric_part (n ) for n in self .get_server_info ().split ("." )[:2 ]]
211210 )
212-
213211 self .encoding = "ascii" # overridden in set_character_set()
214212
215213 if not charset :
@@ -240,6 +238,21 @@ class object, used to create cursors (keyword only)
240238 self .autocommit (autocommit )
241239 self .messages = []
242240
241+ def _set_attributes (self , host = None , user = None , password = None , database = "" , port = 3306 ,
242+ unix_socket = None , ** kwargs ):
243+ """set some attributes for otel"""
244+ if unix_socket and not host :
245+ host = "localhost"
246+ # support opentelemetry-instrumentation-dbapi
247+ self .host = host
248+ # _mysql.Connection provides self.port
249+ self .user = user
250+ self .database = database
251+ # otel-inst-mysqlclient uses db instead of database.
252+ self .db = database
253+ # NOTE: We have not supported semantic conventions yet.
254+ # https://opentelemetry.io/docs/specs/semconv/database/sql/
255+
243256 def __enter__ (self ):
244257 return self
245258
0 commit comments