Skip to content

Commit 10b04ee

Browse files
author
Emanuele Palazzetti
committed
[requests] update documentation using the configuration API
1 parent 9ecf99b commit 10b04ee

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

ddtrace/contrib/requests/__init__.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
"""
2-
To trace all HTTP calls from the requests library, patch the library like so::
2+
The ``requests`` integration traces all HTTP calls to internal or external services.
3+
Auto instrumentation is available using the ``patch`` function that **must be called
4+
before** importing the ``requests`` library. The following is an example::
35
4-
# Patch the requests library.
5-
from ddtrace.contrib.requests import patch
6-
patch()
6+
from ddtrace import patch
7+
patch(requests=True)
78
89
import requests
9-
requests.get("http://www.datadog.com")
10+
requests.get("https://www.datadoghq.com")
1011
11-
If you would prefer finer grained control without monkeypatching the requests'
12-
code, use a TracedSession object as you would a requests.Session::
12+
If you would prefer finer grained control, use a ``TracedSession`` object as you would a
13+
``requests.Session``::
1314
1415
from ddtrace.contrib.requests import TracedSession
1516
1617
session = TracedSession()
17-
session.get("http://www.datadog.com")
18+
session.get("https://www.datadoghq.com")
1819
19-
To enable distributed tracing, for example if you call, from requests, a web service
20-
which is also instrumented and want to have traces including both client and server sides::
20+
The library can be configured globally and per instance, using the Configuration API::
2121
22-
from ddtrace.contrib.requests import TracedSession
22+
from ddtrace import config
2323
24-
session = TracedSession()
25-
session.distributed_tracing = True
26-
session.get("http://host.lan/webservice")
24+
# enable distributed tracing globally
25+
config.requests['distributed_tracing'] = True
26+
27+
# change the service name only for this session
28+
session = Session()
29+
cfg = config.get_from(session)
30+
cfg['service_name'] = 'auth-api'
2731
"""
2832
from ...utils.importlib import require_modules
2933

0 commit comments

Comments
 (0)