opentelemetry-python-contrib
opentelemetry-python-contrib copied to clipboard
fix(opentelemetry-instrumentation-logging): Ensure that logging is pr…
…operly configured independently of the order of instrumentation (this helps especially in case of autoinstrumentation)
- add method to perform proper logging initialisation
- add unittests
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. I have changed the logging instrumentation in a way that ensures proper log setup no matter if the application (log) was already configured. The changes are in a way s.t. we check before applying log level and format to check if basicConfig should be used. Otherwise we are going to modify the log level and handlers "manually".
I also changed the uninstrument method (which is mainly for the test_uninstrumented test. Because as soon as we changed the log format and we "uninstrument" the application, then the logs cannot be formatted anymore.
The changes are highly inspired by this open pull request. So props, to figure out a neat way to resolve this issue go to @rjduffner.
Fixes # (issue)
- Fixes #2346
- Fixes opentelemetry-python#3473 (opentelemetry-pthon)
Type of change
Please delete options that are not relevant.
- [x] Bug fix (non-breaking change which fixes an issue)
How Has This Been Tested?
I have written unit tests to prove that everything should work as expected.
To verify this with some application, you can locally install the repo and perform auto-instrumentation of an application. There it can be verified that the issues mentioned above are gone.
Does This PR Require a Core Repo Change?
- [ ] Yes. - Link to PR:
- [x] No.
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.
- [x] Followed the style guidelines of this project
- [x] Changelogs have been updated
- [x] Unit tests have been added
- [ ] Documentation has been updated
The committers listed above are authorized under a signed CLA.
- :white_check_mark: login: dhofstetter (c30fa400694deb0a12221a494fbdabf58cdeba48, 51ccb36a3677eab49c36ca8dfacac1f248deba4f)
Nice @dhofstetter. Thanks for taking this on.
Looks like my pr #1939 is fully implemented here. I can close #1939 when this is done.
Changed according to suggestions and rebased to main
Rebased again to main.
@ocelotl Would you have your final look onto this pr?