Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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

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

Conversation

jeremydvoss
Copy link
Contributor

@jeremydvoss jeremydvoss commented Sep 26, 2024

Description

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. Speced out to be the level for the SDK's internal logger, not the LoggingHandler.
OTEL_PYTHON_LOG_LEVEL: Currently only used by Python Logging Instrumentation
OTEL_PYTHON_LOG_FORMAT: Currently only used by Python Logging Instrumentation
OTEL_PYTHON_LOG_HANDLER_LEVEL: Possible new env var that is clearer and does not map to the same --log_level flag as OTEL_LOG_LEVEL

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
@jeremydvoss jeremydvoss force-pushed the auto-format branch 2 times, most recently from d510c06 to d996147 Compare May 12, 2025 21:56
@jeremydvoss
Copy link
Contributor Author

@roger-collins-self I switched to using OTEL_PYTHON_LOG_LEVEL instead of OTEL_LOG_LEVEL. This must by why the logging instrumentation does the same.

@jeremydvoss jeremydvoss added the Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary label May 12, 2025
@jeremydvoss
Copy link
Contributor Author

Looks like there's some issue with Python 3.8. Will investigate.

@jeremydvoss
Copy link
Contributor Author

I don't understand this error. How might it be related to this change?

https://github.com/open-telemetry/opentelemetry-python/actions/runs/15004918710/job/42163726837#step:5:408

/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/argparse.py:1548: ArgumentError
____________________________ TestArgs.test_exporter ____________________________

self = <test_run.TestArgs testMethod=test_exporter>
_ = <MagicMock name='execl' id='139772420527680'>

    @patch("opentelemetry.instrumentation.auto_instrumentation.execl")
    def test_exporter(self, _):  # pylint: disable=no-self-use
        with patch("sys.argv", ["instrument", "2"]):
>           auto_instrumentation.run()

opentelemetry-instrumentation/tests/auto_instrumentation/test_run.py:108: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py:65: in run
    parser.add_argument(
/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/argparse.py:1386: in add_argument
    return self._add_action(action)
/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/argparse.py:1749: in _add_action
    self._optionals._add_action(action)
/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/argparse.py:1590: in _add_action
    action = super(_ArgumentGroup, self)._add_action(action)
/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/argparse.py:1400: in _add_action
    self._check_conflict(action)
/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/argparse.py:1539: in _check_conflict
    conflict_handler(action, confl_optionals)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <argparse._ArgumentGroup object at 0x7f1f4d7c3fd0>
action = _StoreAction(option_strings=['--log_level'], dest='log_level', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None)
conflicting_actions = [('--log_level', _StoreAction(option_strings=['--log_level'], dest='log_level', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None))]

    def _handle_conflict_error(self, action, conflicting_actions):
        message = ngettext('conflicting option string: %s',
                           'conflicting option strings: %s',
                           len(conflicting_actions))
        conflict_string = ', '.join([option_string
                                     for option_string, action
                                     in conflicting_actions])
>       raise ArgumentError(action, message % conflict_string)
E       argparse.ArgumentError: argument --log_level: conflicting option string: --log_level

@mzealey
Copy link

mzealey commented May 30, 2025

https://markandruth.co.uk/2025/05/30/getting-opentelemetry-logging-working-in-python might be useful for some gotchas and workarounds while this PR is not yet merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Allow configuration of LoggingHandler in autoinstrumentation
6 participants