Repository: rollbar/pyrollbar

Issue:
Unable to Override the Host name
I'm integrating the RollBar with python for our project that ran on Docker.
But I can't override the host name of Server. Rollbar is only reporting default host name. How can I change the host name ?

Discussion:
@brianr: @EricSei Good quesiton... there's no great way to do this now, but here's an ugly one that should work:

Monkeypatch [`_build_server_data`](https://github.com/rollbar/pyrollbar/blob/master/rollbar/__init__.py#L1299), e.g.:

```
import rollbar
orig_build_server_data = rollbar._build_server_data
def new_build_server_data():
    data = orig_build_server_data()
    data['host'] = 'my hostname value goes here'  # call a function to get this, etc.
    return data
rollbar._build_server_data = new_build_server_data
```

Will this work?@EricSei: Thanks for your answer. I will try your code and keep you updated. @gnpar: Note that the [official rollbar docs](https://docs.rollbar.com/docs/environments#recommended-usage) recommend setting the host for multiple production environments:

> ## Recommended usage
> Use the environment value production for all errors from and deploys to any production environment, even if you have multiple production environments.
> Use the host property in your error payloads to include the 'full path' of the server where an error occurred, including the name of the region/zone, e.g. us-east-1-web02 for the server web-02 that is hosted in the us-east-1 region.



So this should probably be supported. I can work on a PR for this if you'd like.
@danielmorell: @gnpar I agree that an update seems reasonable. Let me see what I can do.

Solution patch:
diff --git a/rollbar/__init__.py b/rollbar/__init__.py
index 2a3a62d..d9a9c56 100644
--- a/rollbar/__init__.py
+++ b/rollbar/__init__.py
@@ -268,6 +268,7 @@ SETTINGS = {
     'environment': 'production',
     'exception_level_filters': [],
     'root': None,  # root path to your code
+    'host': None,  # custom hostname of the current host
     'branch': None,  # git branch name
     'code_version': None,
     # 'blocking', 'thread' (default), 'async', 'agent', 'tornado', 'gae', 'twisted', 'httpx' or 'thread_pool'
@@ -1447,8 +1448,9 @@ def _build_server_data():
     Returns a dictionary containing information about the server environment.
     """
     # server environment
+    host = SETTINGS.get('host') or socket.gethostname()
     server_data = {
-        'host': socket.gethostname(),
+        'host': host,
         'pid': os.getpid()
     }
 
diff --git a/rollbar/logger.py b/rollbar/logger.py
index ef3b102..aada05d 100644
--- a/rollbar/logger.py
+++ b/rollbar/logger.py
@@ -60,7 +60,9 @@ class RollbarHandler(logging.Handler):
 
         if access_token is not None:
             rollbar.init(
-                access_token, environment, **resolve_logging_types(kw))
+                access_token, environment,
+                allow_logging_basic_config=False,   # a handler shouldn't configure the root logger
+                **resolve_logging_types(kw))
 
         self.notify_level = _checkLevel(level)
 


Test patch:
diff --git a/rollbar/test/test_rollbar.py b/rollbar/test/test_rollbar.py
index 29daf3d..eeb77db 100644
--- a/rollbar/test/test_rollbar.py
+++ b/rollbar/test/test_rollbar.py
@@ -74,14 +74,16 @@ class RollbarTest(BaseTest):
         self.assertIn('argv', server_data)
         self.assertNotIn('branch', server_data)
         self.assertNotIn('root', server_data)
+        self.assertGreater(len(server_data['host']), 2)
 
+        rollbar.SETTINGS['host'] = 'test-host'
         rollbar.SETTINGS['branch'] = 'master'
         rollbar.SETTINGS['root'] = '/home/test/'
 
         server_data = rollbar._build_server_data()
 
-        self.assertIn('host', server_data)
         self.assertIn('argv', server_data)
+        self.assertEqual(server_data['host'], 'test-host')
         self.assertEqual(server_data['branch'], 'master')
         self.assertEqual(server_data['root'], '/home/test/')