Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda