Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
0b88e47
Add buffer chain
rnburn Jan 13, 2020
375e3d4
s/AsyncTransporter/LeacyAsyncTransporter/
rnburn Jan 13, 2020
87a4a19
Add new AsyncTransporter
rnburn Jan 13, 2020
053843c
s/ManualRecorder/LegacyManualRecorder/
rnburn Jan 13, 2020
10c054c
Add new manual recorder
rnburn Jan 14, 2020
541e5ba
Set up manual recorder
rnburn Jan 15, 2020
1f8d443
Add ReportRequest
rnburn Jan 15, 2020
7f1982b
Factor out report request header serialization code
rnburn Jan 15, 2020
40c11ce
Migrate code to use WriteReportRequestHeader
rnburn Jan 15, 2020
b1cc701
Remove unused function
rnburn Jan 15, 2020
9932689
Move EmbeddedMetricsMessage
rnburn Jan 16, 2020
47377ae
Set up ReportRequest
rnburn Jan 16, 2020
28b8683
Fill out BufferChain
rnburn Jan 16, 2020
36bcad2
Support joining SerializationChains
rnburn Jan 16, 2020
80383f3
Add SerializationChain test coverage
rnburn Jan 16, 2020
7f918fe
Fill out ReportRequest
rnburn Jan 16, 2020
300ed94
Fill out ReportRequest
rnburn Jan 17, 2020
68cf920
Add ChainedStream
rnburn Jan 17, 2020
2dcd895
Add test for ChainedStream
rnburn Jan 17, 2020
d204bc0
Fix ChainedStream
rnburn Jan 17, 2020
154c6c4
Add test coverage for ChainedStream
rnburn Jan 17, 2020
da6e7cf
Add ComposableFragmentInputStream
rnburn Jan 17, 2020
673cd26
Fix ComposableFragmentInputStream
rnburn Jan 22, 2020
1450283
Make ChainedStream composable
rnburn Jan 22, 2020
776f28b
Add ChainedStream to Recorder interface
rnburn Jan 22, 2020
3079567
Add new ChainedStream into Span
rnburn Jan 22, 2020
3009a7b
Fill out the ChainedStream
rnburn Jan 22, 2020
35ba5b1
Add function for serializing ReportRequest headers
rnburn Jan 23, 2020
4878321
Add code for framing chunked http
rnburn Jan 23, 2020
ec3e173
Add test for chunked http framing
rnburn Jan 23, 2020
6fc1174
Add ability to write a footer
rnburn Jan 23, 2020
33a0c5a
Work on replace SerializationChain
rnburn Jan 23, 2020
584e806
Renaming
rnburn Jan 24, 2020
cfd079b
Add version of AddSpanChunkFramedString for ChainedStream
rnburn Jan 24, 2020
926d493
Switch StreamRecorder to use ChainedStream
rnburn Jan 25, 2020
84a1cbe
Update InMemoryRecorder
rnburn Jan 25, 2020
78d63a0
Remove SerializationChain from Span
rnburn Jan 25, 2020
842c25b
Remove SerializationChain from Recorder interface
rnburn Jan 25, 2020
583b2f7
Remove SerializationChain tests
rnburn Jan 25, 2020
2b1c876
Remove SerializationChain from test/utility
rnburn Jan 25, 2020
4240d08
Remove SerializationChain references
rnburn Jan 25, 2020
8f171d4
Remove SerializationChain references
rnburn Jan 25, 2020
1759804
Update ReportRequest
rnburn Jan 25, 2020
e96fe0b
Removee SerializationChain
rnburn Jan 25, 2020
3ede7dc
Fill out ManualRecorder
rnburn Jan 25, 2020
f52b204
Factor out MetricsTracker
rnburn Jan 27, 2020
6ebc38e
Add MetricsTracker to ManualRecorder
rnburn Jan 27, 2020
3eb6603
Fill out ReportRequest
rnburn Jan 27, 2020
3554a50
Fill out ReportRequest tests
rnburn Jan 27, 2020
d71b2df
Implement AsyncTransporter::Callback interface in ManualRecorder
rnburn Jan 27, 2020
dfc9906
Fill out manual recorder
rnburn Jan 28, 2020
e8c8b9f
Make ManualRecorder fork safe
rnburn Jan 28, 2020
da9e394
Add ManualRcorder test
rnburn Jan 28, 2020
338ed37
s/InMemoryAsyncTransporter/LegacyInMemoryAsyncTransporter/
rnburn Jan 28, 2020
97cd1b6
Add InMemoryAsyncTransporter
rnburn Jan 28, 2020
63ee0eb
Fill out manual recorder test
rnburn Jan 28, 2020
1cd0be1
Add tests for ManualRecorder
rnburn Jan 28, 2020
f57feea
Fill out more of ManualRecorder
rnburn Jan 29, 2020
a755aa6
Fix build error
rnburn Jan 29, 2020
bfa63d8
Add manual tracer benchmarking
rnburn Jan 29, 2020
15ba487
Add logging benchmark
rnburn Jan 29, 2020
63eee75
Fix cmake build
rnburn Jan 29, 2020
bf21347
Fix cmake build
rnburn Jan 29, 2020
ebdb40f
Fix clang-tidy errors
rnburn Jan 29, 2020
fd8c58a
Update documentation
rnburn Jan 30, 2020
6acc881
Fix typos
rnburn Feb 3, 2020
9c3ab25
Merge branch 'master' of github.com:lightstep/lightstep-tracer-cpp in…
rnburn Feb 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ include(LightStepTracerCommon)
include(LightStepTracerConfiguration)

