Repository: scoutapp/scout_apm_python

Issue:
Rename, document, and provide defaults for extra core agent configuration variables
It's possible to set these config vars to change the way the core agent is launched:

* `log_level`
* `log_file`
* `socket_path`
* `config_file`

These should be prefixed with `core_agent` , like `core_agent_log_level`, and be documented. Would also be useful for the [logging guide](https://docs.scoutapm.com/#python-logging) to point to setting `core_agent_log_file` to capture the logs - by default they go to stdout, which is nowhere, and it makes debugging harder.


Discussion:

Resolving patch:
diff --git a/src/scout_apm/core/config.py b/src/scout_apm/core/config.py
--- a/src/scout_apm/core/config.py
+++ b/src/scout_apm/core/config.py
@@ -55,11 +55,14 @@ def known_keys(self):
         return [
             "app_server",
             "application_root",
+            "core_agent_config_file",
             "core_agent_dir",
             "core_agent_download",
             "core_agent_launch",
+            "core_agent_log_file",
             "core_agent_log_level",
             "core_agent_permissions",
+            "core_agent_socket_path",
             "core_agent_version",
             "disabled_instruments",
             "download_url",
@@ -75,7 +78,6 @@ def known_keys(self):
             "scm_subdirectory",
             "shutdown_message_enabled",
             "shutdown_timeout_seconds",
-            "socket_path",
         ]
 
     def core_agent_permissions(self):
@@ -177,7 +179,7 @@ def lookup_func(self, key):
         func_name = "derive_" + key
         return getattr(self, func_name, None)
 
-    def derive_socket_path(self):
+    def derive_core_agent_socket_path(self):
         return "{}/{}/scout-agent.sock".format(
             self.config.value("core_agent_dir"),
             self.config.value("core_agent_full_name"),
diff --git a/src/scout_apm/core/core_agent_manager.py b/src/scout_apm/core/core_agent_manager.py
--- a/src/scout_apm/core/core_agent_manager.py
+++ b/src/scout_apm/core/core_agent_manager.py
@@ -82,7 +82,10 @@ def daemonize_flag(self):
         return ["--daemonize", "true"]
 
     def socket_path(self):
+        # Old deprecated name "socket_path"
         socket_path = scout_config.value("socket_path")
+        if socket_path is None:
+            socket_path = scout_config.value("core_agent_socket_path")
         return ["--socket", socket_path]
 
     def log_level(self):
@@ -93,14 +96,22 @@ def log_level(self):
         return ["--log-level", log_level]
 
     def log_file(self):
+        # Old deprecated name "log_file"
         path = scout_config.value("log_file")
+        if path is None:
+            path = scout_config.value("core_agent_log_file")
+
         if path is not None:
             return ["--log-file", path]
         else:
             return []
 
     def config_file(self):
+        # Old deprecated name "config_file"
         path = scout_config.value("config_file")
+        if path is None:
+            path = scout_config.value("core_agent_config_file")
+
         if path is not None:
             return ["--config-file", path]
         else:
diff --git a/src/scout_apm/core/socket.py b/src/scout_apm/core/socket.py
--- a/src/scout_apm/core/socket.py
+++ b/src/scout_apm/core/socket.py
@@ -65,7 +65,11 @@ def wait_until_drained(cls, timeout_seconds=2.0, callback=None):
         return queue_empty
 
     def run(self):
-        self.socket_path = scout_config.value("socket_path")
+        # Old deprecated name "socket_path"
+        socket_path = scout_config.value("socket_path")
+        if socket_path is None:
+            socket_path = scout_config.value("core_agent_socket_path")
+        self.socket_path = socket_path
         self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
 
         try:


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -120,7 +120,7 @@ def core_agent_manager(core_agent_dir):
     #   Error opening listener on socket: Custom { kind: InvalidInput,
     #   error: StringError("path must be shorter than SUN_LEN") }
     socket_path = "{}/test.sock".format(core_agent_dir)
-    scout_config.set(core_agent_dir=core_agent_dir, socket_path=socket_path)
+    scout_config.set(core_agent_dir=core_agent_dir, core_agent_socket_path=socket_path)
     core_agent_manager = CoreAgentManager()
     try:
         yield core_agent_manager
diff --git a/tests/integration/core/test_core_agent_manager.py b/tests/integration/core/test_core_agent_manager.py
--- a/tests/integration/core/test_core_agent_manager.py
+++ b/tests/integration/core/test_core_agent_manager.py
@@ -100,6 +100,22 @@ def test_launch_error(caplog, core_agent_manager):
     assert caplog.records[0].exc_info[1] is exception
 
 
+def test_socket_path(core_agent_manager):
+    scout_config.set(core_agent_socket_path="foo")
+
+    result = core_agent_manager.socket_path()
+
+    assert result == ["--socket", "foo"]
+
+
+def test_socket_path_old_name_takes_precedence(core_agent_manager):
+    scout_config.set(socket_path="foo", core_agent_socket_path="bar")
+
+    result = core_agent_manager.socket_path()
+
+    assert result == ["--socket", "foo"]
+
+
 def test_log_level(core_agent_manager):
     scout_config.set(core_agent_log_level="foo")
 
@@ -114,3 +130,35 @@ def test_log_level_old_name_takes_precedence(core_agent_manager):
     result = core_agent_manager.log_level()
 
     assert result == ["--log-level", "foo"]
+
+
+def test_log_file(core_agent_manager):
+    scout_config.set(core_agent_log_file="foo")
+
+    result = core_agent_manager.log_file()
+
+    assert result == ["--log-file", "foo"]
+
+
+def test_log_file_old_name_takes_precedence(core_agent_manager):
+    scout_config.set(log_file="foo", core_agent_log_file="bar")
+
+    result = core_agent_manager.log_file()
+
+    assert result == ["--log-file", "foo"]
+
+
+def test_config_file(core_agent_manager):
+    scout_config.set(core_agent_config_file="foo")
+
+    result = core_agent_manager.config_file()
+
+    assert result == ["--config-file", "foo"]
+
+
+def test_config_file_old_name_takes_precedence(core_agent_manager):
+    scout_config.set(config_file="foo", core_agent_config_file="bar")
+
+    result = core_agent_manager.config_file()
+
+    assert result == ["--config-file", "foo"]
diff --git a/tests/unit/core/test_config.py b/tests/unit/core/test_config.py
--- a/tests/unit/core/test_config.py
+++ b/tests/unit/core/test_config.py
@@ -45,7 +45,7 @@ def test_get_derived_config_value():
             r"-(x86_64|i686|unknown)"
             r"-(unknown-linux-gnu|apple-darwin|unknown)"
             r"/scout-agent\.sock",
-            config.value("socket_path"),
+            config.value("core_agent_socket_path"),
         )
     finally:
         ScoutConfig.reset_all()