|
4 | 4 | """ |
5 | 5 |
|
6 | 6 | import os |
| 7 | +import imp |
| 8 | +import sys |
7 | 9 | import logging |
8 | 10 |
|
9 | 11 | from ddtrace.utils.formats import asbool |
@@ -46,6 +48,8 @@ def update_patched_modules(): |
46 | 48 | patch = True |
47 | 49 |
|
48 | 50 | # Respect DATADOG_* environment variables in global tracer configuration |
| 51 | + # TODO: these variables are deprecated; use utils method and update our documentation |
| 52 | + # correct prefix should be DD_* |
49 | 53 | enabled = os.environ.get("DATADOG_TRACE_ENABLED") |
50 | 54 | hostname = os.environ.get("DATADOG_TRACE_AGENT_HOSTNAME") |
51 | 55 | port = os.environ.get("DATADOG_TRACE_AGENT_PORT") |
@@ -76,5 +80,24 @@ def update_patched_modules(): |
76 | 80 |
|
77 | 81 | if 'DATADOG_ENV' in os.environ: |
78 | 82 | tracer.set_tags({"env": os.environ["DATADOG_ENV"]}) |
| 83 | + |
| 84 | + # Ensure sitecustomize.py is properly called if available in application directories: |
| 85 | + # * exclude `bootstrap_dir` from the search |
| 86 | + # * find a user `sitecustomize.py` module |
| 87 | + # * import that module via `imp` |
| 88 | + bootstrap_dir = os.path.dirname(__file__) |
| 89 | + path = list(sys.path) |
| 90 | + path.remove(bootstrap_dir) |
| 91 | + |
| 92 | + try: |
| 93 | + (f, path, description) = imp.find_module('sitecustomize', path) |
| 94 | + except ImportError: |
| 95 | + pass |
| 96 | + else: |
| 97 | + # `sitecustomize.py` found, load it |
| 98 | + log.debug('sitecustomize from user found in: %s', path) |
| 99 | + imp.load_module('sitecustomize', f, path, description) |
| 100 | + |
| 101 | + |
79 | 102 | except Exception as e: |
80 | 103 | log.warn("error configuring Datadog tracing", exc_info=True) |
0 commit comments