Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda