Skip to content

Commit

Permalink
Merge pull request #10 from Tianlin-Zhao/origin/propagators
Browse files Browse the repository at this point in the history
Origin/propagators
  • Loading branch information
Tianlin-Zhao authored Jul 30, 2020
2 parents b09a788 + c88cc14 commit 2f081d8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ static const nostd::string_view kTraceParent = "traceparent";
static const nostd::string_view kTraceState = "tracestate";
static const int kVersionBytes = 2;
static const int kTraceIdBytes = 32;
static const int kParentIdBytes = 16;
static const int kSpanIdBytes = 16;
static const int kTraceFlagBytes = 2;
static const int kTraceDelimiterBytes = 3;
static const int kHeaderSize = kVersionBytes + kTraceIdBytes + kParentIdBytes + kTraceFlagBytes + kTraceDelimiterBytes;
static const int kHeaderSize = kVersionBytes + kTraceIdBytes + kSpanIdBytes + kTraceFlagBytes + kTraceDelimiterBytes;
static const int kTraceStateMaxMembers = 32;
static const int kHeaderElementLengths[4] = {2,32,16,2};

// The HttpTraceContext provides methods to extract and inject
// context into headers of HTTP requests with traces.
// Example:
Expand Down
135 changes: 66 additions & 69 deletions api/include/opentelemetry/trace/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

#include <chrono>

class Span;
struct StartSpanOptions;

OPENTELEMETRY_BEGIN_NAMESPACE
namespace trace
{
Expand All @@ -16,78 +19,72 @@ namespace trace
* This class provides methods for manipulating the context, creating spans, and controlling spans'
* lifecycles.
*/
class Span;

struct StartSpanOptions;

class Tracer
{
public:
Tracer() = default;
//public:
// virtual ~Tracer() = default;
// /**
// * Starts a span.
// *
// * Optionally sets attributes at Span creation from the given key/value pairs.
// *
// * Attributes will be processed in order, previous attributes with the same
// * key will be overwritten.
// */
// virtual nostd::unique_ptr<Span> StartSpan(nostd::string_view name,
// const KeyValueIterable &attributes,
// const StartSpanOptions &options = {}) noexcept = 0;
//
// nostd::unique_ptr<Span> StartSpan(nostd::string_view name,
// const StartSpanOptions &options = {}) noexcept
// {
// return this->StartSpan(name, {}, options);
// }
//
// template <class T, nostd::enable_if_t<detail::is_key_value_iterable<T>::value> * = nullptr>
// nostd::unique_ptr<Span> StartSpan(nostd::string_view name,
// const T &attributes,
// const StartSpanOptions &options = {}) noexcept
// {
// return this->StartSpan(name, KeyValueIterableView<T>(attributes), options);
// }
//
// nostd::unique_ptr<Span> StartSpan(
// nostd::string_view name,
// std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
// const StartSpanOptions &options = {}) noexcept
// {
// return this->StartSpan(name,
// nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
// attributes.begin(), attributes.end()},
// options);
// }
//
// /**
// * Force any buffered spans to flush.
// * @param timeout to complete the flush
// */
// template <class Rep, class Period>
// void ForceFlush(std::chrono::duration<Rep, Period> timeout) noexcept
// {
// this->ForceFlushWithMicroseconds(
// static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(timeout)));
// }
//
// virtual void ForceFlushWithMicroseconds(uint64_t timeout) noexcept = 0;
//
// /**
// * ForceFlush any buffered spans and stop reporting spans.
// * @param timeout to complete the flush
// */
// template <class Rep, class Period>
// void Close(std::chrono::duration<Rep, Period> timeout) noexcept
// {
// this->CloseWithMicroseconds(
// static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(timeout)));
// }
//
// virtual void CloseWithMicroseconds(uint64_t timeout) noexcept = 0;
virtual ~Tracer() = default;
/**
* Starts a span.
*
* Optionally sets attributes at Span creation from the given key/value pairs.
*
* Attributes will be processed in order, previous attributes with the same
* key will be overwritten.
*/
virtual nostd::unique_ptr<Span> StartSpan(nostd::string_view name,
const KeyValueIterable &attributes,
const StartSpanOptions &options = {}) noexcept = 0;

nostd::unique_ptr<Span> StartSpan(nostd::string_view name,
const StartSpanOptions &options = {}) noexcept
{
return this->StartSpan(name, {}, options);
}

template <class T, nostd::enable_if_t<detail::is_key_value_iterable<T>::value> * = nullptr>
nostd::unique_ptr<Span> StartSpan(nostd::string_view name,
const T &attributes,
const StartSpanOptions &options = {}) noexcept
{
return this->StartSpan(name, KeyValueIterableView<T>(attributes), options);
}

nostd::unique_ptr<Span> StartSpan(
nostd::string_view name,
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
const StartSpanOptions &options = {}) noexcept
{
return this->StartSpan(name,
nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
attributes.begin(), attributes.end()},
options);
}

/**
* Force any buffered spans to flush.
* @param timeout to complete the flush
*/
template <class Rep, class Period>
void ForceFlush(std::chrono::duration<Rep, Period> timeout) noexcept
{
this->ForceFlushWithMicroseconds(
static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(timeout)));
}

virtual void ForceFlushWithMicroseconds(uint64_t timeout) noexcept = 0;

/**
* ForceFlush any buffered spans and stop reporting spans.
* @param timeout to complete the flush
*/
template <class Rep, class Period>
void Close(std::chrono::duration<Rep, Period> timeout) noexcept
{
this->CloseWithMicroseconds(
static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(timeout)));
}

virtual void CloseWithMicroseconds(uint64_t timeout) noexcept = 0;
};
} // namespace trace
OPENTELEMETRY_END_NAMESPACE

0 comments on commit 2f081d8

Please sign in to comment.