Skip to content

Commit

Permalink
initial files added (not compiling)
Browse files Browse the repository at this point in the history
  • Loading branch information
mishal23 committed Oct 25, 2020
1 parent 94077f5 commit e2cda38
Show file tree
Hide file tree
Showing 12 changed files with 1,828 additions and 0 deletions.
409 changes: 409 additions & 0 deletions api/include/opentelemetry/event/UUID.hpp

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions api/include/opentelemetry/trace/key_value_iterable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/nostd/function_ref.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace trace
{
/**
* Supports internal iteration over a collection of key-value pairs.
*/
class KeyValueIterable
{
public:
virtual ~KeyValueIterable() = default;

/**
* Iterate over key-value pairs
* @param callback a callback to invoke for each key-value. If the callback returns false,
* the iteration is aborted.
* @return true if every key-value pair was iterated over
*/
virtual bool ForEachKeyValue(nostd::function_ref<bool(nostd::string_view, common::AttributeValue)>
callback) const noexcept = 0;

/**
* @return the number of key-value pairs
*/
virtual size_t size() const noexcept = 0;
};

//
// NULL object pattern empty iterable.
//
class NullKeyValueIterable : public KeyValueIterable
{
public:
NullKeyValueIterable(){};

virtual bool ForEachKeyValue(
nostd::function_ref<bool(nostd::string_view, common::AttributeValue)>) const noexcept
{
return true;
};

virtual size_t size() const noexcept { return 0; }
};

} // namespace trace
OPENTELEMETRY_END_NAMESPACE
65 changes: 65 additions & 0 deletions api/include/opentelemetry/trace/key_value_iterable_view.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#pragma once

#include <iterator>
#include <type_traits>
#include <utility>

#include "opentelemetry/nostd/utility.h"
#include "opentelemetry/trace/key_value_iterable.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace trace
{
namespace detail
{
inline void take_key_value(nostd::string_view, common::AttributeValue) {}

template <class T>
auto is_key_value_iterable_impl(T iterable)
-> decltype(take_key_value(std::begin(iterable)->first, std::begin(iterable)->second),
nostd::size(iterable),
std::true_type{});

std::false_type is_key_value_iterable_impl(...);

template <class T>
struct is_key_value_iterable
{
static const bool value = decltype(detail::is_key_value_iterable_impl(std::declval<T>()))::value;
};
} // namespace detail

template <class T>
class KeyValueIterableView final : public KeyValueIterable
{
#if 0 // TODO: [MG] - confirm if we really need this
static_assert(detail::is_key_value_iterable<T>::value, "Must be a key-value iterable");
#endif

public:
explicit KeyValueIterableView(const T &container) noexcept : container_{&container} {};

// KeyValueIterable
bool ForEachKeyValue(nostd::function_ref<bool(nostd::string_view, common::AttributeValue)>
callback) const noexcept override
{
auto iter = std::begin(*container_);
auto last = std::end(*container_);
for (; iter != last; ++iter)
{
if (!callback(iter->first, iter->second))
{
return false;
}
}
return true;
}

size_t size() const noexcept override { return nostd::size(*container_); }

private:
const T *container_;
};
} // namespace trace
OPENTELEMETRY_END_NAMESPACE
11 changes: 11 additions & 0 deletions api/include/opentelemetry/trace/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/common/key_value_iterable_view.h"
#include "opentelemetry/core/timestamp.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/unique_ptr.h"
#include "opentelemetry/nostd/type_traits.h"
#include "opentelemetry/trace/canonical_code.h"
#include "opentelemetry/trace/span_context.h"
#include "opentelemetry/version.h"
Expand Down Expand Up @@ -167,5 +169,14 @@ class Span
// AddEvent).
virtual bool IsRecording() const noexcept = 0;
};

template <class SpanType, class TracerType>
nostd::shared_ptr<trace::Span> to_span_ptr(TracerType *objPtr,
nostd::string_view name,
const trace::StartSpanOptions &options)
{
return nostd::shared_ptr<trace::Span>{new (std::nothrow) SpanType{*objPtr, name, options}};
}

} // namespace trace
OPENTELEMETRY_END_NAMESPACE
4 changes: 4 additions & 0 deletions api/include/opentelemetry/trace/span_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ namespace trace_api = opentelemetry::trace;
class SpanContext final
{
public:
// An invalid SpanContext.
SpanContext() noexcept
: trace_flags_(trace::TraceFlags((uint8_t) false)), remote_parent_(false){};

/* A temporary constructor for an invalid SpanContext.
* Trace id and span id are set to invalid (all zeros).
*
Expand Down
2 changes: 2 additions & 0 deletions api/include/opentelemetry/trace/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ class Tracer

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

nostd::shared_ptr<Span> StartSpan(
Expand Down
2 changes: 2 additions & 0 deletions exporters/etw/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ cc_library(
],
hdrs = [
"include/opentelemetry/exporters/etw/etw_tracer_exporter.h",
"include/opentelemetry/exporters/etw/utils.h",
],
strip_include_prefix = "include",
deps = [
Expand All @@ -21,6 +22,7 @@ cc_library(
],
hdrs = [
"include/opentelemetry/exporters/etw/etw_provider_exporter.h",
"include/opentelemetry/exporters/etw/utils.h",
]
strip_include_prefix = "include",
deps = [
Expand Down
Loading

0 comments on commit e2cda38

Please sign in to comment.