dd-trace-py
dd-trace-py copied to clipboard
feat(ddtrace): add container auto injection
Add the pieces required to do auto injection of the ddtrace Python package in containerized environments.
This solution works just like ddtrace-run:
-
provide a
sizecustomizemodule which Python will look for and execute in the paths specified by thePYTHONPATHenvironment variable. -
the
sitecustomizemodule executes apip install ddtracewhich will install the package and thenimport ddtrace.bootstrap.sitecustomizeto do the same logic thatddtrace-rundoes. -
update the sys.path and PYTHONPATH for any subsequent executions of Python processes.
All this requires on the container side is to:
- mount the
sitecustomize.pymodule as a volume somewhere in the container - add the volume mount to the
PYTHONPATHenvironment variable
Risks
-
If pip fails to find an appropriate wheel (containing native binaries) for the system then the package will be installed from source which requires many more dependencies to be available on the system.
-
This solution introduces a call to pip install ddtrace on each call to python* on the system. This adds overhead to the command. In my testing this was 5-10 seconds for the package install and <1 second on subsequent calls after the package has been installed initially.
-
This solution requires an internet connection to reach pypi.org. Customers systems may not permit outbound network requests.
-
PYTHONPATH may be overridden in the container in a user's startup script which will override the value we set and cause the application to not be instrumented.