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

[FEATURE]: Enhance consistency between debug mode and root logger hierarchy #12090

Open
shlomiuziel opened this issue Jan 25, 2025 · 0 comments

Comments

@shlomiuziel
Copy link

shlomiuziel commented Jan 25, 2025

Package Name

No response

Package Version(s)

No response

Describe the goal of the feature

Since ddtrace uses the Python logging module, the logger inherits its log level from the root logger. As stated in the documentation, when the application's root logger is set to DEBUG, it requires manual adjustment of the ddtrace logger to disable debug mode.

This can cause confusion, particularly because DD_DEBUG_MODE is explicitly expected to control debug behavior. For example, the current implementation handles DD_DEBUG_MODE setting, but it does not account for cases where getEffectiveLevel() independently resolves to logging.DEBUG due to the root logger hierarchy.

To achieve a more consistent and predictable behavior, the following options are suggested:

  • Logging debug mode has been enabled for the ddtrace logger not only if DD_DEBUG_MODE is set, but also when ddtrace's getEffectiveLevel() evaluates to logging.DEBUG.

  • Issuing a warning log if getEffectiveLevel() evaluates to logging.DEBUG in contradiction to DD_DEBUG_MODE.

  • Explicitly setting the logger to a higher level if DD_DEBUG_MODE is not enabled, but getEffectiveLevel() evaluates to logging.DEBUG

Is your feature request related to a problem?

The current behavior can lead to unexpected results that negatively impact performance:

When DEBUG mode is inadvertently enabled in third-party libraries, it can significantly degrade performance, particularly in production environments. Debug logs, by design, are verbose and can create I/O congestion, especially on web servers.

For ddtrace, this issue can be more problematic due to the frequent invocation of on_span_finish and on_span_start. These methods hold the SpanAggregator’s lock, and since on_span_finish triggers debug logging which holds the logging I/O lock, enabling debug mode introduces a risk of severe contention. High debug log pressure in this scenario (which isn't rate limited) introduces latency to the system, potentially grinding it to a halt. This behavior may resemble a deadlock when looking at the stack trace: threads (or Greenlets) yield on logging I/O operations while holding both the SpanAggregator lock and the logging I/O lock during log writes, and it prevents any creation or finalization of other spans in the meantime.

Describe alternatives you've considered

No response

Additional context

No response

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

No branches or pull requests

1 participant