Skip to content

CORE-916: dynamically enable debug logs on python agent#209

Merged
natyharary merged 6 commits into
mainfrom
core-916-dynamically-enable-debug-logs-on-python-agent
Jul 1, 2026
Merged

CORE-916: dynamically enable debug logs on python agent#209
natyharary merged 6 commits into
mainfrom
core-916-dynamically-enable-debug-logs-on-python-agent

Conversation

@natyharary

Copy link
Copy Markdown
Collaborator

What this PR does / why we need it:

adds support for agent diagnostics for python (like we just added in node)

Changelog entry: Does this PR introduce a user-facing bug fix, feature, dependency update, or breaking change??

Add configurable log level for logs

@natyharary natyharary self-assigned this Jun 24, 2026
@natyharary
natyharary force-pushed the core-916-dynamically-enable-debug-logs-on-python-agent branch from 9c0a652 to 60ed280 Compare June 24, 2026 13:02
@natyharary
natyharary requested a review from tamirdavid1 June 25, 2026 08:09
Comment thread initializer/diagnose.py
logger = logging.getLogger(logger_name)
if level is None:
# No level configured for this logger, so silence it.
logger.disabled = True

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

check if the default is INFO or disabled

@natyharary natyharary Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The default ODIGOS_LOG_LEVEL or OTEL_LOG_LEVEL is non existent, so it is None. So in this case this fits that None -> disable log.
Makes sense to me since we don't want to print any logs to the customer's app if we do not explicitely state so

@natyharary
natyharary force-pushed the core-916-dynamically-enable-debug-logs-on-python-agent branch 2 times, most recently from 3f13629 to 040c379 Compare June 29, 2026 06:18

@natyharary natyharary left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

.

Comment thread initializer/diagnose.py
logger = logging.getLogger(logger_name)
if level is None:
# No level configured for this logger, so silence it.
logger.disabled = True

@natyharary natyharary Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The default ODIGOS_LOG_LEVEL or OTEL_LOG_LEVEL is non existent, so it is None. So in this case this fits that None -> disable log.
Makes sense to me since we don't want to print any logs to the customer's app if we do not explicitely state so

@natyharary
natyharary requested a review from tamirdavid1 June 29, 2026 08:38
Comment thread initializer/diagnose.py Outdated
but the trace-id format may be lost for those apps.
"""
# WARNING is the root logger's constructed default; LoggingInstrumentor changed it to INFO.
logging.getLogger().setLevel(logging.WARNING)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Clarifying comment:
This reverts the logging level back to warning, which is the logging library default

Comment thread initializer/diagnose.py Outdated
Comment on lines +78 to +86
original_basic_config = logging.basicConfig

def basic_config_relay(*args, **kwargs):
level = kwargs.get("level")
if level is not None:
logging.getLogger().setLevel(level)
# Keep the trace-id format the instrumentor installed; ignore the app's format override.
kwargs.pop("format", None)
return original_basic_config(*args, **kwargs)

@natyharary natyharary Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Clarifying comment:
Some frameworks use basicConfig vs. setLevel for definng logging behavor.
We get the original basic config that was set by whatever framework (django, fastapi, etc) and re-apply it to get the log level it has set, but ignore the "format" part so we still get our trace id correlaton e.g.:

2026-06-29 08:50:33,385 INFO [root] [main.py:56] [trace_id=bea3462329d56c9768843d5746b12d0a span_id=88f8cb66fa405afe resource.service.name=inventory trace_sampled=True] - Buying product with id 40

(the "trace_id = ..." part)

@natyharary
natyharary force-pushed the core-916-dynamically-enable-debug-logs-on-python-agent branch 3 times, most recently from 34c090c to 25c1ec6 Compare June 30, 2026 13:07
Comment thread initializer/diagnose.py Outdated
_set_logger_level(OPENTELEMETRY_LOGGER_NAME, _CONFIG_LEVEL_MAP.get(agent_diagnostics.get("openTelemetryComponentsLogLevel")))


def relay_application_log_level() -> None:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

review w tamir: we might not need this now

@natyharary
natyharary force-pushed the core-916-dynamically-enable-debug-logs-on-python-agent branch from 25c1ec6 to ce9985f Compare July 1, 2026 10:33
@natyharary
natyharary force-pushed the core-916-dynamically-enable-debug-logs-on-python-agent branch from ce9985f to c00dc48 Compare July 1, 2026 10:49
@natyharary
natyharary merged commit 2110333 into main Jul 1, 2026
17 of 18 checks passed
@natyharary
natyharary deleted the core-916-dynamically-enable-debug-logs-on-python-agent branch July 1, 2026 10:53
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.

2 participants