Skip to content

Commit

Permalink
Use std shared_ptr, unique_ptr and enable_if
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Dec 2, 2023
1 parent 25343e6 commit 0f9d248
Show file tree
Hide file tree
Showing 40 changed files with 190 additions and 176 deletions.
10 changes: 5 additions & 5 deletions sdk/include/opentelemetry/sdk/common/global_log_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

#pragma once

#include <memory>
#include <sstream>
#include <utility>

#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/sdk/common/attribute_utils.h"
#include "opentelemetry/version.h"

Expand Down Expand Up @@ -94,7 +94,7 @@ class GlobalLogHandler
*
* By default, a default LogHandler is returned.
*/
static inline const nostd::shared_ptr<LogHandler> &GetLogHandler() noexcept
static inline const std::shared_ptr<LogHandler> &GetLogHandler() noexcept
{
return GetHandlerAndLevel().first;
}
Expand All @@ -104,7 +104,7 @@ class GlobalLogHandler
* This should be called once at the start of application before creating any Provider
* instance.
*/
static inline void SetLogHandler(nostd::shared_ptr<LogHandler> eh) noexcept
static inline void SetLogHandler(std::shared_ptr<LogHandler> eh) noexcept
{
GetHandlerAndLevel().first = eh;
}
Expand All @@ -124,7 +124,7 @@ class GlobalLogHandler
static inline void SetLogLevel(LogLevel level) noexcept { GetHandlerAndLevel().second = level; }

