Line data Source code
1 : #pragma once 2 : 3 : #include "envoy/server/tracer_config.h" 4 : #include "envoy/singleton/instance.h" 5 : #include "envoy/tracing/tracer_manager.h" 6 : 7 : #include "source/common/common/logger.h" 8 : #include "source/common/tracing/tracer_config_impl.h" 9 : #include "source/common/tracing/tracer_impl.h" 10 : 11 : namespace Envoy { 12 : namespace Tracing { 13 : 14 : /** 15 : * TracerManager implementation that manages the tracers. This should be used as a singleton except 16 : * in tests. 17 : */ 18 : class TracerManagerImpl : public TracerManager, 19 : public Singleton::Instance, 20 : Logger::Loggable<Logger::Id::tracing> { 21 : public: 22 : TracerManagerImpl(Server::Configuration::TracerFactoryContextPtr factory_context); 23 : 24 : // TracerManager 25 : TracerSharedPtr getOrCreateTracer(const envoy::config::trace::v3::Tracing_Http* config) override; 26 : 27 : // Take a peek into the cache of HttpTracers. This should only be used in tests. 28 0 : const absl::flat_hash_map<std::size_t, std::weak_ptr<Tracer>>& peekCachedTracersForTest() const { 29 0 : return tracers_; 30 0 : } 31 : 32 : static std::shared_ptr<TracerManager> singleton(Server::Configuration::FactoryContext& context); 33 : 34 : private: 35 : void removeExpiredCacheEntries(); 36 : 37 : Server::Configuration::TracerFactoryContextPtr factory_context_; 38 : const TracerSharedPtr null_tracer_{std::make_shared<Tracing::NullTracer>()}; 39 : 40 : // HttpTracers indexed by the hash of their configuration. 41 : absl::flat_hash_map<std::size_t, std::weak_ptr<Tracer>> tracers_; 42 : }; 43 : 44 : } // namespace Tracing 45 : } // namespace Envoy