set(LIGHTSTEP_SRCS src/common/utility.cpp
src/common/buffer_chain.cpp
src/common/fragment_input_stream.cpp
src/common/fragment_array_input_stream.cpp
src/common/protobuf.cpp
Expand All @@ -204,13 +205,20 @@ set(LIGHTSTEP_SRCS src/common/utility.cpp
src/common/random.cpp
src/common/random_traverser.cpp
src/common/serialization.cpp
src/common/serialization_chain.cpp
src/common/chunked_http_framing.cpp
src/common/report_request_framing.cpp
src/common/composable_fragment_input_stream.cpp
src/common/chained_stream.cpp
src/common/timestamp.cpp
src/recorder/report_builder.cpp
src/recorder/auto_recorder.cpp
src/recorder/fork_aware_recorder.cpp
src/recorder/legacy_manual_recorder.cpp
src/recorder/manual_recorder.cpp
src/recorder/transporter.cpp
src/recorder/serialization/report_request.cpp
src/recorder/serialization/report_request_header.cpp
src/recorder/serialization/embedded_metrics_message.cpp
src/tracer/binary_carrier.cpp
src/tracer/json_options.cpp
src/tracer/propagation/b3_propagator.cpp
Expand Down Expand Up @@ -266,10 +274,9 @@ if (WITH_LIBEVENT)
src/recorder/stream_recorder/satellite_connection.cpp
src/recorder/stream_recorder/satellite_streamer.cpp
src/recorder/stream_recorder/span_stream.cpp
src/recorder/stream_recorder/stream_recorder_metrics.cpp
src/recorder/metrics_tracker.cpp
src/recorder/stream_recorder/connection_stream.cpp
src/recorder/stream_recorder/host_header.cpp
src/recorder/stream_recorder/embedded_metrics_message.cpp
src/recorder/stream_recorder/status_line_parser.cpp
src/recorder/stream_recorder/utility.cpp
src/network/event.cpp
Expand Down
9 changes: 9 additions & 0 deletions benchmark/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ lightstep_google_benchmark(
],
)

lightstep_google_benchmark(
name = "manual_tracer_benchmark",
srcs = [
"manual_tracer_benchmark.cpp",
],
deps = [
"//:tracer_lib",
],
)
156 changes: 156 additions & 0 deletions benchmark/manual_tracer_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#include <cassert>
#include <memory>

#include "lightstep/tracer.h"

#include "benchmark/benchmark.h"

int MaxBufferedSpans = 500;

//--------------------------------------------------------------------------------------------------
// LegacyNullTransport
//--------------------------------------------------------------------------------------------------
namespace {
class LegacyNullTransporter final : public lightstep::LegacyAsyncTransporter {
public:
// LegacyAsyncTransporter
void Send(const google::protobuf::Message& request,
google::protobuf::Message& /*response*/,
Callback& callback) override {
using google::protobuf::uint8;
auto size = request.ByteSizeLong();
std::unique_ptr<uint8> buffer{new uint8[size]};
request.SerializeWithCachedSizesToArray(buffer.get());
callback.OnSuccess();
}
};
} // namespace

//--------------------------------------------------------------------------------------------------
// NullTransporter
//--------------------------------------------------------------------------------------------------
namespace {
class NullTransporter final : public lightstep::AsyncTransporter {
public:
// AsyncTransporter
void Send(std::unique_ptr<lightstep::BufferChain>&& message,
Callback& callback) noexcept override {
auto size = message->num_bytes();
std::unique_ptr<char> buffer{new char[size]};
message->CopyOut(buffer.get(), size);
callback.OnSuccess(*message);
}
};
} // namespace

//--------------------------------------------------------------------------------------------------
// MakeLegacyManualTracer
//--------------------------------------------------------------------------------------------------
static std::shared_ptr<lightstep::LightStepTracer> MakeLegacyManualTracer() {
lightstep::LightStepTracerOptions tracer_options;
tracer_options.transporter.reset(new LegacyNullTransporter{});
tracer_options.use_thread = false;
tracer_options.component_name = "abc";
tracer_options.access_token = "123";
tracer_options.max_buffered_spans = static_cast<size_t>(MaxBufferedSpans);

return lightstep::MakeLightStepTracer(std::move(tracer_options));
}

//--------------------------------------------------------------------------------------------------
// MakeManualTracer
//--------------------------------------------------------------------------------------------------
static std::shared_ptr<lightstep::LightStepTracer> MakeManualTracer() {
lightstep::LightStepTracerOptions tracer_options;
tracer_options.transporter.reset(new NullTransporter{});
tracer_options.use_thread = false;
tracer_options.component_name = "abc";
tracer_options.access_token = "123";
tracer_options.max_buffered_spans = static_cast<size_t>(MaxBufferedSpans);

return lightstep::MakeLightStepTracer(std::move(tracer_options));
}

//--------------------------------------------------------------------------------------------------
// MakeTracer
//--------------------------------------------------------------------------------------------------
static std::shared_ptr<lightstep::LightStepTracer> MakeTracer(
opentracing::string_view tracer_type = "legacy_manual") {
if (tracer_type == "legacy_manual") {
return MakeLegacyManualTracer();
}
if (tracer_type == "manual") {
return MakeManualTracer();
}
std::cerr << "Unknown tracer type: " << tracer_type << "\n";
std::terminate();
}

//--------------------------------------------------------------------------------------------------
// BM_SmallSpanReport
//--------------------------------------------------------------------------------------------------
static void BM_SmallSpanReport(benchmark::State& state,
const char* tracer_type) {
auto tracer = MakeTracer(tracer_type);
assert(tracer != nullptr);
for (auto _ : state) {
for (int i = 0; i < MaxBufferedSpans; ++i) {
auto span = tracer->StartSpan("abc123");
}
tracer->Flush();
}
}
BENCHMARK_CAPTURE(BM_SmallSpanReport, legacy_manual, "legacy_manual");
BENCHMARK_CAPTURE(BM_SmallSpanReport, manual, "manual");

//--------------------------------------------------------------------------------------------------
// BM_TaggedSpanReport
//--------------------------------------------------------------------------------------------------
static void BM_TaggedSpanReport(benchmark::State& state,
const char* tracer_type) {
auto tracer = MakeTracer(tracer_type);
assert(tracer != nullptr);
for (auto _ : state) {
for (int i = 0; i < MaxBufferedSpans; ++i) {
auto span = tracer->StartSpan("abc123");
char key[5];
key[0] = 'a';
key[1] = 'b';
key[2] = 'c';
key[3] = '0';
key[4] = '\0';
for (int i = 0; i < 10; ++i) {
span->SetTag(opentracing::string_view{key, 4}, "123");
++key[3];
}
}
tracer->Flush();
}
}
BENCHMARK_CAPTURE(BM_TaggedSpanReport, legacy_manual, "legacy_manual");
BENCHMARK_CAPTURE(BM_TaggedSpanReport, manual, "manual");

//--------------------------------------------------------------------------------------------------
// BM_LoggedSpanReport
//--------------------------------------------------------------------------------------------------
static void BM_LoggedSpanReport(benchmark::State& state,
const char* tracer_type) {
auto tracer = MakeTracer(tracer_type);
assert(tracer != nullptr);
for (auto _ : state) {
for (int i = 0; i < MaxBufferedSpans; ++i) {
auto span = tracer->StartSpan("abc123");
for (int i = 0; i < 10; ++i) {
span->Log({{"abc", 123}});
}
}
tracer->Flush();
}
}
BENCHMARK_CAPTURE(BM_LoggedSpanReport, legacy_manual, "legacy_manual");
BENCHMARK_CAPTURE(BM_LoggedSpanReport, manual, "manual");

//--------------------------------------------------------------------------------------------------
// BENCHMARK_MAIN
//--------------------------------------------------------------------------------------------------
BENCHMARK_MAIN();
8 changes: 8 additions & 0 deletions include/lightstep/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ lightstep_cc_library(
],
)

