diff --git a/src/jaegertracing/Tracer.h b/src/jaegertracing/Tracer.h index e077c817..d1d5d953 100644 --- a/src/jaegertracing/Tracer.h +++ b/src/jaegertracing/Tracer.h @@ -98,8 +98,13 @@ class Tracer : public opentracing::Tracer, config.sampler().makeSampler(serviceName, *logger, *metrics)); std::shared_ptr reporter( config.reporter().makeReporter(serviceName, *logger, *metrics)); - return std::shared_ptr(new Tracer( - serviceName, sampler, reporter, logger, metrics, options)); + return std::shared_ptr(new Tracer(serviceName, + sampler, + reporter, + logger, + metrics, + config.headers(), + options)); } ~Tracer() { Close(); } @@ -217,6 +222,7 @@ class Tracer : public opentracing::Tracer, const std::shared_ptr& reporter, const std::shared_ptr& logger, const std::shared_ptr& metrics, + const propagation::HeadersConfig& headersConfig, int options) : _serviceName(serviceName) , _hostIPv4(net::IPAddress::localIP(AF_INET)) @@ -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) diff --git a/src/jaegertracing/propagation/Propagator.h b/src/jaegertracing/propagation/Propagator.h index 2433e5d2..ec463678 100644 --- a/src/jaegertracing/propagation/Propagator.h +++ b/src/jaegertracing/propagation/Propagator.h @@ -212,6 +212,13 @@ class BinaryPropagator : public Extractor, public: using StrMap = SpanContext::StrMap; + explicit BinaryPropagator(const std::shared_ptr& metrics = + std::shared_ptr()) + : _metrics(metrics == nullptr ? metrics::Metrics::makeNullMetrics() + : metrics) + { + } + void inject(const SpanContext& ctx, std::ostream& out) const override { writeBinary(out, ctx.traceID().high()); @@ -251,11 +258,17 @@ class BinaryPropagator : public Extractor, for (auto i = static_cast(0); i < numBaggageItems; ++i) { const auto keyLength = readBinary(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(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; } @@ -294,6 +307,9 @@ class BinaryPropagator : public Extractor, } return platform::endian::fromBigEndian(value); } + + private: + std::shared_ptr _metrics; }; } // namespace propagation