Skip to content

Commit 39f42f7

Browse files
authored
logging: update documentation (#1318)
1 parent 392e0fd commit 39f42f7

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

ddtrace/commands/ddtrace_run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
DATADOG_TRACE_AGENT_HOSTNAME=localhost: override the address of the trace agent host that the default tracer will attempt to submit to (default: localhost)
3131
DATADOG_TRACE_AGENT_PORT=8126: override the port that the default tracer will submit to (default: 8126)
3232
DD_SERVICE: the service name to be used for this program (default only for select web frameworks)
33-
DATADOG_PRIORITY_SAMPLING=true|false: (default: false): enables Priority Sampling.
33+
DATADOG_PRIORITY_SAMPLING=true|false: enables Priority Sampling. (default: false)
34+
DD_LOGS_INJECTION=true|false: enable injecting trace information into log records to correlate. (default: false)
3435
""" # noqa: E501
3536

3637

ddtrace/contrib/logging/__init__.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
"""
2-
Datadog APM traces can be integrated with Logs by first having the tracing
3-
library patch the standard library ``logging`` module and updating the log
4-
formatter used by an application. This feature enables you to inject the current
5-
trace information into a log entry.
2+
Datadog APM traces can be integrated with Logs by:
3+
4+
1. Having ``ddtrace`` patch the ``logging`` module. This will add trace
5+
attributes to the log record.
6+
7+
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
9+
tracing attributes from the log record. ``ddtrace-run`` will do this
10+
automatically for you by specifying a format. For more detail or instructions
11+
for how to do this manually see the manual section below.
12+
13+
With these in place the trace information will be injected into a log entry
14+
which can be used to correlate the log and trace in Datadog.
615
7-
Before the trace information can be injected into logs, the formatter has to be
8-
updated to include ``dd.trace_id`` and ``dd.span_id`` attributes from the log
9-
record. The integration with Logs occurs as long as the log entry includes
10-
``dd.trace_id=%(dd.trace_id)s`` and ``dd.span_id=%(dd.span_id)s``.
1116
1217
ddtrace-run
1318
-----------
@@ -33,14 +38,18 @@ def hello():
3338
----------------------
3439
3540
If you prefer to instrument manually, patch the logging library then update the
36-
log formatter as in the following example::
41+
log formatter as in the following example
42+
43+
Note that ``dd.trace_id`` and ``dd.span_id`` must come last::
3744
3845
from ddtrace import patch_all; patch_all(logging=True)
3946
import logging
4047
from ddtrace import tracer
4148
4249
FORMAT = ('%(asctime)s %(levelname)s [%(name)s] [%(filename)s:%(lineno)d] '
43-
'[dd.trace_id=%(dd.trace_id)s dd.span_id=%(dd.span_id)s] '
50+
'[dd.service=%(dd.service)s dd.env=%(dd.env)s '
51+
'dd.version=%(dd.version)s] '
52+
'dd.trace_id=%(dd.trace_id)s dd.span_id=%(dd.span_id)s]'
4453
'- %(message)s')
4554
logging.basicConfig(format=FORMAT)
4655
log = logging.getLogger()

0 commit comments

Comments
 (0)