Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
Adding the opencensus AzureLogHandler to the root logger in FastAPI applications

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!

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!