Repository: scoutapp/scout_apm_python
Pull request #251 (2019-09-11 08:50:48)

Override hostname
See: https://github.com/scoutapp/scout_apm_python/issues/248
This also requires the binary agent changes, so do not merge yet.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 88bc388..97c16b9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,8 @@
   ([PR #240](https://github.com/scoutapp/scout_apm_python/pull/240)).
 - Fix CPU statistics to work when the CPU count cannot be determined
   ([PR #245](https://github.com/scoutapp/scout_apm_python/pull/245)).
+- Support the `hostname` setting
+  ([PR #251](https://github.com/scoutapp/scout_apm_python/pull/251)).
 - Support timeline trace view
   ([PR #252](https://github.com/scoutapp/scout_apm_python/pull/252)).
 
diff --git a/src/scout_apm/core/commands.py b/src/scout_apm/core/commands.py
index c891613..e4471ac 100644
--- a/src/scout_apm/core/commands.py
+++ b/src/scout_apm/core/commands.py
@@ -16,13 +16,18 @@ class Register(object):
     def __init__(self, *args, **kwargs):
         self.app = kwargs.get("app")
         self.key = kwargs.get("key")
+        self.hostname = kwargs.get("hostname")
 
     def message(self):
-        logger.info("Registering with app=%s key=%s" % (self.app, self.key))
+        logger.info(
+            "Registering with app=%s key=%s host=%s"
+            % (self.app, self.key, self.hostname)
+        )
         return {
             "Register": {
                 "app": self.app,
                 "key": self.key,
+                "host": self.hostname,
                 "language": "python",
                 "api_version": "1.0",
             }
diff --git a/src/scout_apm/core/config.py b/src/scout_apm/core/config.py
index 22a1570..842fa0c 100644
--- a/src/scout_apm/core/config.py
+++ b/src/scout_apm/core/config.py
@@ -223,7 +223,7 @@ class ScoutConfigDefaults(object):
             "download_url": "https://s3-us-west-1.amazonaws.com/scout-public-downloads/apm_core_agent/release",  # noqa: E501
             "framework": "",
             "framework_version": "",
-            "hostname": "",
+            "hostname": None,
             "key": "",
             "log_level": "info",
             "monitor": False,
diff --git a/src/scout_apm/core/socket.py b/src/scout_apm/core/socket.py
index 03c19de..e6f002d 100644
--- a/src/scout_apm/core/socket.py
+++ b/src/scout_apm/core/socket.py
@@ -197,7 +197,11 @@ class CoreAgentSocket(threading.Thread):
 
     def _register(self):
         self._send(
-            Register(app=self.config.value("name"), key=self.config.value("key"))
+            Register(
+                app=self.config.value("name"),
+                key=self.config.value("key"),
+                hostname=self.config.value("hostname"),
+            )
         )
 
     def _connect(self, connect_attempts=5, retry_wait_secs=1):


Test patch:
diff --git a/tests/unit/core/test_commands.py b/tests/unit/core/test_commands.py
index 022c560..5684858 100644
--- a/tests/unit/core/test_commands.py
+++ b/tests/unit/core/test_commands.py
@@ -32,11 +32,12 @@ END_TIME_STR = "2018-12-01T17:04:34.641403Z"
     "command, message",
     [
         (
-            commands.Register(app="test_app", key="test_key"),
+            commands.Register(app="test_app", key="test_key", hostname="test_host"),
             {
                 "Register": {
                     "app": "test_app",
                     "key": "test_key",
+                    "host": "test_host",
                     "language": "python",
                     "api_version": "1.0",
                 }