Skip to content

Commit

Permalink
Added .clang-tidy and ran it against opentelemetry-sdk. Build and cte…
Browse files Browse the repository at this point in the history
…st working.
  • Loading branch information
msiddhu committed Jul 3, 2024
1 parent 7701239 commit b0edc69
Show file tree
Hide file tree
Showing 52 changed files with 119 additions and 109 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Checks: 'clang-analyzer-*,performance-*,bugprone-*'
2 changes: 1 addition & 1 deletion sdk/include/opentelemetry/sdk/common/attributemap_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ inline void GetHash(size_t &seed, const T &arg)
template <class T>
inline void GetHash(size_t &seed, const std::vector<T> &arg)
{
for (auto v : arg)
for (const auto& v : arg)
{
GetHash<T>(seed, v);
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/include/opentelemetry/sdk/common/global_log_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class GlobalLogHandler
*/
static inline void SetLogHandler(nostd::shared_ptr<LogHandler> eh) noexcept
{
GetHandlerAndLevel().first = eh;
GetHandlerAndLevel().first = std::move(eh);
}

/**
Expand Down Expand Up @@ -147,7 +147,7 @@ OPENTELEMETRY_END_NAMESPACE
{ \
using opentelemetry::sdk::common::internal_log::GlobalLogHandler; \
using opentelemetry::sdk::common::internal_log::LogHandler; \
if (level > GlobalLogHandler::GetLogLevel()) \
if ((level) > GlobalLogHandler::GetLogLevel()) \
{ \
break; \
} \
Expand Down
2 changes: 1 addition & 1 deletion sdk/include/opentelemetry/sdk/logs/logger_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class LoggerContext
{
public:
explicit LoggerContext(std::vector<std::unique_ptr<LogRecordProcessor>> &&processors,
opentelemetry::sdk::resource::Resource resource =
const opentelemetry::sdk::resource::Resource& resource =
opentelemetry::sdk::resource::Resource::Create({})) noexcept;

/**
Expand Down
4 changes: 2 additions & 2 deletions sdk/include/opentelemetry/sdk/logs/logger_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class OPENTELEMETRY_EXPORT LoggerProvider final : public opentelemetry::logs::Lo
* not be a nullptr
*/
explicit LoggerProvider(std::unique_ptr<LogRecordProcessor> &&processor,
opentelemetry::sdk::resource::Resource resource =
const opentelemetry::sdk::resource::Resource& resource =
opentelemetry::sdk::resource::Resource::Create({})) noexcept;

explicit LoggerProvider(std::vector<std::unique_ptr<LogRecordProcessor>> &&processors,
opentelemetry::sdk::resource::Resource resource =
const opentelemetry::sdk::resource::Resource& resource =
opentelemetry::sdk::resource::Resource::Create({})) noexcept;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DefaultAggregation

static std::unique_ptr<Aggregation> CreateAggregation(
AggregationType aggregation_type,
InstrumentDescriptor instrument_descriptor,
const InstrumentDescriptor& instrument_descriptor,
const AggregationConfig *aggregation_config = nullptr)
{
switch (aggregation_type)
Expand Down Expand Up @@ -114,7 +114,7 @@ class DefaultAggregation
}

static std::unique_ptr<Aggregation> CloneAggregation(AggregationType aggregation_type,
InstrumentDescriptor instrument_descriptor,
const InstrumentDescriptor& instrument_descriptor,
const Aggregation &to_copy)
{
const PointType point_data = to_copy.ToPoint();
Expand Down
5 changes: 3 additions & 2 deletions sdk/include/opentelemetry/sdk/metrics/data/exemplar_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <memory>
#include <utility>

#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/sdk/metrics/data/metric_data.h"
Expand All @@ -30,7 +31,7 @@ class ExemplarData
const opentelemetry::common::SystemTimestamp &timestamp,
const PointDataAttributes &point_data_attr)
{
return ExemplarData(context, timestamp, point_data_attr);
return ExemplarData(std::move(context), timestamp, point_data_attr);
}

/**
Expand Down Expand Up @@ -68,7 +69,7 @@ class ExemplarData
static PointType CreateDropPointData() { return DropPointData{}; }

private:
ExemplarData(std::shared_ptr<opentelemetry::trace::SpanContext> context,
ExemplarData(const std::shared_ptr<opentelemetry::trace::SpanContext>& context,
opentelemetry::common::SystemTimestamp timestamp,
const PointDataAttributes &point_data_attr)
: context_(*context.get()), timestamp_(timestamp), point_data_attr_(point_data_attr)
Expand Down
4 changes: 2 additions & 2 deletions sdk/include/opentelemetry/sdk/metrics/meter_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class MeterContext : public std::enable_shared_from_this<MeterContext>
*/
MeterContext(
std::unique_ptr<ViewRegistry> views = std::unique_ptr<ViewRegistry>(new ViewRegistry()),
opentelemetry::sdk::resource::Resource resource =
const opentelemetry::sdk::resource::Resource& resource =
opentelemetry::sdk::resource::Resource::Create({})) noexcept;

/**
Expand Down Expand Up @@ -131,7 +131,7 @@ class MeterContext : public std::enable_shared_from_this<MeterContext>
*
* @param meter
*/
void AddMeter(std::shared_ptr<Meter> meter);
void AddMeter(const std::shared_ptr<Meter>& meter);

void RemoveMeter(nostd::string_view name,
nostd::string_view version,
Expand Down
2 changes: 1 addition & 1 deletion sdk/include/opentelemetry/sdk/metrics/meter_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class OPENTELEMETRY_EXPORT MeterProvider final : public opentelemetry::metrics::
*/
MeterProvider(
std::unique_ptr<ViewRegistry> views = std::unique_ptr<ViewRegistry>(new ViewRegistry()),
sdk::resource::Resource resource = sdk::resource::Resource::Create({})) noexcept;
const sdk::resource::Resource& resource = sdk::resource::Resource::Create({})) noexcept;

/**
* Initialize a new meter provider with a specified context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace metrics
class AsyncMetricStorage : public MetricStorage, public AsyncWritableMetricStorage
{
public:
AsyncMetricStorage(InstrumentDescriptor instrument_descriptor,
AsyncMetricStorage(const InstrumentDescriptor& instrument_descriptor,
const AggregationType aggregation_type,
#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
ExemplarFilterType exempler_filter_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class AttributesHashMap
*/
Aggregation *GetOrSetDefault(const opentelemetry::common::KeyValueIterable &attributes,
const AttributesProcessor *attributes_processor,
std::function<std::unique_ptr<Aggregation>()> aggregation_callback,
const std::function<std::unique_ptr<Aggregation>()>& aggregation_callback,
size_t hash)
{
auto it = hash_map_.find(hash);
Expand All @@ -88,7 +88,7 @@ class AttributesHashMap
return hash_map_[hash].second.get();
}

Aggregation *GetOrSetDefault(std::function<std::unique_ptr<Aggregation>()> aggregation_callback,
Aggregation *GetOrSetDefault(const std::function<std::unique_ptr<Aggregation>()>& aggregation_callback,
size_t hash)
{
auto it = hash_map_.find(hash);
Expand All @@ -108,7 +108,7 @@ class AttributesHashMap
}

Aggregation *GetOrSetDefault(const MetricAttributes &attributes,
std::function<std::unique_ptr<Aggregation>()> aggregation_callback,
const std::function<std::unique_ptr<Aggregation>()>& aggregation_callback,
size_t hash)
{
auto it = hash_map_.find(hash);
Expand Down Expand Up @@ -199,7 +199,7 @@ class AttributesHashMap
size_t attributes_limit_;

Aggregation *GetOrSetOveflowAttributes(
std::function<std::unique_ptr<Aggregation>()> aggregation_callback)
const std::function<std::unique_ptr<Aggregation>()>& aggregation_callback)
{
auto agg = aggregation_callback();
return GetOrSetOveflowAttributes(std::move(agg));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace metrics
class SyncMultiMetricStorage : public SyncWritableMetricStorage
{
public:
void AddStorage(std::shared_ptr<SyncWritableMetricStorage> storage)
void AddStorage(const std::shared_ptr<SyncWritableMetricStorage>& storage)
{
storages_.push_back(storage);
}
Expand Down Expand Up @@ -81,7 +81,7 @@ class SyncMultiMetricStorage : public SyncWritableMetricStorage
class AsyncMultiMetricStorage : public AsyncWritableMetricStorage
{
public:
void AddStorage(std::shared_ptr<AsyncWritableMetricStorage> storage)
void AddStorage(const std::shared_ptr<AsyncWritableMetricStorage>& storage)
{
storages_.push_back(storage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
#endif // ENABLE_METRICS_EXEMPLAR_PREVIEW

public:
SyncMetricStorage(InstrumentDescriptor instrument_descriptor,
SyncMetricStorage(const InstrumentDescriptor& instrument_descriptor,
const AggregationType aggregation_type,
const AttributesProcessor *attributes_processor,
#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class TemporalMetricStorage
nostd::span<std::shared_ptr<CollectorHandle>> collectors,
opentelemetry::common::SystemTimestamp sdk_start_ts,
opentelemetry::common::SystemTimestamp collection_ts,
std::shared_ptr<AttributesHashMap> delta_metrics,
const std::shared_ptr<AttributesHashMap>& delta_metrics,
nostd::function_ref<bool(MetricData)> callback) noexcept;

private:
Expand Down
14 changes: 7 additions & 7 deletions sdk/include/opentelemetry/sdk/metrics/sync_instruments.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Synchronous
public:
Synchronous(InstrumentDescriptor instrument_descriptor,
std::unique_ptr<SyncWritableMetricStorage> storage)
: instrument_descriptor_(instrument_descriptor), storage_(std::move(storage))
: instrument_descriptor_(std::move(instrument_descriptor)), storage_(std::move(storage))
{}

protected:
Expand All @@ -37,7 +37,7 @@ class Synchronous
class LongCounter : public Synchronous, public opentelemetry::metrics::Counter<uint64_t>
{
public:
LongCounter(InstrumentDescriptor instrument_descriptor,
LongCounter(const InstrumentDescriptor& instrument_descriptor,
std::unique_ptr<SyncWritableMetricStorage> storage);

void Add(uint64_t value,
Expand All @@ -56,7 +56,7 @@ class DoubleCounter : public Synchronous, public opentelemetry::metrics::Counter
{

public:
DoubleCounter(InstrumentDescriptor instrument_descriptor,
DoubleCounter(const InstrumentDescriptor& instrument_descriptor,
std::unique_ptr<SyncWritableMetricStorage> storage);

void Add(double value,
Expand All @@ -72,7 +72,7 @@ class DoubleCounter : public Synchronous, public opentelemetry::metrics::Counter
class LongUpDownCounter : public Synchronous, public opentelemetry::metrics::UpDownCounter<int64_t>
{
public:
LongUpDownCounter(InstrumentDescriptor instrument_descriptor,
LongUpDownCounter(const InstrumentDescriptor& instrument_descriptor,
std::unique_ptr<SyncWritableMetricStorage> storage);

void Add(int64_t value,
Expand All @@ -88,7 +88,7 @@ class LongUpDownCounter : public Synchronous, public opentelemetry::metrics::UpD
class DoubleUpDownCounter : public Synchronous, public opentelemetry::metrics::UpDownCounter<double>
{
public:
DoubleUpDownCounter(InstrumentDescriptor instrument_descriptor,
DoubleUpDownCounter(const InstrumentDescriptor& instrument_descriptor,
std::unique_ptr<SyncWritableMetricStorage> storage);

void Add(double value,
Expand All @@ -104,7 +104,7 @@ class DoubleUpDownCounter : public Synchronous, public opentelemetry::metrics::U
class LongHistogram : public Synchronous, public opentelemetry::metrics::Histogram<uint64_t>
{
public:
LongHistogram(InstrumentDescriptor instrument_descriptor,
LongHistogram(const InstrumentDescriptor& instrument_descriptor,
std::unique_ptr<SyncWritableMetricStorage> storage);

#if OPENTELEMETRY_ABI_VERSION_NO >= 2
Expand All @@ -124,7 +124,7 @@ class LongHistogram : public Synchronous, public opentelemetry::metrics::Histogr
class DoubleHistogram : public Synchronous, public opentelemetry::metrics::Histogram<double>
{
public:
DoubleHistogram(InstrumentDescriptor instrument_descriptor,
DoubleHistogram(const InstrumentDescriptor& instrument_descriptor,
std::unique_ptr<SyncWritableMetricStorage> storage);

#if OPENTELEMETRY_ABI_VERSION_NO >= 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class FilteringAttributesProcessor : public AttributesProcessor
{
public:
FilteringAttributesProcessor(
const std::unordered_map<std::string, bool> allowed_attribute_keys = {})
: allowed_attribute_keys_(std::move(allowed_attribute_keys))
const std::unordered_map<std::string, bool>& allowed_attribute_keys = {})
: allowed_attribute_keys_(allowed_attribute_keys)
{}

MetricAttributes process(
Expand Down
3 changes: 2 additions & 1 deletion sdk/include/opentelemetry/sdk/metrics/view/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <memory>
#include <string>
#include <utility>

#include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h"
#include "opentelemetry/sdk/metrics/instruments.h"
Expand Down Expand Up @@ -36,7 +37,7 @@ class View
description_(description),
unit_(unit),
aggregation_type_{aggregation_type},
aggregation_config_{aggregation_config},
aggregation_config_{std::move(aggregation_config)},
attributes_processor_{std::move(attributes_processor)}
{}

Expand Down
2 changes: 1 addition & 1 deletion sdk/include/opentelemetry/sdk/trace/recordable.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Recordable
* Add a link to a span with default (empty) attributes.
* @param span_context the span context of the linked span
*/
void AddLink(opentelemetry::trace::SpanContext span_context)
void AddLink(const opentelemetry::trace::SpanContext& span_context)
{
AddLink(span_context, opentelemetry::sdk::GetEmptyAttributes());
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/include/opentelemetry/sdk/trace/samplers/parent.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace trace
class ParentBasedSampler : public Sampler
{
public:
explicit ParentBasedSampler(std::shared_ptr<Sampler> delegate_sampler) noexcept;
explicit ParentBasedSampler(const std::shared_ptr<Sampler>& delegate_sampler) noexcept;
/** The decision either respects the parent span's sampling decision or delegates to
* delegateSampler for root spans
* @return Returns DROP always
Expand Down
5 changes: 3 additions & 2 deletions sdk/include/opentelemetry/sdk/trace/span_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#include "opentelemetry/common/attribute_value.h"
Expand Down Expand Up @@ -36,7 +37,7 @@ class SpanDataEvent
SpanDataEvent(std::string name,
opentelemetry::common::SystemTimestamp timestamp,
const opentelemetry::common::KeyValueIterable &attributes)
: name_(name), timestamp_(timestamp), attribute_map_(attributes)
: name_(std::move(name)), timestamp_(timestamp), attribute_map_(attributes)
{}

/**
Expand Down Expand Up @@ -73,7 +74,7 @@ class SpanDataEvent
class SpanDataLink
{
public:
SpanDataLink(opentelemetry::trace::SpanContext span_context,
SpanDataLink(const opentelemetry::trace::SpanContext& span_context,
const opentelemetry::common::KeyValueIterable &attributes)
: span_context_(span_context), attribute_map_(attributes)
{}
Expand Down
2 changes: 1 addition & 1 deletion sdk/include/opentelemetry/sdk/trace/tracer_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TracerContext
public:
explicit TracerContext(
std::vector<std::unique_ptr<SpanProcessor>> &&processor,
opentelemetry::sdk::resource::Resource resource =
const opentelemetry::sdk::resource::Resource& resource =
opentelemetry::sdk::resource::Resource::Create({}),
std::unique_ptr<Sampler> sampler = std::unique_ptr<AlwaysOnSampler>(new AlwaysOnSampler),
std::unique_ptr<IdGenerator> id_generator =
Expand Down
4 changes: 2 additions & 2 deletions sdk/include/opentelemetry/sdk/trace/tracer_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ class OPENTELEMETRY_EXPORT TracerProvider final : public opentelemetry::trace::T
*/
explicit TracerProvider(
std::unique_ptr<SpanProcessor> processor,
opentelemetry::sdk::resource::Resource resource =
const opentelemetry::sdk::resource::Resource& resource =
opentelemetry::sdk::resource::Resource::Create({}),
std::unique_ptr<Sampler> sampler = std::unique_ptr<AlwaysOnSampler>(new AlwaysOnSampler),
std::unique_ptr<IdGenerator> id_generator =
std::unique_ptr<IdGenerator>(new RandomIdGenerator())) noexcept;

explicit TracerProvider(
std::vector<std::unique_ptr<SpanProcessor>> &&processors,
opentelemetry::sdk::resource::Resource resource =
const opentelemetry::sdk::resource::Resource& resource =
opentelemetry::sdk::resource::Resource::Create({}),
std::unique_ptr<Sampler> sampler = std::unique_ptr<AlwaysOnSampler>(new AlwaysOnSampler),
std::unique_ptr<IdGenerator> id_generator =
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/common/global_log_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void DefaultLogHandler::Handle(LogLevel level,
{
output_s << msg;
}
output_s << std::endl;
output_s << '\n';
// TBD - print attributes

switch (level)
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/logs/event_logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace logs
EventLogger::EventLogger(
opentelemetry::nostd::shared_ptr<opentelemetry::logs::Logger> delegate_logger,
opentelemetry::nostd::string_view event_domain) noexcept
: delegate_logger_(delegate_logger), event_domain_(event_domain)
: delegate_logger_(std::move(delegate_logger)), event_domain_(event_domain)
{}

const opentelemetry::nostd::string_view EventLogger::GetName() noexcept
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/logs/logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Logger::Logger(
std::unique_ptr<instrumentationscope::InstrumentationScope> instrumentation_scope) noexcept
: logger_name_(std::string(name)),
instrumentation_scope_(std::move(instrumentation_scope)),
context_(context)
context_(std::move(context))
{}

const opentelemetry::nostd::string_view Logger::GetName() noexcept
Expand Down
Loading

0 comments on commit b0edc69

Please sign in to comment.