From 4e0b86eed2c32ff36969bf759c5f2bae3a4315d4 Mon Sep 17 00:00:00 2001 From: Munir Abdinur Date: Thu, 17 Jul 2025 15:29:32 -0400 Subject: [PATCH] fix(docs): update log injection support (#14031) With ddtrace v3.10.0 `log injection` is enabled by default for structured loggers. This PR updates documentation and adds a more release note. - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) - [ ] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) --------- Co-authored-by: Brett Langdon (cherry picked from commit 549416977ca14e412be9a322a0198ebe261e3325) --- ddtrace/contrib/_logging.py | 22 +++++++++---------- docs/configuration.rst | 13 ++++++++--- ...n-enabled-by-default-395259b0419c7a5f.yaml | 5 +++++ 3 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 releasenotes/notes/feat-log-injection-enabled-by-default-395259b0419c7a5f.yaml diff --git a/ddtrace/contrib/_logging.py b/ddtrace/contrib/_logging.py index f2997f362f7..b57174b7c1f 100644 --- a/ddtrace/contrib/_logging.py +++ b/ddtrace/contrib/_logging.py @@ -5,7 +5,7 @@ attributes to the log record. 2. Updating the log formatter used by the application. In order to inject -tracing information into a log the formatter must be updated to include the +tracing information using the log the formatter must be updated to include the tracing attributes from the log record. @@ -15,22 +15,20 @@ Patch ``logging`` ~~~~~~~~~~~~~~~~~ -There are a few ways to tell ddtrace to patch the ``logging`` module: - -1. If using :ref:`ddtrace-run`, you can set the environment variable ``DD_LOGS_INJECTION=true``. - -2. Use :func:`patch()` to manually enable the integration:: - - from ddtrace import patch - patch(logging=True) - -3. (beta) Set ``log_injection_enabled`` at runtime via the Datadog UI. +Datadog support for built-in logging is enabled by default when you either: run your application +with the ddtrace-run command, or Import ddtrace.auto in your code. If you are using the ddtrace +library directly, you can enable logging support by calling: ``ddtrace.patch(logging=True)``. +Note: Directly enabling integrations via ddtrace.patch(...) is not recommended. Update Log Format ~~~~~~~~~~~~~~~~~ -Make sure that your log format exactly matches the following:: +Make sure that your log format supports the following attributes: ``dd.trace_id``, ``dd.span_id``, +``dd.service``, ``dd.env``, ``dd.version``. These values will be automatically added to +the log record by the ``ddtrace`` library. + +Example:: import logging from ddtrace.trace import tracer diff --git a/docs/configuration.rst b/docs/configuration.rst index 79a8a66a0dd..a4ffc14719f 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -749,9 +749,16 @@ Logs .. ddtrace-configuration-options:: DD_LOGS_INJECTION: - type: string - default: structured - description: Enables :ref:`Logs Injection`. Supported values are ``false``, ``true``, and ``structured``. + type: Boolean + default: True + description: Enables :ref:`Logs Injection`. Supported values are ``false``, and ``true``. + version_added: + v0.51.0: | + Added support for correlating traces to log using the builtin logger. This feature was disabled by default. + v3.10.0: | + The default value was changed to ``true``. This means that the tracer will inject trace context into logs when ``ddtrace-run`` or ``import ddtrace.auto`` is used. + To disable this behavior, set ``DD_LOGS_INJECTION=false``. + DD_TRACE_DEBUG: type: Boolean diff --git a/releasenotes/notes/feat-log-injection-enabled-by-default-395259b0419c7a5f.yaml b/releasenotes/notes/feat-log-injection-enabled-by-default-395259b0419c7a5f.yaml new file mode 100644 index 00000000000..536c1dfd2ac --- /dev/null +++ b/releasenotes/notes/feat-log-injection-enabled-by-default-395259b0419c7a5f.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + logging: Automatic injection of trace attributes into logs is now enabled for the standard logging library when using + either ``ddtrace-run`` or ``import ddtrace.auto``. To disable this feature, set the environment variable ``DD_LOGS_INJECTION`` to `False`. \ No newline at end of file