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

Commit 0977a4d

Browse files
ringercisaachier
authored andcommitted
Record logs passed with Span::FinishWithOptions (#58)
Jaeger cpp-client was previously dropping logs included in a FinishSpanOptions silently on the floor. Fixes #57 Signed-off-by: Craig Ringer <[email protected]>
1 parent 567c23b commit 0977a4d

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

src/jaegertracing/LogRecord.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <type_traits>
2626
#include <vector>
2727

28+
#include <opentracing/span.h>
29+
2830
namespace jaegertracing {
2931

3032
class LogRecord {
@@ -45,6 +47,12 @@ class LogRecord {
4547
{
4648
}
4749

50+
LogRecord(const opentracing::LogRecord & other)
51+
: _timestamp(other.timestamp),
52+
_fields(other.fields.begin(), other.fields.end())
53+
{
54+
}
55+
4856
const Clock::time_point& timestamp() const { return _timestamp; }
4957

5058
const std::vector<Tag>& fields() const { return _fields; }

src/jaegertracing/Span.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ void Span::FinishWithOptions(
9797
}
9898
_duration = finishTimeSteady - _startTimeSteady;
9999
tracer = _tracer;
100+
101+
std::copy(finishSpanOptions.log_records.begin(),
102+
finishSpanOptions.log_records.end(),
103+
std::back_inserter(_logs));
100104
}
101105

102106
// Call `reportSpan` even for non-sampled traces.

src/jaegertracing/Tag.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ class Tag {
3838
{
3939
}
4040

41+
template <typename ValueArg>
42+
Tag(const std::pair<std::string,ValueArg> & tag_pair)
43+
: _key(tag_pair.first)
44+
, _value(tag_pair.second)
45+
{
46+
}
47+
4148
bool operator==(const Tag& rhs) const
4249
{
4350
return _key == rhs._key && _value == rhs._value;

src/jaegertracing/TracerTest.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,12 @@ TEST(Tracer, testTracer)
179179
ASSERT_EQ("test-baggage-item-value",
180180
span->BaggageItem("test-baggage-item-key"));
181181
span->Log({ { "log-bool", true } });
182-
span->Finish();
182+
opentracing::FinishSpanOptions foptions;
183+
opentracing::LogRecord lr{};
184+
lr.fields = { {"options-log", "yep"} };
185+
foptions.log_records.push_back(std::move(lr));
186+
lr.timestamp = opentracing::SystemClock::now();
187+
span->FinishWithOptions(foptions);
183188
ASSERT_GE(Span::SteadyClock::now(),
184189
span->startTimeSteady() + span->duration());
185190
span->SetOperationName("test-set-operation-after-finish");

0 commit comments

Comments
 (0)