opentelemetry-python-contrib
opentelemetry-python-contrib copied to clipboard
Improved logging instrumentor
Description
Logging fields customization
Having connected this tool, I was surprised that the names of the logging fields were hard-coded. The naming convention for such fields in my company is different, so I couldn't use this module as it is. I decided that I could easily inherit and replace the fields with my own, but when I opened the code, I was surprised that all the action of the instrumentator is in one function and it will not be possible to change the behavior with a little modification.
As a result, I decided to add the ability to specify my field names to the instrumentator, while not changing the standard behavior (for those who already use this instrumentator as is).
As I added in the documentation, it is now possible to specify any convenient names for the fields:
LoggingInstrumentor(
trace_id_field="trace_id",
span_id_field="span_id",
trace_sampled_field="trace_sampled",
service_name_field="service_name",
)
Performance
LogRecordFactory without log_hook
Now, for cases when a log_hook is not passed to the instrumentator, a factory is passed to logging, which does not check the possibility of using log_hook every log record.
Single service_name call
Now we don't calculate service_name on log record, get it once - on instrumentation.
Typehints
Added type hints for every function signature and class variable
Code readability
Code style before change was like this:
Now it's used early log record return for every case, when you can't get trace or span:
Type of change
Please delete options that are not relevant.
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [x] This change requires a documentation update
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
- [ ] Test A
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
- [ ] Unit tests have been added
- [x] Documentation has been updated