|
1 | 1 | """ |
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:: |
3 | 5 |
|
4 | | - # Patch the requests library. |
5 | | - from ddtrace.contrib.requests import patch |
6 | | - patch() |
| 6 | + from ddtrace import patch |
| 7 | + patch(requests=True) |
7 | 8 |
|
8 | 9 | import requests |
9 | | - requests.get("http://www.datadog.com") |
| 10 | + requests.get("https://www.datadoghq.com") |
10 | 11 |
|
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``:: |
13 | 14 |
|
14 | 15 | from ddtrace.contrib.requests import TracedSession |
15 | 16 |
|
16 | 17 | session = TracedSession() |
17 | | - session.get("http://www.datadog.com") |
| 18 | + session.get("https://www.datadoghq.com") |
18 | 19 |
|
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:: |
21 | 21 |
|
22 | | - from ddtrace.contrib.requests import TracedSession |
| 22 | + from ddtrace import config |
23 | 23 |
|
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' |
27 | 31 | """ |
28 | 32 | from ...utils.importlib import require_modules |
29 | 33 |
|
|
0 commit comments