python aio库日志和异步方法日志未显示在函数应用程序洞察中

python aio库日志和异步方法日志未显示在函数应用程序洞察中,python,python-3.x,azure,azure-functions,python-asyncio,Python,Python 3.x,Azure,Azure Functions,Python Asyncio,我正在使用python aio管理客户端库创建azure资源,例如azure.mgmt.eventhub.aio.EventHubManagementClient 观察: 而对应的azure同步库(例如azure.mgmt.eventhub.EventHubManagementClient)在调用管理服务API时打印http日志,但异步库不会打印类似的日志 另外,当我使用异步方法并在异步方法中使用python logger时,即使这些日志也不会打印 示例代码 logger = log

我正在使用python aio管理客户端库创建azure资源,例如
azure.mgmt.eventhub.aio.EventHubManagementClient

观察

  • 而对应的azure同步库(例如
    azure.mgmt.eventhub.EventHubManagementClient
    )在调用管理服务API时打印http日志,但异步库不会打印类似的日志
  • 另外,当我使用异步方法并在异步方法中使用python logger时,即使这些日志也不会打印
示例代码

    logger = logging.getLogger(__name__)
    logger.setLevel(logging.INFO)
    logging.basicConfig(level=logging.INFO)

    async def _create_or_update_eventhub_namespace_authorization_rule(self, authorization_rule_name,
                                                                  rights: AccessRights):
    await self._event_management_client.namespaces.create_or_update_authorization_rule(
        resource_group_name=EnvironmentVariables.RESOURCE_GROUP_NAME,
        namespace_name=self._env_var_obj.event_hub_name_space_name,
        authorization_rule_name=authorization_rule_name,
        parameters={
            "rights": [rights]
        }
    )

    logger.info('Provisioned EH-Namespace Rule:' + authorization_rule_name)

在这里,创建或更新授权规则()和我自己的日志都没有显示在Azure function insights中。

当我将Azure函数主函数本身定义为异步函数时,这个问题得到了解决,Azure python workers handle管理事件循环并异步调用这个主方法

async def main(req: func.HttpRequest) -> func.HttpResponse:
有了这些,所有aio客户端日志和我自己的日志都可以登录到app insights中

注意: 前面我将上述方法定义为非异步,然后通过显式创建事件循环并使用
asgiref.async\u to_sync
库从main()调用异步方法