def _xray_traced_connect(wrapped, instance, args, kwargs): conn = wrapped(*args, **kwargs) parameterized_dsn = { c[0]: c[-1] for c in map(methodcaller('split', '='), conn.dsn.split(' ')) } meta = { 'database_type': 'PostgreSQL', 'url': 'postgresql://{}@{}:{}/{}'.format( parameterized_dsn.get('user', 'unknown'), parameterized_dsn.get('host', 'unknown'), parameterized_dsn.get('port', 'unknown'), parameterized_dsn.get('dbname', 'unknown'), ), 'user': parameterized_dsn.get('user', 'unknown'), 'database_version': str(conn.server_version), 'driver_version': 'Psycopg 2' } return XRayTracedConn(conn, meta)
def _xray_traced_connect(wrapped, instance, args, kwargs): conn = wrapped(*args, **kwargs) meta = { 'database_type': 'MySQL', 'user': conn.user.decode('utf-8'), 'driver_version': 'PyMySQL' } if hasattr(conn, 'server_version'): version = sanitize_db_ver(getattr(conn, 'server_version')) if version: meta['database_version'] = version return XRayTracedConn(conn, meta)
def _xray_traced_connect(wrapped, instance, args, kwargs): conn = wrapped(*args, **kwargs) meta = {} for attr, key in MYSQL_ATTR.items(): if hasattr(conn, attr): meta[key] = getattr(conn, attr) if hasattr(conn, '_server_version'): version = sanitize_db_ver(getattr(conn, '_server_version')) if version: meta['database_version'] = version return XRayTracedConn(conn, meta)
def _xray_traced_connect(wrapped, instance, args, kwargs): conn = wrapped(*args, **kwargs) meta = {} dsn = conn.get_dsn_parameters() for attr, key in PG_ATTR.items(): value = dsn.get(attr) if value: meta[key] = value if hasattr(conn, '_server_version'): version = sanitize_db_ver(getattr(conn, '_server_version')) if version: meta['database_version'] = version return XRayTracedConn(conn, meta)
def _xray_traced_connect(wrapped, instance, args, kwargs): conn = wrapped(*args, **kwargs) host = kwargs['host'] if 'host' in kwargs else re.search( r'host=(\S+)\b', args[0]).groups()[0] dbname = kwargs['dbname'] if 'dbname' in kwargs else re.search( r'dbname=(\S+)\b', args[0]).groups()[0] port = kwargs['port'] if 'port' in kwargs else re.search( r'port=(\S+)\b', args[0]).groups()[0] user = kwargs['user'] if 'user' in kwargs else re.search( r'user=(\S+)\b', args[0]).groups()[0] meta = { 'database_type': 'PostgreSQL', 'url': 'postgresql://{}@{}:{}/{}'.format(user, host, port, dbname), 'user': user, 'database_version': str(conn.server_version), 'driver_version': 'Psycopg 2' } return XRayTracedConn(conn, meta)