Skip to content

Commit 48f436b

Browse files
authored
Merge pull request #392 from DataDog/christian/configurefix
[tracer] keep hostname and port when calling configure()
2 parents 4794988 + ac6f58d commit 48f436b

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

ddtrace/tracer.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,15 @@ def configure(self, enabled=None, hostname=None, port=None, sampler=None,
114114

115115
if hostname is not None or port is not None or filters is not None or \
116116
priority_sampling is not None:
117+
# Preserve hostname and port when overriding filters or priority sampling
118+
default_hostname = self.DEFAULT_HOSTNAME
119+
default_port = self.DEFAULT_PORT
120+
if hasattr(self, 'writer') and hasattr(self.writer, 'api'):
121+
default_hostname = self.writer.api.hostname
122+
default_port = self.writer.api.port
117123
self.writer = AgentWriter(
118-
hostname or self.DEFAULT_HOSTNAME,
119-
port or self.DEFAULT_PORT,
124+
hostname or default_hostname,
125+
port or default_port,
120126
filters=filters,
121127
priority_sampler=self.priority_sampler,
122128
)

tests/test_integration.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,3 +518,23 @@ def test_send_single_trace(self):
518518
response = self.api_msgpack.send_traces(traces)
519519
ok_(response)
520520
eq_(response.status, 200)
521+
522+
@skipUnless(
523+
os.environ.get('TEST_DATADOG_INTEGRATION', False),
524+
'You should have a running trace agent and set TEST_DATADOG_INTEGRATION=1 env variable'
525+
)
526+
class TestConfigure(TestCase):
527+
"""
528+
Ensures that when calling configure without specifying hostname and port,
529+
previous overrides have been kept.
530+
"""
531+
def test_configure_keeps_api_hostname_and_port(self):
532+
tracer = Tracer() # use real tracer with real api
533+
eq_('localhost', tracer.writer.api.hostname)
534+
eq_(8126, tracer.writer.api.port)
535+
tracer.configure(hostname='127.0.0.1', port=8127)
536+
eq_('127.0.0.1', tracer.writer.api.hostname)
537+
eq_(8127, tracer.writer.api.port)
538+
tracer.configure(priority_sampling=True)
539+
eq_('127.0.0.1', tracer.writer.api.hostname)
540+
eq_(8127, tracer.writer.api.port)

0 commit comments

Comments
 (0)