From 3de81197c69f8fa8144983cd8d4116729cb7ac16 Mon Sep 17 00:00:00 2001 From: Ben Donnelly Date: Wed, 1 Nov 2023 17:51:32 +0000 Subject: [PATCH] feat(app root): add app root to allow for better app frame detection --- docs/config/config.md | 20 +++++++++++--------- src/deep/__init__.py | 8 ++++++++ src/deep/processor/frame_collector.py | 3 +++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/docs/config/config.md b/docs/config/config.md index 2a74f66..090a153 100644 --- a/docs/config/config.md +++ b/docs/config/config.md @@ -4,14 +4,16 @@ A list of the possible config values for the deep python agent. They can be set Note: When setting as environment variable prefix the key with 'DEEP_'. e.g. DEEP_SERVICE_URL -| Key | Default | Description | -|-----------------------|------------|--------------------------------------------------------------------------------------------------------------------------------------| -| SERVICE_URL | deep:43315 | The url (hostname:port) of the deep service to connect to. | -| SERVICE_SECURE | True | Can be set to False if the service doesn't support secure connections. | -| LOGGING_CONF | None | Can be used to override the python logging config used by the agent. | -| POLL_TIMER | 10 | The time (in seconds) of the interval between polls. | -| SERVICE_AUTH_PROVIDER | None | The auth provider to use, each provider can have their own config, see available [auth providers](../auth/providers.md) for details. | -| IN_APP_INCLUDE | None | A string of comma (,) seperated values that indicate a package is part of the app. | -| IN_APP_EXCLUDE | None | A string of comma (,) seperated values that indicate a package is not part of the app. | +| Key | Default | Description | +|-----------------------|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------| +| SERVICE_URL | deep:43315 | The url (hostname:port) of the deep service to connect to. | +| SERVICE_SECURE | True | Can be set to False if the service doesn't support secure connections. | +| LOGGING_CONF | None | Can be used to override the python logging config used by the agent. | +| POLL_TIMER | 10 | The time (in seconds) of the interval between polls. | +| SERVICE_AUTH_PROVIDER | None | The auth provider to use, each provider can have their own config, see available [auth providers](../auth/providers.md) for details. | +| IN_APP_INCLUDE | None | A string of comma (,) seperated values that indicate a package is part of the app. | +| IN_APP_EXCLUDE | None | A string of comma (,) seperated values that indicate a package is not part of the app. | +| APP_ROOT | Calculated | This is the root folder in which the application is running. If not set it is calculated as the directory in which the file that calls `Deep.start` is in. | + diff --git a/src/deep/__init__.py b/src/deep/__init__.py index 385387a..06203e6 100644 --- a/src/deep/__init__.py +++ b/src/deep/__init__.py @@ -9,6 +9,8 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. +import inspect +import os from deep import logging, version from deep.api import Deep @@ -23,6 +25,12 @@ def start(config=None): if config is None: config = {} + # we use the app root to shorten file paths for display + if 'APP_ROOT' not in config: + # if app root is not set then we use the folder in which the code that called us is in as the app root + config['APP_ROOT'] = os.getenv("DEEP_APP_ROOT", None) or os.path.dirname( + os.path.dirname(inspect.stack()[1].filename)) + from deep.config.config_service import ConfigService cfg = ConfigService(config) logging.init(cfg) diff --git a/src/deep/processor/frame_collector.py b/src/deep/processor/frame_collector.py index 906ea2e..2337a51 100644 --- a/src/deep/processor/frame_collector.py +++ b/src/deep/processor/frame_collector.py @@ -114,6 +114,9 @@ def is_app_frame(self, filename: str) -> Tuple[bool, str | None]: if filename.startswith(path): return True, path + if filename.startswith(self._config.APP_ROOT): + return True, self._config.APP_ROOT + return True, None def process_frame_variables_breadth_first(self, f_locals):