Skip to content

Commit 4404085

Browse files
mabdinurbrettlangdon
authored andcommitted
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. ## Checklist - [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 Checklist - [ ] 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 <[email protected]> (cherry picked from commit 5494169)
1 parent 1f8c272 commit 4404085

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

ddtrace/contrib/_logging.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
attributes to the log record.
66
77
2. Updating the log formatter used by the application. In order to inject
8-
tracing information into a log the formatter must be updated to include the
8+
tracing information using the log the formatter must be updated to include the
99
tracing attributes from the log record.
1010
1111
@@ -15,22 +15,20 @@
1515
Patch ``logging``
1616
~~~~~~~~~~~~~~~~~
1717
18-
There are a few ways to tell ddtrace to patch the ``logging`` module:
19-
20-
1. If using :ref:`ddtrace-run<ddtracerun>`, you can set the environment variable ``DD_LOGS_INJECTION=true``.
21-
22-
2. Use :func:`patch()<ddtrace.patch>` to manually enable the integration::
23-
24-
from ddtrace import patch
25-
patch(logging=True)
26-
27-
3. (beta) Set ``log_injection_enabled`` at runtime via the Datadog UI.
18+
Datadog support for built-in logging is enabled by default when you either: run your application
19+
with the ddtrace-run command, or Import ddtrace.auto in your code. If you are using the ddtrace
20+
library directly, you can enable logging support by calling: ``ddtrace.patch(logging=True)``.
21+
Note: Directly enabling integrations via ddtrace.patch(...) is not recommended.
2822
2923
3024
Update Log Format
3125
~~~~~~~~~~~~~~~~~
3226
33-
Make sure that your log format exactly matches the following::
27+
Make sure that your log format supports the following attributes: ``dd.trace_id``, ``dd.span_id``,
28+
``dd.service``, ``dd.env``, ``dd.version``. These values will be automatically added to
29+
the log record by the ``ddtrace`` library.
30+
31+
Example::
3432
3533
import logging
3634
from ddtrace.trace import tracer

docs/configuration.rst

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,16 @@ Logs
749749
.. ddtrace-configuration-options::
750750

751751
DD_LOGS_INJECTION:
752-
type: string
753-
default: structured
754-
description: Enables :ref:`Logs Injection`. Supported values are ``false``, ``true``, and ``structured``.
752+
type: Boolean
753+
default: True
754+
description: Enables :ref:`Logs Injection`. Supported values are ``false``, and ``true``.
755+
version_added:
756+
v0.51.0: |
757+
Added support for correlating traces to log using the builtin logger. This feature was disabled by default.
758+
v3.10.0: |
759+
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.
760+
To disable this behavior, set ``DD_LOGS_INJECTION=false``.
761+
755762

756763
DD_TRACE_DEBUG:
757764
type: Boolean
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
logging: Automatic injection of trace attributes into logs is now enabled for the standard logging library when using
5+
either ``ddtrace-run`` or ``import ddtrace.auto``. To disable this feature, set the environment variable ``DD_LOGS_INJECTION`` to `False`.

0 commit comments

Comments
 (0)