Skip to content

Commit

Permalink
make sampling decision for root span
Browse files Browse the repository at this point in the history
* inspired by the jaeger module we check whether any of the references are
  ChildOf to identify a parent span.
  • Loading branch information
pingles committed May 17, 2018
1 parent 3a59143 commit d7628b2
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions zipkin_opentracing/src/opentracing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,11 @@ class OtTracer : public ot::Tracer,
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
ProbabilisticSampler s(0.5);
if (s.ShouldSample()) {
span->setSampled(true);
if (!hasParent(options)) {
ProbabilisticSampler s(0.5);
if (s.ShouldSample()) {
span->setSampled(true);
}
}

Endpoint endpoint{tracer_->serviceName(), tracer_->address()};
Expand Down Expand Up @@ -345,6 +341,15 @@ class OtTracer : public ot::Tracer,
private:
TracerPtr tracer_;

bool hasParent(const ot::StartSpanOptions &options) const {
for (auto ref : options.references) {
if (ref.first == ot::SpanReferenceType::ChildOfRef) {
return true;
}
}
return false;
}

template <class Carrier>
expected<void> InjectImpl(const ot::SpanContext &sc, Carrier &writer) const
try {
Expand Down

0 comments on commit d7628b2

Please sign in to comment.