Skip to content

fix(docs): update log injection support [backport 3.10] #14052

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions ddtrace/contrib/_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand All @@ -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<ddtracerun>`, you can set the environment variable ``DD_LOGS_INJECTION=true``.

2. Use :func:`patch()<ddtrace.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
Expand Down
13 changes: 10 additions & 3 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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`.
Loading