Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.53k stars 2.76k forks source link

Invalid type WSGIRequest for attribute 'request' value on django sample code #36671

Closed Fox-Coderr closed 1 month ago

Fox-Coderr commented 1 month ago

Describe the bug When running the sample django code and calling the basic exception api, in the azure monitor i get the message "Invalid type WSGIRequest for attribute 'request' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types" instead of the request and exception information

To Reproduce Steps to reproduce the behavior:

  1. clone the project
  2. go to the sample code
  3. add the connection_string to manage.py and remove the configure_azure_monitor from asgi and wsgi
  4. run and call the api http://127.0.0.1:8000/exception
  5. check azure monitor

Expected behavior should display the request information and the except information on the azure monitor.

Any and all requests/exceptions send that message.

github-actions[bot] commented 1 month ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.

github-actions[bot] commented 1 month ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jeremydvoss @lzchen.

Fox-Coderr commented 1 month ago

ok, i was half wrong, i'm getting the requests and exceptions information, but that trace message is still happening every time those 2 are logged.

lzchen commented 1 month ago

@Fox-Coderr

The error is most likely being generated from the OpenTelemetry Django instrumentation itself, not the Azure monitor distro. I was able to reproduce this with a simple django app with only printing to the console. Feel free to open up an issue regarding the log error message itself in the community when using django instrumentation with LoggingHandler on the root logger.

Now to omit the log on the Azure monitor distro side, you can specify a logger_name parameter in the configure_azure_monitor() call to only collect logs from a parent logger that is namespaced. This way, the root logger won't be used by default and you won't collect error messages from the Django instrumentation.

...
configure_azure_monitor(
   logger_name="name_of_your_parent_logger",
)
...