Skip to content

Commit

Permalink
minor update: move TracerManager registration to common/tracing (#25420)
Browse files Browse the repository at this point in the history
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
  • Loading branch information
code authored Feb 9, 2023
1 parent 455409c commit c51a400
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
3 changes: 2 additions & 1 deletion source/common/tracing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ envoy_cc_library(
"tracer_manager_impl.h",
],
deps = [
":tracer_config_lib",
"//envoy/server:tracer_config_interface",
"//envoy/singleton:instance_interface",
"//envoy/tracing:tracer_manager_interface",
"//source/common/common:minimal_logger_lib",
"//source/common/config:utility_lib",
"//source/common/tracing:http_tracer_lib",
"//source/common/tracing:tracer_lib",
],
)

Expand Down
3 changes: 3 additions & 0 deletions source/common/tracing/tracer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ void TracerUtility::finalizeSpan(Span& span, const TraceContext& trace_context,
it.second->applySpan(span, ctx);
}
}

// Finish the span.
span.finishSpan();
}

TracerImpl::TracerImpl(DriverSharedPtr driver, const LocalInfo::LocalInfo& local_info)
Expand Down
12 changes: 12 additions & 0 deletions source/common/tracing/tracer_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Envoy {
namespace Tracing {

SINGLETON_MANAGER_REGISTRATION(tracer_manager);

TracerManagerImpl::TracerManagerImpl(Server::Configuration::TracerFactoryContextPtr factory_context)
: factory_context_(std::move(factory_context)) {}

Expand Down Expand Up @@ -59,5 +61,15 @@ void TracerManagerImpl::removeExpiredCacheEntries() {
});
}

std::shared_ptr<TracerManager>
TracerManagerImpl::singleton(Server::Configuration::FactoryContext& context) {
return context.singletonManager().getTyped<Tracing::TracerManagerImpl>(
SINGLETON_MANAGER_REGISTERED_NAME(tracer_manager), [&context] {
return std::make_shared<Tracing::TracerManagerImpl>(
std::make_unique<Tracing::TracerFactoryContextImpl>(
context.getServerFactoryContext(), context.messageValidationVisitor()));
});
}

} // namespace Tracing
} // namespace Envoy
7 changes: 7 additions & 0 deletions source/common/tracing/tracer_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
#include "envoy/tracing/tracer_manager.h"

#include "source/common/common/logger.h"
#include "source/common/tracing/tracer_config_impl.h"
#include "source/common/tracing/tracer_impl.h"

namespace Envoy {
namespace Tracing {

/**
* TracerManager implementation that manages the tracers. This should be used as a singleton except
* in tests.
*/
class TracerManagerImpl : public TracerManager,
public Singleton::Instance,
Logger::Loggable<Logger::Id::tracing> {
Expand All @@ -24,6 +29,8 @@ class TracerManagerImpl : public TracerManager,
return tracers_;
}

static std::shared_ptr<TracerManager> singleton(Server::Configuration::FactoryContext& context);

private:
void removeExpiredCacheEntries();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ Http::HeaderValidatorFactoryPtr createHeaderValidatorFactory(
SINGLETON_MANAGER_REGISTRATION(date_provider);
SINGLETON_MANAGER_REGISTRATION(route_config_provider_manager);
SINGLETON_MANAGER_REGISTRATION(scoped_routes_config_provider_manager);
SINGLETON_MANAGER_REGISTRATION(tracer_manager);

Utility::Singletons Utility::createSingletons(Server::Configuration::FactoryContext& context) {
std::shared_ptr<Http::TlsCachingDateProviderImpl> date_provider =
Expand All @@ -215,12 +214,7 @@ Utility::Singletons Utility::createSingletons(Server::Configuration::FactoryCont
context.admin(), *route_config_provider_manager);
});

auto tracer_manager = context.singletonManager().getTyped<Tracing::TracerManagerImpl>(
SINGLETON_MANAGER_REGISTERED_NAME(tracer_manager), [&context] {
return std::make_shared<Tracing::TracerManagerImpl>(
std::make_unique<Tracing::TracerFactoryContextImpl>(
context.getServerFactoryContext(), context.messageValidationVisitor()));
});
auto tracer_manager = Tracing::TracerManagerImpl::singleton(context);

std::shared_ptr<Http::DownstreamFilterConfigProviderManager> filter_config_provider_manager =
Http::FilterChainUtility::createSingletonDownstreamFilterConfigProviderManager(
Expand Down

0 comments on commit c51a400

Please sign in to comment.