Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
Fix host IP formatting and improve local IP API (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
isaachier authored and black-adder committed Nov 14, 2017
1 parent dd369e2 commit f325ae1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if(HUNTER_ENABLED)
endif()
endif()

project(jaegertracing VERSION 0.0.5)
project(jaegertracing VERSION 0.0.7)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Expand Down
6 changes: 2 additions & 4 deletions src/jaegertracing/Tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class Tracer : public opentracing::Tracer,
const std::shared_ptr<logging::Logger>& logger,
const std::shared_ptr<metrics::Metrics>& metrics)
: _serviceName(serviceName)
, _hostIPv4(net::IPAddress::host(AF_INET))
, _hostIPv4(net::IPAddress::localIP(AF_INET))
, _sampler(sampler)
, _reporter(reporter)
, _metrics(metrics)
Expand All @@ -219,9 +219,7 @@ class Tracer : public opentracing::Tracer,
_logger->error("Unable to determine this host's IP address");
}
else {
std::ostringstream oss;
oss << _hostIPv4;
_tags.push_back(Tag(kTracerIPTagKey, oss.str()));
_tags.push_back(Tag(kTracerIPTagKey, _hostIPv4.host()));
}

std::random_device device;
Expand Down
10 changes: 10 additions & 0 deletions src/jaegertracing/TracerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ TEST(Tracer, testTracer)
options.references.emplace_back(opentracing::SpanReferenceType::ChildOfRef,
&debugCtx);

const auto& tags = tracer->tags();
auto itr = std::find_if(
std::begin(tags),
std::end(tags),
[](const Tag& tag) { return tag.key() == kTracerIPTagKey; });
ASSERT_NE(std::end(tags), itr);
ASSERT_TRUE(itr->value().is<std::string>());
ASSERT_EQ(net::IPAddress::v4(itr->value().get<std::string>()).host(),
net::IPAddress::localIP(AF_INET).host());

std::unique_ptr<Span> span(static_cast<Span*>(
tracer->StartSpanWithOptions("test-operation", options).release()));
ASSERT_TRUE(static_cast<bool>(span));
Expand Down
6 changes: 3 additions & 3 deletions src/jaegertracing/net/IPAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ struct IfAddrDeleter : public std::function<void(ifaddrs*)> {

} // anonymous namespace

IPAddress IPAddress::host(int family)
IPAddress IPAddress::localIP(int family)
{
return host([family](const ifaddrs* ifAddr) {
return localIP([family](const ifaddrs* ifAddr) {
return ifAddr->ifa_addr->sa_family == family;
});
}

IPAddress IPAddress::host(std::function<bool(const ifaddrs*)> filter)
IPAddress IPAddress::localIP(std::function<bool(const ifaddrs*)> filter)
{
auto* ifAddrRawPtr = static_cast<ifaddrs*>(nullptr);
getifaddrs(&ifAddrRawPtr);
Expand Down
4 changes: 2 additions & 2 deletions src/jaegertracing/net/IPAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class IPAddress {
return versionFromString(ip, port, AF_INET6);
}

static IPAddress host(int family);
static IPAddress localIP(int family);

static IPAddress host(std::function<bool(const ifaddrs*)> filter);
static IPAddress localIP(std::function<bool(const ifaddrs*)> filter);

IPAddress()
: _addr()
Expand Down

0 comments on commit f325ae1

Please sign in to comment.