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

Commit

Permalink
Fix usage of propagation headers config
Browse files Browse the repository at this point in the history
Signed-off-by: Isaac Hier <[email protected]>
  • Loading branch information
isaachier committed Apr 27, 2018
1 parent 359979c commit 321a365
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/jaegertracing/Tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ class Tracer : public opentracing::Tracer,
config.sampler().makeSampler(serviceName, *logger, *metrics));
std::shared_ptr<reporters::Reporter> reporter(
config.reporter().makeReporter(serviceName, *logger, *metrics));
return std::shared_ptr<Tracer>(new Tracer(
serviceName, sampler, reporter, logger, metrics, options));
return std::shared_ptr<Tracer>(new Tracer(serviceName,
sampler,
reporter,
logger,
metrics,
config.headers(),
options));
}

~Tracer() { Close(); }
Expand Down Expand Up @@ -217,6 +222,7 @@ class Tracer : public opentracing::Tracer,
const std::shared_ptr<reporters::Reporter>& reporter,
const std::shared_ptr<logging::Logger>& logger,
const std::shared_ptr<metrics::Metrics>& metrics,
const propagation::HeadersConfig& headersConfig,
int options)
: _serviceName(serviceName)
, _hostIPv4(net::IPAddress::localIP(AF_INET))
Expand All @@ -225,9 +231,9 @@ class Tracer : public opentracing::Tracer,
, _metrics(metrics)
, _logger(logger)
, _randomNumberGenerator()
, _textPropagator()
, _httpHeaderPropagator()
, _binaryPropagator()
, _textPropagator(headersConfig, _metrics)
, _httpHeaderPropagator(headersConfig, _metrics)
, _binaryPropagator(_metrics)
, _tags()
, _restrictionManager(new baggage::DefaultRestrictionManager(0))
, _baggageSetter(*_restrictionManager, *_metrics)
Expand Down
20 changes: 18 additions & 2 deletions src/jaegertracing/propagation/Propagator.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ class BinaryPropagator : public Extractor<std::istream&>,
public:
using StrMap = SpanContext::StrMap;

explicit BinaryPropagator(const std::shared_ptr<metrics::Metrics>& metrics =
std::shared_ptr<metrics::Metrics>())
: _metrics(metrics == nullptr ? metrics::Metrics::makeNullMetrics()
: metrics)
{
}

void inject(const SpanContext& ctx, std::ostream& out) const override
{
writeBinary(out, ctx.traceID().high());
Expand Down Expand Up @@ -251,11 +258,17 @@ class BinaryPropagator : public Extractor<std::istream&>,
for (auto i = static_cast<uint32_t>(0); i < numBaggageItems; ++i) {
const auto keyLength = readBinary<uint32_t>(in);
std::string key(keyLength, '\0');
in.read(&key[0], keyLength);
if (!in.read(&key[0], keyLength)) {
_metrics->decodingErrors().inc(1);
return SpanContext();
}

const auto valueLength = readBinary<uint32_t>(in);
std::string value(valueLength, '\0');
in.read(&value[0], valueLength);
if (!in.read(&value[0], valueLength)) {
_metrics->decodingErrors().inc(1);
return SpanContext();
}

baggage[key] = value;
}
Expand Down Expand Up @@ -294,6 +307,9 @@ class BinaryPropagator : public Extractor<std::istream&>,
}
return platform::endian::fromBigEndian(value);
}

private:
std::shared_ptr<metrics::Metrics> _metrics;
};

} // namespace propagation
Expand Down

0 comments on commit 321a365

Please sign in to comment.