[QUESTION] Logging to Application Insights
See original GitHub issueDescription
I’m trying to send logs for my app to Azure Application Insights. I’ve tried following steps from this article: https://github.com/microsoft/ApplicationInsights-Python
Namely the section called “Basic logging configuration (second option)”. I’ve setup the logger, added my instrumentation key, but I don’t see anything going to Application Insights, or to the logs of my container. This could be unrelated to FastAPI, but I’m not sure. Here’s a snippet of my code
from fastapi import FastAPI
import logging
from applicationinsights.logging import enable, LoggingHandler
from features import FeaturesRequest
from XGB_New_Cust_80_Feature import predict_output_new_customer
from XGB_Rep_Cust_80_Feature import predict_output_repeat_customer
app = FastAPI(openapi_prefix="/risk-model")
instrumentation_key = '<my instrumentation key>'
try:
with open("/keyvault/ApplicationInsights__InstrumentationKey", "r")as f:
instrumentation_key = f.read()
except IOError:
pass
enable(instrumentation_key)
handler = LoggingHandler(instrumentation_key)
logging.basicConfig(handlers=[ handler ], format='%(levelname)s: %(message)s', level=logging.DEBUG)
logger = logging.getLogger("main")
@app.post("/risk-predictions/new-customers")
async def new_customer_risk_prediction(features: FeaturesRequest):
logger.info(features)
prediction = predict_output_new_customer(features)
return {
"prediction": prediction[0][0],
"model": prediction[1]
}
@app.post("/risk-predictions/existing-customers")
async def existing_customer_risk_prediction(features: FeaturesRequest):
logger.info(features)
prediction = predict_output_repeat_customer(features)
return {
"prediction": prediction[0][0],
"model": prediction[1]
}
Additional context Add any other context or screenshots about the feature request here.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Application Insights logging with .NET - Azure Monitor
Application Insights captures and sends ILogger logs by using the same TelemetryConfiguration information that's used for every other telemetry.
Read more >How can I view logs in Application Insights? - Stack Overflow
Application Insights -> Transaction search Here you can filter data by TRACE type and it is your application logs.
Read more >Sitecore Identity server logs to Application Insights
I want to write the logs into the Application Insights for the Sitecore Identity server. What I have done till: I checked the...
Read more >Structured Logging In Microsoft's Azure Application Insights
This becomes especially critical with automatic logging frameworks/SDKs like Application Insights. Azure Application Insights logs all the ...
Read more >Using Application Insights For Better Application Logging
App Insights can give you a clear look into your browser errors, making it easy to group error logs by various keys like...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone who might drop by. I’ve created fastapi middleware that can be added for opencencus tracer
It is heavily inspired by the flask middleware.
You can add the middleware by
This thread might get interesting in the future
Thanks for the help here @victoraugustolls! 🍰🚀
And thanks @bwoods89 for reporting back and closing the issue. 🎉