Skip to content

Conversation

@dhofstetter
Copy link
Contributor

@dhofstetter dhofstetter commented Mar 30, 2024

…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)

Type of change

Please delete options that are not relevant.

  • 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:
  • 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
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 30, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@rjduffner
Copy link
Contributor

Nice @dhofstetter. Thanks for taking this on.

Looks like my pr #1939 is fully implemented here. I can close #1939 when this is done.

@dhofstetter dhofstetter force-pushed the fix/logging-instrumentation branch 2 times, most recently from 5ebe8c8 to 02f5edb Compare April 25, 2024 16:27
@dhofstetter dhofstetter requested a review from a team April 25, 2024 16:27
@dhofstetter dhofstetter force-pushed the fix/logging-instrumentation branch 5 times, most recently from 3e45d57 to c7264c1 Compare April 28, 2024 15:20
@dhofstetter dhofstetter force-pushed the fix/logging-instrumentation branch 2 times, most recently from 40d5db1 to fb3ceab Compare April 30, 2024 06:27
@dhofstetter dhofstetter requested a review from xrmx April 30, 2024 06:28
@dhofstetter
Copy link
Contributor Author

Changed according to suggestions and rebased to main

…operly configured independently of the order of instrumentation (this helps especially in case of autoinstrumentation) - add method to perform proper logging initialisation - add unittests - extend CHANGELOG
@dhofstetter dhofstetter force-pushed the fix/logging-instrumentation branch from 0854421 to 51ccb36 Compare June 11, 2024 21:29
@dhofstetter
Copy link
Contributor Author

Rebased again to main.

@ocelotl Would you have your final look onto this pr?

self.assertFalse(hasattr(record, "otelTraceSampled"))


class TestLogSetup(TestBase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to capture and verify actual logging output behavior?

if root_logger.hasHandlers():
root_logger.setLevel(level)
for handler in root_logger.handlers:
handler.setFormatter(logging.Formatter(format))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be only reconfiguring the format for the OpenTelemetry LoggingHandler and not all of the user's handlers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

7 participants