OpenTelemetry Logging with Django #4294
willianantunes
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Django uses the dictionary
LOGGING
to configure the logging system (check its documentation). Talking about programmatically configuration, OpenTelemetry Logging Instrumentation can be configured in themanage.py
file andgunicorn_config.py
file if you are using Gunicorn. If you setLoggingInstrumentor().instrument(tracer_provider=provider, set_logging_format=True)
in both files, it won't work properly, because Django will calllogging.config.dictConfig(LOGGING)
later, and it will overwrite the configuration set by OpenTelemetry. To solve this issue, you can create a class like the following:Then you can set the
LOGGING
dictionary like this:Notice the custom handler named
otlp
. Remember, according to the documentation, the APIs withinopentelemetry.sdk._logs
are subject to change. So, it is important to keep an eye on the updates. Libraries I used at the time I posted this comment:Sample project.
Beta Was this translation helpful? Give feedback.
All reactions