Django server not responding with Azure Application Insights connector
See original GitHub issueDescribe your environment.
Running on WSL2 Ubuntu 20.04.
Django = "^4.0.5"
opencensus-ext-azure = "^1.1.4"
Steps to reproduce.
- Create a new Django project and app
django-admin startproject '<project_name>'
django-admin startapp 'myapp'
- Create an Application Insights resource on Azure and add the logging configuration to
settings.py
:
CONNECTION_STRING = 'InstrumentationKey=xxxx-xxx-xx-xx....'
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"azure": {
"level": "DEBUG",
"class": "opencensus.ext.azure.log_exporter.AzureLogHandler",
"connection_string": CONNECTION_STRING
},
"console": {
"class": "logging.StreamHandler",
},
},
"loggers": {
"django": {
"handlers": ["console", "azure"],
},
},
}
What is the expected behavior?
Server should respond to requests on 8000 and logs should be sent to Insights.
What is the actual behavior?
Server will not respond when started: python manage.py runserver
. Logs are not sent.
June 20, 2022 - 13:39:47
Django version 4.0.5, using settings 'insights.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
# After the server is up
$ telnet 127.0.0.1 8000
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
Workaround 'disable_existing_loggers': True
doesn’t work. The HTTP server responds, but Insights is not updated with metrics.
Additional context.
This issue was talk about in #904 but it was not resolved. I’m opening this issue to find what the cause really is.
Issue Analytics
- State:
- Created a year ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Django example not working · Issue #94623 - GitHub
When I remove only the "azure" handler, the HTTP port starts responding again, but then logs are not sent to insights. "loggers": {...
Read more >Django + Azure Application Insights - Stack Overflow
i'm trying to embed Azure's Application Insights in a dockerized Django/AngularJS environment to cover the data flow from end to end.
Read more >Diagnose exceptions in web apps with Application Insights
Open the app solution in Visual Studio. Run the app, either on your server or on your development machine by using F5 ....
Read more >Track incoming requests with OpenCensus Python
Monitor request calls for your Python apps via OpenCensus Python. ... The data is then sent to Application Insights under Azure Monitor as ......
Read more >Troubleshoot Bad Gateway errors - Azure Application Gateway
Solution · Check UDR associated with the application gateway subnet. Ensure that the UDR isn't directing traffic away from the backend subnet.
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 Free
Top 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
@dsv-mckinsey
You need to create a custom logger. Here is what worked for me:
@epomatti It is recommended usage to not use the root logger because the azure exporters themselves log messages when an exception occurs. All of the examples that send log data use custom loggers. This is already in the official docs