Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Origin/propagators #10

Merged
merged 3 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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