private:
static std::pair<nostd::shared_ptr<LogHandler>, LogLevel> &GetHandlerAndLevel() noexcept;
static std::pair<std::shared_ptr<LogHandler>, LogLevel> &GetHandlerAndLevel() noexcept;
};

} // namespace internal_log
Expand All @@ -146,7 +146,7 @@ OPENTELEMETRY_END_NAMESPACE
{ \
break; \
} \
const opentelemetry::nostd::shared_ptr<LogHandler> &log_handler = \
const opentelemetry::std::shared_ptr<LogHandler> &log_handler = \
GlobalLogHandler::GetLogHandler(); \
if (!log_handler) \
{ \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

#pragma once

#include <memory>
#include <string>
#include <type_traits>

#include "opentelemetry/common/key_value_iterable_view.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/type_traits.h"
#include "opentelemetry/nostd/unique_ptr.h"
#include "opentelemetry/nostd/variant.h"
#include "opentelemetry/sdk/common/attribute_utils.h"
#include "opentelemetry/version.h"
Expand All @@ -35,13 +35,13 @@ class InstrumentationScope
* @param attributes attributes of the instrumentation scope.
* @returns the newly created InstrumentationScope.
*/
static nostd::unique_ptr<InstrumentationScope> Create(
static std::unique_ptr<InstrumentationScope> Create(
nostd::string_view name,
nostd::string_view version = "",
nostd::string_view schema_url = "",
InstrumentationScopeAttributes &&attributes = {})
{
return nostd::unique_ptr<InstrumentationScope>(
return std::unique_ptr<InstrumentationScope>(
new InstrumentationScope{name, version, schema_url, std::move(attributes)});
}

Expand All @@ -53,13 +53,13 @@ class InstrumentationScope
* @param attributes attributes of the instrumentation scope.
* @returns the newly created InstrumentationScope.
*/
static nostd::unique_ptr<InstrumentationScope> Create(
static std::unique_ptr<InstrumentationScope> Create(
nostd::string_view name,
nostd::string_view version,
nostd::string_view schema_url,
const InstrumentationScopeAttributes &attributes)
{
return nostd::unique_ptr<InstrumentationScope>(new InstrumentationScope{
return std::unique_ptr<InstrumentationScope>(new InstrumentationScope{
name, version, schema_url, InstrumentationScopeAttributes(attributes)});
}

Expand All @@ -73,14 +73,14 @@ class InstrumentationScope
*/
template <
class ArgumentType,
nostd::enable_if_t<opentelemetry::common::detail::is_key_value_iterable<ArgumentType>::value>
std::enable_if_t<opentelemetry::common::detail::is_key_value_iterable<ArgumentType>::value>
* = nullptr>
static nostd::unique_ptr<InstrumentationScope> Create(nostd::string_view name,
nostd::string_view version,
nostd::string_view schema_url,
const ArgumentType &arg)
static std::unique_ptr<InstrumentationScope> Create(nostd::string_view name,
nostd::string_view version,
nostd::string_view schema_url,
const ArgumentType &arg)
{
nostd::unique_ptr<InstrumentationScope> result = nostd::unique_ptr<InstrumentationScope>(
std::unique_ptr<InstrumentationScope> result = std::unique_ptr<InstrumentationScope>(
new InstrumentationScope{name, version, schema_url});

// Do not construct a KeyValueIterable, so it has better performance.
Expand Down
11 changes: 5 additions & 6 deletions sdk/include/opentelemetry/sdk/logs/event_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

#pragma once

#include <memory>
#include <string>

#include "opentelemetry/logs/event_logger.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/unique_ptr.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
Expand All @@ -27,23 +26,23 @@ class EventLogger final : public opentelemetry::logs::EventLogger
* @param delegate_logger The delegate logger instance
* @param event_domain Event domain
*/
explicit EventLogger(nostd::shared_ptr<opentelemetry::logs::Logger> delegate_logger,
explicit EventLogger(std::shared_ptr<opentelemetry::logs::Logger> delegate_logger,
nostd::string_view event_domain) noexcept;

/**
* Returns the name of this logger.
*/
const opentelemetry::nostd::string_view GetName() noexcept override;

nostd::shared_ptr<opentelemetry::logs::Logger> GetDelegateLogger() noexcept override;
std::shared_ptr<opentelemetry::logs::Logger> GetDelegateLogger() noexcept override;

using opentelemetry::logs::EventLogger::EmitEvent;

void EmitEvent(nostd::string_view event_name,
nostd::unique_ptr<opentelemetry::logs::LogRecord> &&log_record) noexcept override;
std::unique_ptr<opentelemetry::logs::LogRecord> &&log_record) noexcept override;

private:
nostd::shared_ptr<opentelemetry::logs::Logger> delegate_logger_;
std::shared_ptr<opentelemetry::logs::Logger> delegate_logger_;
std::string event_domain_;
};

Expand Down
7 changes: 4 additions & 3 deletions sdk/include/opentelemetry/sdk/logs/event_logger_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

#pragma once

#include <memory>

#include "opentelemetry/logs/event_logger_provider.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/version.h"

Expand All @@ -27,8 +28,8 @@ class EventLoggerProvider final : public opentelemetry::logs::EventLoggerProvide

~EventLoggerProvider() override;

nostd::shared_ptr<opentelemetry::logs::EventLogger> CreateEventLogger(
nostd::shared_ptr<opentelemetry::logs::Logger> delegate_logger,
std::shared_ptr<opentelemetry::logs::EventLogger> CreateEventLogger(
std::shared_ptr<opentelemetry::logs::Logger> delegate_logger,
nostd::string_view event_domain) noexcept override;
};
} // namespace logs
Expand Down
5 changes: 2 additions & 3 deletions sdk/include/opentelemetry/sdk/logs/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "opentelemetry/common/macros.h"
#include "opentelemetry/logs/logger.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/unique_ptr.h"
#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
#include "opentelemetry/sdk/logs/logger_context.h"
#include "opentelemetry/version.h"
Expand Down Expand Up @@ -40,12 +39,12 @@ class Logger final : public opentelemetry::logs::Logger
*/
const opentelemetry::nostd::string_view GetName() noexcept override;

nostd::unique_ptr<opentelemetry::logs::LogRecord> CreateLogRecord() noexcept override;
std::unique_ptr<opentelemetry::logs::LogRecord> CreateLogRecord() noexcept override;

using opentelemetry::logs::Logger::EmitLogRecord;

void EmitLogRecord(
nostd::unique_ptr<opentelemetry::logs::LogRecord> &&log_record) noexcept override;
std::unique_ptr<opentelemetry::logs::LogRecord> &&log_record) noexcept override;

/** Returns the associated instrumentation scope */
const opentelemetry::sdk::instrumentationscope::InstrumentationScope &GetInstrumentationScope()
Expand Down
3 changes: 1 addition & 2 deletions sdk/include/opentelemetry/sdk/logs/logger_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <vector>

#include "opentelemetry/logs/logger_provider.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/sdk/resource/resource.h"
#include "opentelemetry/version.h"
Expand Down Expand Up @@ -71,7 +70,7 @@ class LoggerProvider final : public opentelemetry::logs::LoggerProvider
* @param library_version The version of the library.
* @param schema_url The schema URL.
*/
nostd::shared_ptr<opentelemetry::logs::Logger> GetLogger(
std::shared_ptr<opentelemetry::logs::Logger> GetLogger(
nostd::string_view logger_name,
nostd::string_view library_name,
nostd::string_view library_version = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "opentelemetry/context/context.h"
#include "opentelemetry/nostd/function_ref.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/sdk/common/attribute_utils.h"
#include "opentelemetry/sdk/metrics/exemplar/reservoir.h"
#include "opentelemetry/sdk/metrics/exemplar/reservoir_cell.h"
Expand Down
6 changes: 3 additions & 3 deletions sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ class ExemplarReservoir
virtual std::vector<std::shared_ptr<ExemplarData>> CollectAndReset(
const MetricAttributes &pointAttributes) noexcept = 0;

static nostd::shared_ptr<ExemplarReservoir> GetFilteredExemplarReservoir(
static std::shared_ptr<ExemplarReservoir> GetFilteredExemplarReservoir(
std::shared_ptr<ExemplarFilter> filter,
std::shared_ptr<ExemplarReservoir> reservoir);

static nostd::shared_ptr<ExemplarReservoir> GetHistogramExemplarReservoir(
static std::shared_ptr<ExemplarReservoir> GetHistogramExemplarReservoir(
size_t size,
std::shared_ptr<ReservoirCellSelector> reservoir_cell_selector,
std::shared_ptr<ExemplarData> (ReservoirCell::*map_and_reset_cell)(
const common::OrderedAttributeMap &attributes));

static nostd::shared_ptr<ExemplarReservoir> GetNoExemplarReservoir();
static std::shared_ptr<ExemplarReservoir> GetNoExemplarReservoir();
};

} // namespace metrics
Expand Down
30 changes: 14 additions & 16 deletions sdk/include/opentelemetry/sdk/metrics/meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
#include "opentelemetry/common/macros.h"
#include "opentelemetry/metrics/meter.h"
#include "opentelemetry/metrics/noop.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/unique_ptr.h"
#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
#include "opentelemetry/sdk/metrics/instrument_metadata_validator.h"
#include "opentelemetry/sdk/metrics/instruments.h"
Expand Down Expand Up @@ -44,62 +42,62 @@ class Meter final : public opentelemetry::metrics::Meter
std::unique_ptr<opentelemetry::sdk::instrumentationscope::InstrumentationScope> scope =
opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("")) noexcept;

nostd::unique_ptr<opentelemetry::metrics::Counter<uint64_t>> CreateUInt64Counter(
std::unique_ptr<opentelemetry::metrics::Counter<uint64_t>> CreateUInt64Counter(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;

nostd::unique_ptr<opentelemetry::metrics::Counter<double>> CreateDoubleCounter(
std::unique_ptr<opentelemetry::metrics::Counter<double>> CreateDoubleCounter(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;

nostd::shared_ptr<opentelemetry::metrics::ObservableInstrument> CreateInt64ObservableCounter(
std::shared_ptr<opentelemetry::metrics::ObservableInstrument> CreateInt64ObservableCounter(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;

nostd::shared_ptr<opentelemetry::metrics::ObservableInstrument> CreateDoubleObservableCounter(
std::shared_ptr<opentelemetry::metrics::ObservableInstrument> CreateDoubleObservableCounter(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;

nostd::unique_ptr<opentelemetry::metrics::Histogram<uint64_t>> CreateUInt64Histogram(
std::unique_ptr<opentelemetry::metrics::Histogram<uint64_t>> CreateUInt64Histogram(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;

nostd::unique_ptr<opentelemetry::metrics::Histogram<double>> CreateDoubleHistogram(
std::unique_ptr<opentelemetry::metrics::Histogram<double>> CreateDoubleHistogram(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;

nostd::shared_ptr<opentelemetry::metrics::ObservableInstrument> CreateInt64ObservableGauge(
std::shared_ptr<opentelemetry::metrics::ObservableInstrument> CreateInt64ObservableGauge(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;

nostd::shared_ptr<opentelemetry::metrics::ObservableInstrument> CreateDoubleObservableGauge(
std::shared_ptr<opentelemetry::metrics::ObservableInstrument> CreateDoubleObservableGauge(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;

nostd::unique_ptr<opentelemetry::metrics::UpDownCounter<int64_t>> CreateInt64UpDownCounter(
std::unique_ptr<opentelemetry::metrics::UpDownCounter<int64_t>> CreateInt64UpDownCounter(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;

nostd::unique_ptr<opentelemetry::metrics::UpDownCounter<double>> CreateDoubleUpDownCounter(
std::unique_ptr<opentelemetry::metrics::UpDownCounter<double>> CreateDoubleUpDownCounter(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;

nostd::shared_ptr<opentelemetry::metrics::ObservableInstrument>
std::shared_ptr<opentelemetry::metrics::ObservableInstrument>
CreateInt64ObservableUpDownCounter(nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;

nostd::shared_ptr<opentelemetry::metrics::ObservableInstrument>
std::shared_ptr<opentelemetry::metrics::ObservableInstrument>
CreateDoubleObservableUpDownCounter(nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;
Expand Down Expand Up @@ -131,10 +129,10 @@ class Meter final : public opentelemetry::metrics::Meter
InstrumentDescriptor &instrument_descriptor);
opentelemetry::common::SpinLockMutex storage_lock_;

static nostd::shared_ptr<opentelemetry::metrics::ObservableInstrument>
static std::shared_ptr<opentelemetry::metrics::ObservableInstrument>
GetNoopObservableInsrument()
{
static nostd::shared_ptr<opentelemetry::metrics::ObservableInstrument> noop_instrument(
static std::shared_ptr<opentelemetry::metrics::ObservableInstrument> noop_instrument(
new opentelemetry::metrics::NoopObservableInstrument("", "", ""));
return noop_instrument;
}
Expand Down
5 changes: 2 additions & 3 deletions sdk/include/opentelemetry/sdk/metrics/meter_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <mutex>

#include "opentelemetry/metrics/meter_provider.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/sdk/metrics/view/view_registry.h"
#include "opentelemetry/sdk/resource/resource.h"
Expand Down Expand Up @@ -54,13 +53,13 @@ class OPENTELEMETRY_EXPORT MeterProvider final : public opentelemetry::metrics::
using opentelemetry::metrics::MeterProvider::GetMeter;

#if OPENTELEMETRY_ABI_VERSION_NO >= 2
nostd::shared_ptr<opentelemetry::metrics::Meter> GetMeter(
std::shared_ptr<opentelemetry::metrics::Meter> GetMeter(
nostd::string_view name,
nostd::string_view version,
nostd::string_view schema_url,
const opentelemetry::common::KeyValueIterable *attributes) noexcept override;
#else
nostd::shared_ptr<opentelemetry::metrics::Meter> GetMeter(
std::shared_ptr<opentelemetry::metrics::Meter> GetMeter(
nostd::string_view name,
nostd::string_view version = "",
nostd::string_view schema_url = "") noexcept override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <memory>
#include <mutex>
#include <vector>

#include "opentelemetry/metrics/meter.h"
#include "opentelemetry/metrics/meter_provider.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/sdk/metrics/meter.h"
#include "opentelemetry/sdk/metrics/meter_context.h"
#include "opentelemetry/sdk/resource/resource.h"
Expand Down
Loading

0 comments on commit 0f9d248

Please sign in to comment.