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

Commit

Permalink
Update OpenTracing to 1.6.0. Use GTest @1.8.0 because the latest vers…
Browse files Browse the repository at this point in the history
…ion seems to have a problem with rpath.

Signed-off-by: Mehrez DOUAIHY <mehrez.douaihy@gmail.com> (+2 squashed commits)
  • Loading branch information
mdouaihy committed Feb 25, 2020
1 parent 9e1b39c commit d413b0a
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 24 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ matrix:
env:
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7 && CMAKE_OPTIONS='-DCMAKE_BUILD_TYPE=Release
-DJAEGERTRACING_PLUGIN=ON -DBUILD_TESTING=ON -DHUNTER_CONFIGURATION_TYPES=Release'"
branches:
only:
- master
before_install:
- eval "${MATRIX_EVAL}"
- mkdir cmake-download && cd cmake-download && curl -O https://cmake.org/files/v3.10/cmake-3.10.0-rc5-Linux-x86_64.sh
Expand Down
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ include(HunterGate)
option(HUNTER_BUILD_SHARED_LIBS "Build Shared Library" ON)

HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.23.201.tar.gz"
SHA1 "29f10683f10c7b35e1f599d71542af0c2daa6a01"
URL "https://github.com/cpp-pm/hunter/archive/v0.23.249.tar.gz"
SHA1 "d45d77d8bba9da13e9290a180e0477e90accd89b"
LOCAL # load `${CMAKE_CURRENT_LIST_DIR}/cmake/Hunter/config.cmake`
)

project(jaegertracing VERSION 0.5.0)
Expand Down Expand Up @@ -341,7 +342,7 @@ if(BUILD_TESTING)
src/jaegertracing/utils/UDPSenderTest.cpp
src/jaegertracing/utils/HTTPTransporterTest.cpp)
target_link_libraries(
UnitTest PRIVATE testutils GTest::main ${JAEGERTRACING_LIB})
UnitTest PRIVATE testutils PUBLIC GTest::main ${JAEGERTRACING_LIB})
add_test(NAME UnitTest COMMAND UnitTest)

update_path_for_test(UnitTest)
Expand Down
1 change: 1 addition & 0 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hunter_config(GTest VERSION 1.8.0-hunter-p11)
2 changes: 1 addition & 1 deletion src/jaegertracing/Span.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void Span::SetBaggageItem(opentracing::string_view restrictedKey,
value,
[this](std::vector<Tag>::const_iterator first,
std::vector<Tag>::const_iterator last) {
logFieldsNoLocking(first, last);
logFieldsNoLocking(SystemClock::now(), first, last);
});
_context = _context.withBaggage(baggage);
}
Expand Down
54 changes: 38 additions & 16 deletions src/jaegertracing/Span.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,24 +190,27 @@ class Span : public opentracing::Span {
: itr->second;
}

void Log(opentracing::SystemTime timestamp,
std::initializer_list<
std::pair<opentracing::string_view, opentracing::Value>>
fieldPairs) noexcept override
{
doLog(timestamp, fieldPairs);
}

void Log(opentracing::SystemTime timestamp,
const std::vector<
std::pair<opentracing::string_view, opentracing::Value>>&
fieldPairs) noexcept override
{
doLog(timestamp, fieldPairs);
}

void Log(std::initializer_list<
std::pair<opentracing::string_view, opentracing::Value>>
fieldPairs) noexcept override
{
std::lock_guard<std::mutex> lock(_mutex);
if (!_context.isSampled()) {
return;
}

std::vector<Tag> fields;
fields.reserve(fieldPairs.size());
std::transform(
std::begin(fieldPairs),
std::end(fieldPairs),
std::back_inserter(fields),
[](const std::pair<opentracing::string_view, opentracing::Value>&
pair) { return Tag(pair.first, pair.second); });
logFieldsNoLocking(std::begin(fields), std::end(fields));
doLog(SystemClock::now(), fieldPairs);
}

const SpanContext& context() const noexcept override
Expand All @@ -228,12 +231,31 @@ class Span : public opentracing::Span {
bool isFinished() const { return _duration != SteadyClock::duration(); }

template <typename FieldIterator>
void logFieldsNoLocking(FieldIterator first, FieldIterator last) noexcept
void logFieldsNoLocking(const std::chrono::system_clock::time_point& timestamp, FieldIterator first, FieldIterator last) noexcept
{
LogRecord log(SystemClock::now(), first, last);
LogRecord log(timestamp, first, last);
_logs.push_back(log);
}

template <typename Container>
void doLog(opentracing::SystemTime timestamp, Container fieldPairs) noexcept
{
std::lock_guard<std::mutex> lock(_mutex);
if (!_context.isSampled()) {
return;
}

std::vector<Tag> fields;
fields.reserve(fieldPairs.size());
std::transform(
std::begin(fieldPairs),
std::end(fieldPairs),
std::back_inserter(fields),
[](const std::pair<opentracing::string_view, opentracing::Value>&
pair) { return Tag(pair.first, pair.second); });
logFieldsNoLocking(timestamp, std::begin(fields), std::end(fields));
}

void setSamplingPriority(const opentracing::Value& value);

std::shared_ptr<const Tracer> _tracer;
Expand Down
2 changes: 1 addition & 1 deletion src/jaegertracing/SpanContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class SpanContext : public opentracing::SpanContext {
forEachBaggageItem(f);
}

std::unique_ptr<opentracing::SpanContext> Clone() const noexcept
std::unique_ptr<opentracing::SpanContext> Clone() const noexcept override
{
std::lock_guard<std::mutex> lock(_mutex);
return std::unique_ptr<opentracing::SpanContext>(
Expand Down
5 changes: 5 additions & 0 deletions src/jaegertracing/TracerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class FakeSpanContext : public opentracing::SpanContext {
{
// Do nothing
}

virtual std::unique_ptr<SpanContext> Clone() const noexcept override
{
return std::unique_ptr<FakeSpanContext>(new FakeSpanContext());
}
};

template <typename BaseWriter>
Expand Down

0 comments on commit d413b0a

Please sign in to comment.