Skip to content

Commit

Permalink
Don't attempt to lookup the ip address if specified via a tag
Browse files Browse the repository at this point in the history
This matches the functionality of jaeger-client-java after
jaegertracing/jaeger-client-java#371 was merged.

Refs: jaegertracing#166
  • Loading branch information
SEJeff committed Apr 29, 2018
1 parent 93c26c8 commit 21dc240
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions jaeger_client/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def __init__(
self.service_name = service_name
self.reporter = reporter
self.sampler = sampler
self.ip_address = ipv4_to_int(local_ip())
self.metrics_factory = metrics_factory or LegacyMetricsFactory(metrics or Metrics())
self.metrics = TracerMetrics(self.metrics_factory)
self.random = random.Random(time.time() * (os.getpid() or 1))
Expand All @@ -80,11 +79,13 @@ def __init__(
self.codecs.update(extra_codecs)
self.tags = {
constants.JAEGER_VERSION_TAG_KEY: constants.JAEGER_CLIENT_VERSION,
constants.JAEGER_IP_TAG_KEY: self.ip_address,
}
if tags:
self.tags.update(tags)

if self.tags.get(constants.JAEGER_IP_TAG_KEY) is None:
self.tags[constants.JAEGER_IP_TAG_KEY] = ipv4_to_int(local_ip())

if self.tags.get(constants.JAEGER_HOSTNAME_TAG_KEY) is None:
try:
hostname = socket.gethostname()
Expand Down
15 changes: 15 additions & 0 deletions tests/test_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def test_tracer_override_codecs():
assert tracer.codecs[Format.BINARY] == "overridden_binary_codec",\
"Binary format codec not overridden"


def test_tracer_hostname_tag():
reporter = mock.MagicMock()
sampler = ConstSampler(True)
Expand All @@ -274,3 +275,17 @@ def test_tracer_hostname_tag():

assert tracer.tags[c.JAEGER_HOSTNAME_TAG_KEY] == \
'jaeger-client-app.local'


def test_tracer_ip_tag():
reporter = mock.MagicMock()
sampler = ConstSampler(True)
tracer = Tracer(
service_name='x',
tags={c.JAEGER_IP_TAG_KEY: '192.0.2.3'},
reporter=reporter,
sampler=sampler,
)

assert tracer.tags[c.JAEGER_IP_TAG_KEY] == \
'192.0.2.3'

0 comments on commit 21dc240

Please sign in to comment.