Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ set(LIGHTSTEP_SRCS src/utility.cpp
src/manual_recorder.cpp
src/auto_recorder.cpp
src/lightstep_span_context.cpp
src/lightstep_immutable_span_context.cpp
src/lightstep_span.cpp
src/lightstep_tracer_impl.cpp
src/lightstep_tracer_factory.cpp
Expand Down
14 changes: 14 additions & 0 deletions benchmark/span_operations_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ static void BM_SpanCreation(benchmark::State& state) {
}
BENCHMARK(BM_SpanCreation);

static void BM_SpanCreationWithParent(benchmark::State& state) {
auto tracer = MakeTracer();
assert(tracer != nullptr);
auto parent_span = tracer->StartSpan("parent");
parent_span->Finish();
opentracing::StartSpanOptions options;
options.references.emplace_back(opentracing::SpanReferenceType::ChildOfRef,
&parent_span->context());
for (auto _ : state) {
auto span = tracer->StartSpanWithOptions("abc123", options);
}
}
BENCHMARK(BM_SpanCreationWithParent);

static void BM_SpanSetTag1(benchmark::State& state) {
auto tracer = MakeTracer();
assert(tracer != nullptr);
Expand Down
4 changes: 2 additions & 2 deletions src/auto_recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ AutoRecorder::~AutoRecorder() {
//------------------------------------------------------------------------------
// RecordSpan
//------------------------------------------------------------------------------
void AutoRecorder::RecordSpan(collector::Span&& span) noexcept try {
void AutoRecorder::RecordSpan(const collector::Span& span) noexcept try {
std::lock_guard<std::mutex> lock_guard{write_mutex_};
if (builder_.num_pending_spans() >= max_buffered_spans_snapshot_ ||
write_exit_) {
dropped_spans_++;
options_.metrics_observer->OnSpansDropped(1);
return;
}
builder_.AddSpan(std::move(span));
builder_.AddSpan(span);
if (builder_.num_pending_spans() >= max_buffered_spans_snapshot_) {
write_cond_->NotifyAll();
}
Expand Down
4 changes: 2 additions & 2 deletions src/auto_recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace lightstep {
// AutoRecorder buffers spans finished by a tracer and sends them over to
// the provided SyncTransporter. It uses an internal thread to regularly send
// the reports according to the rate specified by LightStepTracerOptions.
class AutoRecorder : public Recorder {
class AutoRecorder final : public Recorder {
public:
AutoRecorder(Logger& logger, LightStepTracerOptions&& options,
std::unique_ptr<SyncTransporter>&& transporter);
Expand All @@ -32,7 +32,7 @@ class AutoRecorder : public Recorder {

~AutoRecorder() override;

void RecordSpan(collector::Span&& span) noexcept override;
void RecordSpan(const collector::Span& span) noexcept override;

bool FlushWithTimeout(
std::chrono::system_clock::duration timeout) noexcept override;
Expand Down
37 changes: 37 additions & 0 deletions src/lightstep_immutable_span_context.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "lightstep_immutable_span_context.h"

namespace lightstep {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
LightStepImmutableSpanContext::LightStepImmutableSpanContext(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would be slightly inclined to remove the LightStep prefix since you're in namespace lightstep.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a little redundant.

I used names like LightStepSpan, LightStepTracer, etc to keep them from clashing with the opentracing names in case you happen to use both namespaces; then chose this name to be consistent. But maybe I should rename them all.

I'll merge in as is for now and maybe make a separate PR to rename everything.

uint64_t trace_id, uint64_t span_id, bool sampled,
const std::unordered_map<std::string, std::string>& baggage)
: trace_id_{trace_id}, span_id_{span_id}, sampled_{sampled} {
for (auto& baggage_item : baggage) {
baggage_.insert(
BaggageMap::value_type(baggage_item.first, baggage_item.second));
}
}

LightStepImmutableSpanContext::LightStepImmutableSpanContext(
uint64_t trace_id, uint64_t span_id, bool sampled,
BaggageMap&& baggage) noexcept
: trace_id_{trace_id},
span_id_{span_id},
sampled_{sampled},
baggage_{std::move(baggage)} {}

//------------------------------------------------------------------------------
// ForeachBaggageItem
//------------------------------------------------------------------------------
void LightStepImmutableSpanContext::ForeachBaggageItem(
std::function<bool(const std::string& key, const std::string& value)> f)
const {
for (const auto& baggage_item : baggage_) {
if (!f(baggage_item.first, baggage_item.second)) {
return;
}
}
}
} // namespace lightstep
56 changes: 56 additions & 0 deletions src/lightstep_immutable_span_context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#pragma once

#include "lightstep_span_context.h"

namespace lightstep {
class LightStepImmutableSpanContext final : public LightStepSpanContext {
public:
LightStepImmutableSpanContext(
uint64_t trace_id, uint64_t span_id, bool sampled,
const std::unordered_map<std::string, std::string>& baggage);

LightStepImmutableSpanContext(uint64_t trace_id, uint64_t span_id,
bool sampled, BaggageMap&& baggage) noexcept;

uint64_t trace_id() const noexcept override { return trace_id_; }

uint64_t span_id() const noexcept override { return span_id_; }

bool sampled() const noexcept override { return sampled_; }

void ForeachBaggageItem(
std::function<bool(const std::string& key, const std::string& value)> f)
const override;

opentracing::expected<void> Inject(
const PropagationOptions& propagation_options,
std::ostream& writer) const override {
return this->InjectImpl(propagation_options, writer);
}

opentracing::expected<void> Inject(
const PropagationOptions& propagation_options,
const opentracing::TextMapWriter& writer) const override {
return this->InjectImpl(propagation_options, writer);
}

opentracing::expected<void> Inject(
const PropagationOptions& propagation_options,
const opentracing::HTTPHeadersWriter& writer) const override {
return this->InjectImpl(propagation_options, writer);
}

private:
uint64_t trace_id_;
uint64_t span_id_;
bool sampled_;
BaggageMap baggage_;

template <class Carrier>
opentracing::expected<void> InjectImpl(
const PropagationOptions& propagation_options, Carrier& writer) const {
return InjectSpanContext(propagation_options, writer, trace_id_, span_id_,
sampled_, baggage_);
}
};
} // namespace lightstep
Loading