.. _program_listing_file_include_opentelemetry_trace_tracer.h: Program Listing for File tracer.h ================================= |exhale_lsh| :ref:`Return to documentation for file ` (``include/opentelemetry/trace/tracer.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/trace/default_span.h" #include "opentelemetry/trace/scope.h" #include "opentelemetry/trace/span.h" #include "opentelemetry/trace/span_context_kv_iterable_view.h" #include "opentelemetry/version.h" #include OPENTELEMETRY_BEGIN_NAMESPACE namespace trace { class Tracer { public: virtual ~Tracer() = default; virtual nostd::shared_ptr StartSpan(nostd::string_view name, const common::KeyValueIterable &attributes, const SpanContextKeyValueIterable &links, const StartSpanOptions &options = {}) noexcept = 0; nostd::shared_ptr StartSpan(nostd::string_view name, const StartSpanOptions &options = {}) noexcept { return this->StartSpan(name, {}, {}, options); } template ::value> * = nullptr> nostd::shared_ptr StartSpan(nostd::string_view name, const T &attributes, const StartSpanOptions &options = {}) noexcept { return this->StartSpan(name, attributes, {}, options); } nostd::shared_ptr StartSpan(nostd::string_view name, const common::KeyValueIterable &attributes, const StartSpanOptions &options = {}) noexcept { return this->StartSpan(name, attributes, NullSpanContext(), options); } template ::value> * = nullptr, nostd::enable_if_t::value> * = nullptr> nostd::shared_ptr StartSpan(nostd::string_view name, const T &attributes, const U &links, const StartSpanOptions &options = {}) noexcept { return this->StartSpan(name, common::KeyValueIterableView(attributes), SpanContextKeyValueIterableView(links), options); } nostd::shared_ptr StartSpan( nostd::string_view name, std::initializer_list> attributes, const StartSpanOptions &options = {}) noexcept { return this->StartSpan(name, attributes, {}, options); } template ::value> * = nullptr> nostd::shared_ptr StartSpan( nostd::string_view name, const T &attributes, std::initializer_list< std::pair>>> links, const StartSpanOptions &options = {}) noexcept { return this->StartSpan( name, attributes, nostd::span>>>{ links.begin(), links.end()}, options); } template ::value> * = nullptr> nostd::shared_ptr StartSpan( nostd::string_view name, std::initializer_list> attributes, const T &links, const StartSpanOptions &options = {}) noexcept { return this->StartSpan(name, nostd::span>{ attributes.begin(), attributes.end()}, links, options); } nostd::shared_ptr StartSpan( nostd::string_view name, std::initializer_list> attributes, std::initializer_list< std::pair>>> links, const StartSpanOptions &options = {}) noexcept { return this->StartSpan( name, nostd::span>{attributes.begin(), attributes.end()}, nostd::span>>>{ links.begin(), links.end()}, options); } nostd::unique_ptr WithActiveSpan(nostd::shared_ptr &span) noexcept { return nostd::unique_ptr(new Scope{span}); } nostd::shared_ptr GetCurrentSpan() noexcept { context::ContextValue active_span = context::RuntimeContext::GetValue(kSpanKey); if (nostd::holds_alternative>(active_span)) { return nostd::get>(active_span); } else { return nostd::shared_ptr(new DefaultSpan(SpanContext::GetInvalid())); } } template void ForceFlush(std::chrono::duration timeout) noexcept { this->ForceFlushWithMicroseconds( static_cast(std::chrono::duration_cast(timeout))); } virtual void ForceFlushWithMicroseconds(uint64_t timeout) noexcept = 0; template void Close(std::chrono::duration timeout) noexcept { this->CloseWithMicroseconds( static_cast(std::chrono::duration_cast(timeout))); } virtual void CloseWithMicroseconds(uint64_t timeout) noexcept = 0; }; } // namespace trace OPENTELEMETRY_END_NAMESPACE