dd-trace-py icon indicating copy to clipboard operation
dd-trace-py copied to clipboard

feat(ddtrace): add container auto injection

Open Kyle-Verhoog opened this issue 3 years ago • 0 comments

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 sizecustomize module which Python will look for and execute in the paths specified by the PYTHONPATH environment variable.

  • the sitecustomize module executes a pip install ddtrace which will install the package and then import ddtrace.bootstrap.sitecustomize to do the same logic that ddtrace-run does.

  • 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.py module as a volume somewhere in the container
  • add the volume mount to the PYTHONPATH environment variable

Risks

  1. 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.

  2. 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.

  3. This solution requires an internet connection to reach pypi.org. Customers systems may not permit outbound network requests.

  4. 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.

Kyle-Verhoog avatar Aug 09 '22 21:08 Kyle-Verhoog