Skip to content

Commit

Permalink
Get rid of obsolete core namespace in API (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyohannes authored Apr 22, 2021
1 parent c8c697f commit a978920
Show file tree
Hide file tree
Showing 41 changed files with 204 additions and 129 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Increment the:

## [Unreleased]

* [API] Move class from opentelemetry::core namespace to opentelemetry::common namespace ([#686](https://github.com/open-telemetry/opentelemetry-cpp/pull/686))

## [0.4.0] 2021-04-12

* [EXPORTER] ETW Exporter enhancements ([#519](https://github.com/open-telemetry/opentelemetry-cpp/pull/519))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,46 @@
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace core
namespace common
{
/**
* Represents a timepoint relative to the system clock epoch
* @brief A timepoint relative to the system clock epoch.
*
* This is used for marking the beginning and end of an operation.
*/
class SystemTimestamp
{
public:
/**
* @brief Initializes a system timestamp pointing to the start of the epoch.
*/
SystemTimestamp() noexcept : nanos_since_epoch_{0} {}

/**
* @brief Initializes a system timestamp from a duration.
*
* @param time_since_epoch Time elapsed since the beginning of the epoch.
*/
template <class Rep, class Period>
explicit SystemTimestamp(const std::chrono::duration<Rep, Period> &time_since_epoch) noexcept
: nanos_since_epoch_{static_cast<int64_t>(
std::chrono::duration_cast<std::chrono::nanoseconds>(time_since_epoch).count())}
{}

/**
* @brief Initializes a system timestamp based on a point in time.
*
* @param time_point A point in time.
*/
/*implicit*/ SystemTimestamp(const std::chrono::system_clock::time_point &time_point) noexcept
: SystemTimestamp{time_point.time_since_epoch()}
{}

/**
* @brief Returns a time point for the time stamp.
*
* @return A time point corresponding to the time stamp.
*/
operator std::chrono::system_clock::time_point() const noexcept
{
return std::chrono::system_clock::time_point{
Expand All @@ -35,18 +55,30 @@ class SystemTimestamp
}

/**
* @return the amount of time that has passed since the system clock epoch
* @brief Returns the nanoseconds since the beginning of the epoch.
*
* @return Elapsed nanoseconds since the beginning of the epoch for this timestamp.
*/
std::chrono::nanoseconds time_since_epoch() const noexcept
{
return std::chrono::nanoseconds{nanos_since_epoch_};
}

/**
* @brief Compare two steady time stamps.
*
* @return true if the two time stamps are equal.
*/
bool operator==(const SystemTimestamp &other) const noexcept
{
return nanos_since_epoch_ == other.nanos_since_epoch_;
}

/**
* @brief Compare two steady time stamps for inequality.
*
* @return true if the two time stamps are not equal.
*/
bool operator!=(const SystemTimestamp &other) const noexcept
{
return nanos_since_epoch_ != other.nanos_since_epoch_;
Expand All @@ -57,23 +89,43 @@ class SystemTimestamp
};

/**
* Represents a timepoint relative to the monotonic clock epoch
* @brief A timepoint relative to the monotonic clock epoch
*
* This is used for calculating the duration of an operation.
*/
class SteadyTimestamp
{
public:
/**
* @brief Initializes a monotonic timestamp pointing to the start of the epoch.
*/
SteadyTimestamp() noexcept : nanos_since_epoch_{0} {}

/**
* @brief Initializes a monotonic timestamp from a duration.
*
* @param time_since_epoch Time elapsed since the beginning of the epoch.
*/
template <class Rep, class Period>
explicit SteadyTimestamp(const std::chrono::duration<Rep, Period> &time_since_epoch) noexcept
: nanos_since_epoch_{static_cast<int64_t>(
std::chrono::duration_cast<std::chrono::nanoseconds>(time_since_epoch).count())}
{}

/**
* @brief Initializes a monotonic timestamp based on a point in time.
*
* @param time_point A point in time.
*/
/*implicit*/ SteadyTimestamp(const std::chrono::steady_clock::time_point &time_point) noexcept
: SteadyTimestamp{time_point.time_since_epoch()}
{}

/**
* @brief Returns a time point for the time stamp.
*
* @return A time point corresponding to the time stamp.
*/
operator std::chrono::steady_clock::time_point() const noexcept
{
return std::chrono::steady_clock::time_point{
Expand All @@ -82,18 +134,30 @@ class SteadyTimestamp
}

/**
* @return the amount of time that has passed since the monotonic clock epoch
* @brief Returns the nanoseconds since the beginning of the epoch.
*
* @return Elapsed nanoseconds since the beginning of the epoch for this timestamp.
*/
std::chrono::nanoseconds time_since_epoch() const noexcept
{
return std::chrono::nanoseconds{nanos_since_epoch_};
}

/**
* @brief Compare two steady time stamps.
*
* @return true if the two time stamps are equal.
*/
bool operator==(const SteadyTimestamp &other) const noexcept
{
return nanos_since_epoch_ == other.nanos_since_epoch_;
}

/**
* @brief Compare two steady time stamps for inequality.
*
* @return true if the two time stamps are not equal.
*/
bool operator!=(const SteadyTimestamp &other) const noexcept
{
return nanos_since_epoch_ != other.nanos_since_epoch_;
Expand All @@ -102,5 +166,5 @@ class SteadyTimestamp
private:
int64_t nanos_since_epoch_;
};
} // namespace core
} // namespace common
OPENTELEMETRY_END_NAMESPACE
8 changes: 4 additions & 4 deletions api/include/opentelemetry/logs/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/common/key_value_iterable.h"
#include "opentelemetry/common/key_value_iterable_view.h"
#include "opentelemetry/core/timestamp.h"
#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/logs/severity.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/span.h"
Expand Down Expand Up @@ -80,7 +80,7 @@ class Logger
trace::TraceId trace_id,
trace::SpanId span_id,
trace::TraceFlags trace_flags,
core::SystemTimestamp timestamp) noexcept = 0;
common::SystemTimestamp timestamp) noexcept = 0;

/*** Overloaded methods for KeyValueIterables ***/
/**
Expand All @@ -101,7 +101,7 @@ class Logger
trace::TraceId trace_id,
trace::SpanId span_id,
trace::TraceFlags trace_flags,
core::SystemTimestamp timestamp) noexcept
common::SystemTimestamp timestamp) noexcept
{
Log(severity, name, body, common::KeyValueIterableView<T>(resource),
common::KeyValueIterableView<U>(attributes), trace_id, span_id, trace_flags, timestamp);
Expand All @@ -115,7 +115,7 @@ class Logger
trace::TraceId trace_id,
trace::SpanId span_id,
trace::TraceFlags trace_flags,
core::SystemTimestamp timestamp) noexcept
common::SystemTimestamp timestamp) noexcept
{
return this->Log(severity, name, body,
nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
Expand Down
4 changes: 2 additions & 2 deletions api/include/opentelemetry/logs/noop.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/common/key_value_iterable.h"
#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/context/runtime_context.h"
#include "opentelemetry/core/timestamp.h"
#include "opentelemetry/logs/logger.h"
#include "opentelemetry/logs/logger_provider.h"
#include "opentelemetry/logs/severity.h"
Expand Down Expand Up @@ -60,7 +60,7 @@ class NoopLogger final : public Logger
trace::TraceId trace_id,
trace::SpanId span_id,
trace::TraceFlags trace_flags,
core::SystemTimestamp timestamp) noexcept override
common::SystemTimestamp timestamp) noexcept override
{}
};

Expand Down
4 changes: 2 additions & 2 deletions api/include/opentelemetry/plugin/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ class Span final : public trace::Span

void AddEvent(nostd::string_view name) noexcept override { span_->AddEvent(name); }

void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept override
void AddEvent(nostd::string_view name, common::SystemTimestamp timestamp) noexcept override
{
span_->AddEvent(name, timestamp);
}

void AddEvent(nostd::string_view name,
core::SystemTimestamp timestamp,
common::SystemTimestamp timestamp,
const common::KeyValueIterable &attributes) noexcept override
{
span_->AddEvent(name, timestamp, attributes);
Expand Down
4 changes: 2 additions & 2 deletions api/include/opentelemetry/trace/default_span.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class DefaultSpan : public Span

void AddEvent(nostd::string_view /* name */) noexcept {}

void AddEvent(nostd::string_view /* name */, core::SystemTimestamp /* timestamp */) noexcept {}
void AddEvent(nostd::string_view /* name */, common::SystemTimestamp /* timestamp */) noexcept {}

void AddEvent(nostd::string_view /* name */,
core::SystemTimestamp /* timestamp */,
common::SystemTimestamp /* timestamp */,
const common::KeyValueIterable & /* attributes */) noexcept
{}

Expand Down
5 changes: 3 additions & 2 deletions api/include/opentelemetry/trace/noop.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ class NoopSpan final : public Span

void AddEvent(nostd::string_view /*name*/) noexcept override {}

void AddEvent(nostd::string_view /*name*/, core::SystemTimestamp /*timestamp*/) noexcept override
void AddEvent(nostd::string_view /*name*/,
common::SystemTimestamp /*timestamp*/) noexcept override
{}

void AddEvent(nostd::string_view /*name*/,
core::SystemTimestamp /*timestamp*/,
common::SystemTimestamp /*timestamp*/,
const common::KeyValueIterable & /*attributes*/) noexcept override
{}

Expand Down
16 changes: 8 additions & 8 deletions api/include/opentelemetry/trace/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/common/key_value_iterable_view.h"
#include "opentelemetry/core/timestamp.h"
#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/nostd/string_view.h"
Expand Down Expand Up @@ -54,8 +54,8 @@ struct StartSpanOptions
// Span's duration, while timestamps from the system clock can be used to most
// accurately place a Span's
// time point relative to other Spans collected across a distributed system.
core::SystemTimestamp start_system_time;
core::SteadyTimestamp start_steady_time;
common::SystemTimestamp start_system_time;
common::SteadyTimestamp start_steady_time;

// Explicitly set the parent of a Span.
//
Expand All @@ -75,7 +75,7 @@ struct StartSpanOptions
struct EndSpanOptions
{
// Optionally sets the end time of a Span.
core::SteadyTimestamp end_steady_time;
common::SteadyTimestamp end_steady_time;
};

class Tracer;
Expand Down Expand Up @@ -109,11 +109,11 @@ class Span
virtual void AddEvent(nostd::string_view name) noexcept = 0;

// Adds an event to the Span, with a custom timestamp.
virtual void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept = 0;
virtual void AddEvent(nostd::string_view name, common::SystemTimestamp timestamp) noexcept = 0;

// Adds an event to the Span, with a custom timestamp, and attributes.
virtual void AddEvent(nostd::string_view name,
core::SystemTimestamp timestamp,
common::SystemTimestamp timestamp,
const common::KeyValueIterable &attributes) noexcept = 0;

virtual void AddEvent(nostd::string_view name,
Expand All @@ -125,7 +125,7 @@ class Span
template <class T,
nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
void AddEvent(nostd::string_view name,
core::SystemTimestamp timestamp,
common::SystemTimestamp timestamp,
const T &attributes) noexcept
{
this->AddEvent(name, timestamp, common::KeyValueIterableView<T>{attributes});
Expand All @@ -139,7 +139,7 @@ class Span
}

void AddEvent(nostd::string_view name,
core::SystemTimestamp timestamp,
common::SystemTimestamp timestamp,
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
attributes) noexcept
{
Expand Down
6 changes: 3 additions & 3 deletions api/test/core/timestamp_test.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "opentelemetry/core/timestamp.h"
#include "opentelemetry/common/timestamp.h"

#include <gtest/gtest.h>

using opentelemetry::core::SteadyTimestamp;
using opentelemetry::core::SystemTimestamp;
using opentelemetry::common::SteadyTimestamp;
using opentelemetry::common::SystemTimestamp;

template <class Timestamp>
static bool AreNearlyEqual(const Timestamp &t1, const Timestamp &t2) noexcept
Expand Down
4 changes: 2 additions & 2 deletions api/test/logs/logger_test.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include <array>

#include "opentelemetry/core/timestamp.h"
#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/logs/logger.h"
#include "opentelemetry/logs/provider.h"
#include "opentelemetry/nostd/shared_ptr.h"
Expand Down Expand Up @@ -77,7 +77,7 @@ class TestLogger : public Logger
opentelemetry::trace::TraceId trace_id,
opentelemetry::trace::SpanId span_id,
opentelemetry::trace::TraceFlags trace_flags,
opentelemetry::core::SystemTimestamp timestamp) noexcept override
opentelemetry::common::SystemTimestamp timestamp) noexcept override
{}
};

Expand Down
4 changes: 2 additions & 2 deletions api/test/trace/noop_test.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "opentelemetry/trace/noop.h"
#include "opentelemetry/core/timestamp.h"
#include "opentelemetry/common/timestamp.h"

#include <map>
#include <memory>
#include <string>

#include <gtest/gtest.h>

using opentelemetry::core::SystemTimestamp;
using opentelemetry::common::SystemTimestamp;
using opentelemetry::trace::NoopTracer;
using opentelemetry::trace::SpanContext;
using opentelemetry::trace::Tracer;
Expand Down
Loading

0 comments on commit a978920

Please sign in to comment.