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

Add configuration of log level and formatting for Auto Instrumentation #4203

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

Conversation

jeremydvoss
Copy link
Contributor

Description

DRAFT: Proposal for adding configuration of log level and formatting for Auto Instrumentation. Main subject to decide on is which env vars to use:
OTEL_LOG_LEVEL: Exists in the SDK but unused
OTEL_PYTHON_LOG_LEVEL: Currently only used by Python Logging Instrumentation
OTEL_PYTHON_LOG_FORMAT: Currently only used by Python Logging Instrumentation

Fixes #4034

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 Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

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

@jeremydvoss jeremydvoss changed the title Add configuration of log level and formatting for Auto Instrumentation DRAFT: Add configuration of log level and formatting for Auto Instrumentation Sep 26, 2024
@jeremydvoss jeremydvoss force-pushed the auto-format branch 2 times, most recently from a0b79f8 to e641e75 Compare October 2, 2024 21:50
@roger-collins-self
Copy link

roger-collins-self commented Feb 3, 2025

According to the specification, OTEL_LOG_LEVEL is to be used for the SDK loggers, not the instrumented OTLP loggers.

The logging config should only apply to the opentelemetry logger namespace and not the root logger.

@jeremydvoss jeremydvoss changed the title DRAFT: Add configuration of log level and formatting for Auto Instrumentation Add configuration of log level and formatting for Auto Instrumentation Mar 12, 2025
@jeremydvoss
Copy link
Contributor Author

jeremydvoss commented Mar 12, 2025

According to the specification, OTEL_LOG_LEVEL is to be used for the SDK loggers, not the instrumented OTLP loggers.

The logging config should only apply to the opentelemetry logger namespace and not the root logger.

I see your point. I'll bring up in the next sig. Since this is a broader matter, I have also made an issue to make sure we tackle this before logging stability.

@jeremydvoss
Copy link
Contributor Author

Added tests.

@jeremydvoss jeremydvoss marked this pull request as ready for review March 25, 2025 20:25
@jeremydvoss jeremydvoss requested a review from a team as a code owner March 25, 2025 20:25
@@ -665,9 +677,151 @@ def test_logging_init_exporter(self):
getLogger(__name__).error("hello")
self.assertTrue(provider.processor.exporter.export_called)

@patch.dict(environ, {}, clear=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing a test passing an invalid log level value and getting INFO set.

{"OTEL_RESOURCE_ATTRIBUTES": "service.name=otlp-service"},
{
"OTEL_RESOURCE_ATTRIBUTES": "service.name=otlp-service",
"OTEL_LOG_LEVEL": "CUSTOM_LOG_LEVEL",
Copy link
Member

Choose a reason for hiding this comment

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

Does this line have an effect since the next line is patching _get_log_level?

)
self.assertEqual(self.set_provider_mock.call_count, 1)
provider = self.set_provider_mock.call_args[0][0]
self.assertIsInstance(provider, DummyLoggerProvider)
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about these assertions? Do we want to keep just the ones that test the changes in this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Allow configuration of LoggingHandler in autoinstrumentation
5 participants