Open kgilpin opened 4 months ago
Enable AppMap to record individual Python files specified in appmap.yml
The current implementation of appmap-python
does not record Python code that isn't part of a module. This behavior limits the ability to record simple projects or individual files specified by their path in appmap.yml
.
AppMap is designed to record function executions, HTTP requests, and database transactions in supported languages through dynamic instrumentation. For appmap-python
, the tool auto-detects and instruments Python modules defined in the appmap.yml
configuration file. However, it currently ignores individual Python files not part of a module, which can be restrictive in some scenarios.
To resolve this, we need to modify the configuration and file loading mechanisms to detect and instrument individual Python files if their path
is specified in appmap.yml
. This involves:
appmap.yml
configuration to recognize and validate individual file paths._appmap/configuration.py
find_top_packages
method to include scanning for individual .py
files._resolve_relative_to
method to resolve paths for individual Python files.vendor/_appmap/wrapt/importer.py
_set_loader
and _load_module
methods to include logic for individual file instrumentation._appmap/recorder.py
Recorder
methods to handle events from both modules and individual files.Integration with existing configurations
appmap.yml
to recognize and correctly handle individual Python file paths.appmap.yml
configurations that list only modules._appmap/configuration.py
:
find_top_packages
to scan for individual .py
files and include them in the packages list._resolve_relative_to
to resolve paths for .py
files and validate their existence.default_packages
and packages
properties._appmap/recorder.py
:
Recorder
class to handle file paths in its recording registry._start_recording
and _stop_recording
methods correctly initiate and end recording for individual Python files.Other files (init
, env
, generation
, etc.):
This update will enable appmap-python
to record individual Python files if their paths are specified in appmap.yml
. The changes involve modifications in configuration parsing, instrumentation setup, and recorder handling to support the recording of both modules and individual files.
By implementing these changes, users will gain the enhanced ability to record and analyze simpler Python projects or specific Python scripts, improving the flexibility and usability of AppMap.
appmap-python
currently refuses to record Python code that isn't in a module. This is a barrier to getting the desired data in some cases, especially for simple projects.If the
path
setting in appmap.yml matches the name of a Python file, that file should be instrumented.