forked from rnburn/zipkin-cpp-opentracing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: add sampling. current limits include...
* hardcoded sampling rate of 50% * sampling decision should only be performed at root or honour parent span decision * allow more than probabilistic strategy for sampling * pretty sure i've not understood the model, code tidying to come
- Loading branch information
Showing
8 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,5 @@ | |
*.app | ||
|
||
bazel-* | ||
|
||
.build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
#include <zipkin/opentracing.h> | ||
#include <opentracing/util.h> | ||
|
||
#include "propagation.h" | ||
#include "utility.h" | ||
#include <atomic> | ||
#include <cstring> | ||
#include <mutex> | ||
#include <unordered_map> | ||
#include <random> | ||
#include <zipkin/tracer.h> | ||
#include <zipkin/utility.h> | ||
#include <zipkin/zipkin_core_types.h> | ||
|
@@ -156,7 +158,7 @@ class OtSpan : public ot::Span { | |
parent_span_context->baggage_mutex_}; | ||
auto baggage = parent_span_context->baggage_; | ||
span_context_ = | ||
OtSpanContext{zipkin::SpanContext{*span_}, std::move(baggage)}; | ||
OtSpanContext{zipkin::SpanContext{*span_}, std::move(baggage)}; | ||
} else { | ||
span_context_ = OtSpanContext{zipkin::SpanContext{*span_}}; | ||
} | ||
|
@@ -277,11 +279,28 @@ class OtTracer : public ot::Tracer, | |
StartSpanWithOptions(string_view operation_name, | ||
const ot::StartSpanOptions &options) const | ||
noexcept override { | ||
|
||
// Create the core zipkin span. | ||
SpanPtr span{new zipkin::Span{}}; | ||
span->setName(operation_name); | ||
span->setTracer(tracer_.get()); | ||
|
||
// TODO | ||
// * sampling rate should be arg-based | ||
// * sampling should probably be extracted into a sampler to allow | ||
// different strategies | ||
// * we should be guarding this to set sampling only when its a | ||
// root span | ||
auto value = RandomUtil::generateId(); | ||
auto max = std::numeric_limits<uint64_t>::max(); | ||
long double sampling_rate = 0.5; | ||
auto boundary = sampling_rate * max; // be false 50% of the time | ||
auto samplingBoundary = static_cast<uint64_t>(boundary); | ||
|
||
if (value > samplingBoundary) { | ||
span->setSampled(true); | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
rnburn
|
||
|
||
Endpoint endpoint{tracer_->serviceName(), tracer_->address()}; | ||
|
||
// Add a binary annotation for the serviceName. | ||
|
@@ -329,7 +348,7 @@ class OtTracer : public ot::Tracer, | |
|
||
private: | ||
TracerPtr tracer_; | ||
|
||
template <class Carrier> | ||
expected<void> InjectImpl(const ot::SpanContext &sc, Carrier &writer) const | ||
try { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Could you use double for sample rate instead of float. It's more common and otherwise something like options.sample_rate = .7 will trigger a warning because of loss of precision.