From d3a19316dab1de7627a03fb6192b4521169ca3ec Mon Sep 17 00:00:00 2001 From: TianlinZhao Date: Thu, 30 Jul 2020 14:02:14 -0400 Subject: [PATCH] tracer workaround --- api/include/opentelemetry/trace/span.h | 2 +- .../opentelemetry/trace/span_context.h | 5 - api/include/opentelemetry/trace/tracer.h | 108 +++++++++--------- 3 files changed, 55 insertions(+), 60 deletions(-) diff --git a/api/include/opentelemetry/trace/span.h b/api/include/opentelemetry/trace/span.h index 3a37e97ca5..9de9ad7f3a 100644 --- a/api/include/opentelemetry/trace/span.h +++ b/api/include/opentelemetry/trace/span.h @@ -2,6 +2,7 @@ #include +#include "opentelemetry/trace/tracer.h" #include "opentelemetry/common/attribute_value.h" #include "opentelemetry/core/timestamp.h" #include "opentelemetry/nostd/span.h" @@ -9,7 +10,6 @@ #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/trace/canonical_code.h" #include "opentelemetry/trace/key_value_iterable_view.h" -#include "opentelemetry/trace/tracer.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/api/include/opentelemetry/trace/span_context.h b/api/include/opentelemetry/trace/span_context.h index b55597f3a9..5070f7e92c 100644 --- a/api/include/opentelemetry/trace/span_context.h +++ b/api/include/opentelemetry/trace/span_context.h @@ -19,7 +19,6 @@ #include "opentelemetry/trace/trace_flags.h" #include "opentelemetry/trace/trace_id.h" #include "opentelemetry/trace/trace_state.h" -#include "opentelemetry/trace/span.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace trace @@ -72,10 +71,6 @@ class SpanContext final static SpanContext GetInvalid() { return SpanContext(); } - nostd::unique_ptr test() { - return nostd::unique_ptr(new Span()); - } - private: TraceId trace_id_; SpanId span_id_; diff --git a/api/include/opentelemetry/trace/tracer.h b/api/include/opentelemetry/trace/tracer.h index a117b4db41..7927a2702e 100644 --- a/api/include/opentelemetry/trace/tracer.h +++ b/api/include/opentelemetry/trace/tracer.h @@ -28,60 +28,60 @@ class Tracer * Attributes will be processed in order, previous attributes with the same * key will be overwritten. */ -// virtual nostd::unique_ptr StartSpan(nostd::string_view name, -// const KeyValueIterable &attributes, -// const StartSpanOptions &options = {}) noexcept = 0; -// -// nostd::unique_ptr StartSpan(nostd::string_view name, -// const StartSpanOptions &options = {}) noexcept -// { -// return this->StartSpan(name, {}, options); -// } -// -// template ::value> * = nullptr> -// nostd::unique_ptr StartSpan(nostd::string_view name, -// const T &attributes, -// const StartSpanOptions &options = {}) noexcept -// { -// return this->StartSpan(name, KeyValueIterableView(attributes), options); -// } -// -// nostd::unique_ptr StartSpan( -// nostd::string_view name, -// std::initializer_list> attributes, -// const StartSpanOptions &options = {}) noexcept -// { -// return this->StartSpan(name, -// nostd::span>{ -// attributes.begin(), attributes.end()}, -// options); -// } -// -// /** -// * Force any buffered spans to flush. -// * @param timeout to complete the flush -// */ -// 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; -// -// /** -// * ForceFlush any buffered spans and stop reporting spans. -// * @param timeout to complete the flush -// */ -// 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; + virtual nostd::unique_ptr StartSpan(nostd::string_view name, + const KeyValueIterable &attributes, + const StartSpanOptions &options = {}) noexcept = 0; + + nostd::unique_ptr StartSpan(nostd::string_view name, + const StartSpanOptions &options = {}) noexcept + { + return this->StartSpan(name, {}, options); + } + + template ::value> * = nullptr> + nostd::unique_ptr StartSpan(nostd::string_view name, + const T &attributes, + const StartSpanOptions &options = {}) noexcept + { + return this->StartSpan(name, KeyValueIterableView(attributes), options); + } + + nostd::unique_ptr StartSpan( + nostd::string_view name, + std::initializer_list> attributes, + const StartSpanOptions &options = {}) noexcept + { + return this->StartSpan(name, + nostd::span>{ + attributes.begin(), attributes.end()}, + options); + } + + /** + * Force any buffered spans to flush. + * @param timeout to complete the flush + */ + 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; + + /** + * ForceFlush any buffered spans and stop reporting spans. + * @param timeout to complete the flush + */ + 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 \ No newline at end of file