I am having significant difficulty with emitting logs to the Azure Application Insights. When the AzureLogHandler is initialised and added to a child logger within app.py, it works fine. However, the issue begins outside of app.py when I go to create a new logger instance, the logs are not emitted to Azure. Sample:
# app.py
logger = logging.getLogger(__name__)
logger.addHandler(AzureLogHandler(connection_string=""))
logger.info("This is emitted")
# main.py
logger = logging.getLogger(__name__)
logger.addHandler(AzureLogHandler(connection_string=""))
logger.info("This is NOT emitted")
The only way I have managed to get it to work is by importing the logger instance I created in app.py which is suboptimal:
# sub-optimal - does not permit me to create a log hierarchy
# main.py
from app.py import logger
logger.info("This works but restricts me")
Ideally, I would like to implement opencensus AzureLogHandler with as little interference with the project as possible, for example adding the AzureLogHandler to the root logger at the start and then deriving all child loggers without need to attach the handler seperately:
# app.py
logging.basicConfig(handlers=[AzurelogHandler(connection_string=""))
logger = logging.getLogger(__name__)
logger.debug("so simple!")
# main.py
logger = logging.getLogger(__name__)
logger.debug("so simple!")
Note: The solution must work with Asyncronous FastAPI. This seems to complicate things as I have implemented this for Flask and other services just fine.
Thanks!