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

Commit

Permalink
Record logs passed with Span::FinishWithOptions (#58)
Browse files Browse the repository at this point in the history
Jaeger cpp-client was previously dropping logs included in a FinishSpanOptions
silently on the floor.

Fixes #57

Signed-off-by: Craig Ringer <[email protected]>
  • Loading branch information
ringerc authored and isaachier committed Mar 26, 2018
1 parent 567c23b commit 0977a4d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/jaegertracing/LogRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <type_traits>
#include <vector>

#include <opentracing/span.h>

namespace jaegertracing {

class LogRecord {
Expand All @@ -45,6 +47,12 @@ class LogRecord {
{
}

LogRecord(const opentracing::LogRecord & other)
: _timestamp(other.timestamp),
_fields(other.fields.begin(), other.fields.end())
{
}

const Clock::time_point& timestamp() const { return _timestamp; }

const std::vector<Tag>& fields() const { return _fields; }
Expand Down
4 changes: 4 additions & 0 deletions src/jaegertracing/Span.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ void Span::FinishWithOptions(
}
_duration = finishTimeSteady - _startTimeSteady;
tracer = _tracer;

std::copy(finishSpanOptions.log_records.begin(),
finishSpanOptions.log_records.end(),
std::back_inserter(_logs));
}

// Call `reportSpan` even for non-sampled traces.
Expand Down
7 changes: 7 additions & 0 deletions src/jaegertracing/Tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class Tag {
{
}

template <typename ValueArg>
Tag(const std::pair<std::string,ValueArg> & tag_pair)
: _key(tag_pair.first)
, _value(tag_pair.second)
{
}

bool operator==(const Tag& rhs) const
{
return _key == rhs._key && _value == rhs._value;
Expand Down
7 changes: 6 additions & 1 deletion src/jaegertracing/TracerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ TEST(Tracer, testTracer)
ASSERT_EQ("test-baggage-item-value",
span->BaggageItem("test-baggage-item-key"));
span->Log({ { "log-bool", true } });
span->Finish();
opentracing::FinishSpanOptions foptions;
opentracing::LogRecord lr{};
lr.fields = { {"options-log", "yep"} };
foptions.log_records.push_back(std::move(lr));
lr.timestamp = opentracing::SystemClock::now();
span->FinishWithOptions(foptions);
ASSERT_GE(Span::SteadyClock::now(),
span->startTimeSteady() + span->duration());
span->SetOperationName("test-set-operation-after-finish");
Expand Down

0 comments on commit 0977a4d

Please sign in to comment.