lightstep_cc_library(
name = "buffer_chain_interface",
hdrs = [
"buffer_chain.h",
],
)

lightstep_cc_library(
name = "transporter_interface",
hdrs = [
"transporter.h",
],
external_deps = [
":buffer_chain_interface",
"@com_google_protobuf//:protobuf",
"@io_opentracing_cpp//:opentracing",
],
Expand Down
42 changes: 42 additions & 0 deletions include/lightstep/buffer_chain.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include <cstddef>

namespace lightstep {
/**
* BufferChain provides an interface to access a chained sequence of
* contiguous memory buffers.
*/
class BufferChain {
public:
using FragmentCallback = bool (*)(void*, const void*, size_t);

virtual ~BufferChain() = default;

/**
* @return the number of fragments in chain
*/
virtual size_t num_fragments() const noexcept = 0;

/**
* @return the total number of bytes in all fragments
*/
virtual size_t num_bytes() const noexcept = 0;

/**
* Iterate over each fragment in the buffer chain
* @param callback the callback to call for each fragment
* @param context a pointer to pass to the callback.
*/
virtual bool ForEachFragment(FragmentCallback callback,
void* context) const = 0;

/**
* Copy out all the fragments into an area of contiguous memory
* @param data the location to start copying
* @param length the size of the buffer destination. Length must be at least
* num_bytes.
*/
void CopyOut(char* data, size_t length) const noexcept;
};
} // namespace lightstep
2 changes: 1 addition & 1 deletion include/lightstep/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ struct LightStepTracerOptions {
// default transporter is used.
//
// If `use_thread` is false, `transporter` should be derived from
// AsyncTransporter; otherwise, it must be derived from SyncTransporter.
// LegacyAsyncTransporter; otherwise, it must be derived from SyncTransporter.
std::unique_ptr<Transporter> transporter;

// `metrics_observer` can be optionally provided to track LightStep tracer
Expand Down
57 changes: 54 additions & 3 deletions include/lightstep/transporter.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#pragma once

#include <google/protobuf/message.h>
#include <lightstep/buffer_chain.h>
#include <opentracing/string_view.h>
#include <opentracing/util.h>

namespace lightstep {
// Transporter is the abstract base class for SyncTransporter and
// AsyncTransporter.
// LegacyAsyncTransporter.
class Transporter {
public:
Transporter() noexcept = default;
Expand Down Expand Up @@ -36,8 +37,10 @@ class SyncTransporter : public Transporter {
google::protobuf::Message& response) = 0;
};

// AsyncTransporter customizes how asynchronous tracing reports are sent.
class AsyncTransporter : public Transporter {
// LegacyAsyncTransporter customizes how asynchronous tracing reports are sent.
//
// Deprecated: Use AsyncTransporter
class LegacyAsyncTransporter : public Transporter {
public:
// Callback interface used by Send.
class Callback {
Expand Down Expand Up @@ -66,4 +69,52 @@ class AsyncTransporter : public Transporter {
google::protobuf::Message& response,
Callback& callback) = 0;
};

/**
* Provides a hook to customize how ReportRequests are transported.
*/
class AsyncTransporter : public Transporter {
public:
/**
* A Callback to be invoked after transporting a ReportRequest
*/
class Callback {
public:
Callback() noexcept = default;
Callback(const Callback&) noexcept = default;
Callback(Callback&&) noexcept = default;

virtual ~Callback() = default;

Callback& operator=(const Callback&) noexcept = default;
Callback& operator=(Callback&&) noexcept = default;

/**
* Call when a ReportRequest was successfully transported.
* @param message the ReportRequest
*/
virtual void OnSuccess(BufferChain& message) noexcept = 0;

/**
* Call when a ReportRequest not successfully transported.
* @param message the ReportRequest
*/
virtual void OnFailure(BufferChain& message) noexcept = 0;
};

/**
* Called when the tracer's span buffer is full. Implementors can either flush
* the pending spans early (so that we don't drop anything) or do nothing and
* let subsequent finished spans drop.
*/
virtual void OnSpanBufferFull() noexcept {}

/**
* Send a ReportRequest
* @param message a BufferChain representing the ReportRequest's serialization
* @param callback a Callback to be called after message is transported
*/
virtual void Send(std::unique_ptr<BufferChain>&& message,
Callback& callback) noexcept = 0;
};
} // namespace lightstep
Loading