Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved logging instrumentor #2718

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

Olegt0rr
Copy link
Contributor

@Olegt0rr Olegt0rr commented Jul 17, 2024

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:
telegram-cloud-photo-size-2-5228942634012229246-x

Now it's used early log record return for every case, when you can't get trace or span:
Screenshot 2024-07-23 at 19 22 43

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 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:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@Olegt0rr Olegt0rr marked this pull request as ready for review July 22, 2024 22:04
@Olegt0rr Olegt0rr requested a review from a team July 22, 2024 22:04
@Olegt0rr
Copy link
Contributor Author

@lzchen
Copy link
Contributor

lzchen commented Jul 23, 2024

@Olegt0rr

Would you be able to add a more informative description to the change that this pr pertains? A sample showing it in action and the expected output would be great as well.

@Olegt0rr
Copy link
Contributor Author

@Olegt0rr

Would you be able to add a more informative description to the change that this pr pertains? A sample showing it in action and the expected output would be great as well.

Updated PR description

@ocelotl ocelotl removed their assignment Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants