Line data Source code
1 : #pragma once 2 : 3 : #include <memory> 4 : 5 : #include "envoy/common/pure.h" 6 : #include "envoy/common/random_generator.h" 7 : 8 : #include "source/common/common/macros.h" 9 : 10 : #include "absl/strings/string_view.h" 11 : 12 : namespace Envoy { 13 : namespace Extensions { 14 : namespace Tracers { 15 : namespace XRay { 16 : 17 : struct SamplingRequest { 18 : absl::string_view host_; 19 : absl::string_view http_method_; 20 : absl::string_view http_url_; 21 : }; 22 : 23 : /** 24 : * Strategy provides an interface for implementing trace sampling strategies. 25 : */ 26 : class SamplingStrategy { 27 : public: 28 0 : explicit SamplingStrategy(Random::RandomGenerator& rng) : rng_(rng) {} 29 0 : virtual ~SamplingStrategy() = default; 30 : 31 : /** 32 : * sampleRequest determines if the given request should be traced or not. 33 : * Implementation _must_ be thread-safe. 34 : */ 35 : virtual bool shouldTrace(const SamplingRequest& sampling_request) PURE; 36 : 37 : protected: 38 0 : uint64_t random() const { return rng_.random(); } 39 : 40 : private: 41 : Random::RandomGenerator& rng_; 42 : }; 43 : 44 : using SamplingStrategyPtr = std::unique_ptr<SamplingStrategy>; 45 : 46 : } // namespace XRay 47 : } // namespace Tracers 48 : } // namespace Extensions 49 : } // namespace Envoy