.. _program_listing_file_include_opentelemetry_trace_provider.h: Program Listing for File provider.h =================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/opentelemetry/trace/provider.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include #include "opentelemetry/common/spin_lock_mutex.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/trace/noop.h" #include "opentelemetry/trace/tracer_provider.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace trace { class Provider { public: static nostd::shared_ptr GetTracerProvider() noexcept { std::lock_guard guard(GetLock()); return nostd::shared_ptr(GetProvider()); } static void SetTracerProvider(nostd::shared_ptr tp) noexcept { std::lock_guard guard(GetLock()); GetProvider() = tp; } private: static nostd::shared_ptr &GetProvider() noexcept { static nostd::shared_ptr provider(new NoopTracerProvider); return provider; } static common::SpinLockMutex &GetLock() noexcept { static common::SpinLockMutex lock; return lock; } }; } // namespace trace OPENTELEMETRY_END_NAMESPACE