Skip to content

Commit

Permalink
Merge branch 'main' into feat_thread_instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff authored Dec 9, 2024
2 parents d5f1075 + 762b73d commit eedde5c
Show file tree
Hide file tree
Showing 90 changed files with 2,119 additions and 653 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/cppcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ jobs:
- name: Count warnings
run: |
set +e
COUNT=`grep -c -E "\[.+\]" cppcheck.log`
echo "cppcheck reported ${COUNT} warning(s)"
# TODO: uncomment to enforce failing the build
# if [ $COUNT -ne 0 ] ; then exit 1 ; fi
readonly WARNING_COUNT=`grep -c -E "\[.+\]" cppcheck.log`
echo "cppcheck reported ${WARNING_COUNT} warning(s)"
# Acceptable limit, to decrease over time down to 0
readonly WARNING_LIMIT=10
# FAIL the build if WARNING_COUNT > WARNING_LIMIT
if [ $WARNING_COUNT -gt $WARNING_LIMIT ] ; then
exit 1
# WARN in annotations if WARNING_COUNT > 0
elif [ $WARNING_COUNT -gt 0 ] ; then
echo "::warning::cppcheck reported ${WARNING_COUNT} warning(s)"
fi
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ Increment the:
* [bazel] Update opentelemetry-proto in MODULE.bazel
[#3163](https://github.com/open-telemetry/opentelemetry-cpp/pull/3163)

* [EXPORTER] Fix scope attributes missing from otlp traces metrics
[#3185](https://github.com/open-telemetry/opentelemetry-cpp/pull/3185)

Important changes:

* [API] Jaeger Propagator should not be deprecated
Expand Down
37 changes: 24 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.9)
cmake_minimum_required(VERSION 3.10)

# See https://cmake.org/cmake/help/v3.3/policy/CMP0057.html required by certain
# versions of gtest
cmake_policy(SET CMP0057 NEW)

# See https://cmake.org/cmake/help/v3.12/policy/CMP0074.html required by certain
# version of zlib which CURL depends on.
# See https://cmake.org/cmake/help/latest/policy/CMP0074.html required by
# certain version of zlib which CURL depends on.
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12")
cmake_policy(SET CMP0074 NEW)
endif()

# Allow to use normal variable for option()
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13")
cmake_policy(SET CMP0077 NEW)
endif()

# Prefer CMAKE_MSVC_RUNTIME_LIBRARY if possible
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif()

# MSVC RTTI flag /GR should not be not added to CMAKE_CXX_FLAGS by default. @see
# https://cmake.org/cmake/help/latest/policy/CMP0117.html
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.20.0")
cmake_policy(SET CMP0117 NEW)
endif()

project(opentelemetry-cpp)

# Mark variables as used so cmake doesn't complain about them
Expand Down Expand Up @@ -421,12 +428,16 @@ if(WITH_OTLP_GRPC
endif()
# Latest Protobuf imported targets and without legacy module support
if(TARGET protobuf::protoc)
project_build_tools_get_imported_location(PROTOBUF_PROTOC_EXECUTABLE
protobuf::protoc)
# If protobuf::protoc is not a imported target, then we use the target
# directly for fallback
if(NOT PROTOBUF_PROTOC_EXECUTABLE)
set(PROTOBUF_PROTOC_EXECUTABLE protobuf::protoc)
if(CMAKE_CROSSCOMPILING AND Protobuf_PROTOC_EXECUTABLE)
set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
else()
project_build_tools_get_imported_location(PROTOBUF_PROTOC_EXECUTABLE
protobuf::protoc)
# If protobuf::protoc is not a imported target, then we use the target
# directly for fallback
if(NOT PROTOBUF_PROTOC_EXECUTABLE)
set(PROTOBUF_PROTOC_EXECUTABLE protobuf::protoc)
endif()
endif()
elseif(Protobuf_PROTOC_EXECUTABLE)
# Some versions of FindProtobuf.cmake uses mixed case instead of uppercase
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/baggage/baggage_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ inline nostd::shared_ptr<Baggage> GetBaggage(const context::Context &context) no
}

inline context::Context SetBaggage(context::Context &context,
nostd::shared_ptr<Baggage> baggage) noexcept
const nostd::shared_ptr<Baggage> &baggage) noexcept
{
return context.SetValue(kBaggageHeader, baggage);
}
Expand Down
36 changes: 21 additions & 15 deletions api/include/opentelemetry/context/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@ class Context
// hold a shared_ptr to the head of the DataList linked list
template <class T>
Context(const T &keys_and_values) noexcept
{
head_ = nostd::shared_ptr<DataList>{new DataList(keys_and_values)};
}
: head_{nostd::shared_ptr<DataList>{new DataList(keys_and_values)}}
{}

// Creates a context object from a key and value, this will
// hold a shared_ptr to the head of the DataList linked list
Context(nostd::string_view key, ContextValue value) noexcept
{
head_ = nostd::shared_ptr<DataList>{new DataList(key, value)};
}
: head_{nostd::shared_ptr<DataList>{new DataList(key, value)}}
{}

// Accepts a new iterable and then returns a new context that
// contains the new key and value data. It attaches the
Expand Down Expand Up @@ -92,22 +90,21 @@ class Context

private:
// A linked list to contain the keys and values of this context node
class DataList
struct DataList
{
public:
char *key_;
char *key_ = nullptr;

nostd::shared_ptr<DataList> next_;
nostd::shared_ptr<DataList> next_{nullptr};

size_t key_length_;
size_t key_length_ = 0UL;

ContextValue value_;

DataList() { next_ = nullptr; }
DataList() = default;

// Builds a data list off of a key and value iterable and returns the head
template <class T>
DataList(const T &keys_and_vals) : key_{nullptr}, next_(nostd::shared_ptr<DataList>{nullptr})
DataList(const T &keys_and_vals)
{
bool first = true;
auto *node = this;
Expand All @@ -132,9 +129,18 @@ class Context
{
key_ = new char[key.size()];
key_length_ = key.size();
memcpy(key_, key.data(), key.size() * sizeof(char));
value_ = value;
std::memcpy(key_, key.data(), key.size() * sizeof(char));
next_ = nostd::shared_ptr<DataList>{nullptr};
value_ = value;
}

DataList(const DataList &other)
: key_(new char[other.key_length_]),
next_(other.next_),
key_length_(other.key_length_),
value_(other.value_)
{
std::memcpy(key_, other.key_, other.key_length_ * sizeof(char));
}

DataList &operator=(DataList &&other) noexcept
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class OPENTELEMETRY_EXPORT GlobalTextMapPropagator
return nostd::shared_ptr<TextMapPropagator>(GetPropagator());
}

static void SetGlobalPropagator(nostd::shared_ptr<TextMapPropagator> prop) noexcept
static void SetGlobalPropagator(const nostd::shared_ptr<TextMapPropagator> &prop) noexcept
{
std::lock_guard<common::SpinLockMutex> guard(GetLock());
GetPropagator() = prop;
Expand Down
3 changes: 2 additions & 1 deletion api/include/opentelemetry/context/runtime_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ class OPENTELEMETRY_EXPORT RuntimeContext
*
* @param storage a custom runtime context storage
*/
static void SetRuntimeContextStorage(nostd::shared_ptr<RuntimeContextStorage> storage) noexcept
static void SetRuntimeContextStorage(
const nostd::shared_ptr<RuntimeContextStorage> &storage) noexcept
{
GetStorage() = storage;
}
Expand Down
4 changes: 2 additions & 2 deletions api/include/opentelemetry/logs/event_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace logs
class EventId
{
public:
EventId(int64_t id, nostd::string_view name) noexcept : id_{id}
EventId(int64_t id, nostd::string_view name) noexcept
: id_{id}, name_{nostd::unique_ptr<char[]>{new char[name.length() + 1]}}
{
name_ = nostd::unique_ptr<char[]>{new char[name.length() + 1]};
std::copy(name.begin(), name.end(), name_.get());
name_.get()[name.length()] = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions api/include/opentelemetry/logs/provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class OPENTELEMETRY_EXPORT Provider
/**
* Changes the singleton LoggerProvider.
*/
static void SetLoggerProvider(nostd::shared_ptr<LoggerProvider> tp) noexcept
static void SetLoggerProvider(const nostd::shared_ptr<LoggerProvider> &tp) noexcept
{
std::lock_guard<common::SpinLockMutex> guard(GetLock());
GetProvider() = tp;
Expand All @@ -60,7 +60,7 @@ class OPENTELEMETRY_EXPORT Provider
/**
* Changes the singleton EventLoggerProvider.
*/
static void SetEventLoggerProvider(nostd::shared_ptr<EventLoggerProvider> tp) noexcept
static void SetEventLoggerProvider(const nostd::shared_ptr<EventLoggerProvider> &tp) noexcept
{
std::lock_guard<common::SpinLockMutex> guard(GetLock());
GetEventProvider() = tp;
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/metrics/provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Provider
/**
* Changes the singleton MeterProvider.
*/
static void SetMeterProvider(nostd::shared_ptr<MeterProvider> tp) noexcept
static void SetMeterProvider(const nostd::shared_ptr<MeterProvider> &tp) noexcept
{
std::lock_guard<common::SpinLockMutex> guard(GetLock());
GetProvider() = tp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ template <class ReturnType, class FunctionObject, std::size_t... BoundIndices>
struct MakeVisitationMatrix<ReturnType, FunctionObject, index_sequence<>,
index_sequence<BoundIndices...>> {
using ResultType = ReturnType (*)(FunctionObject&&);
// cppcheck-suppress [duplInheritedMember]
static constexpr ResultType Run() {
return &call_with_indices<ReturnType, FunctionObject,
(BoundIndices - 1)...>;
Expand Down Expand Up @@ -722,6 +723,7 @@ struct VariantCoreAccess {
Self* self, Args&&... args) {
Destroy(*self);
using New = typename absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative<NewIndex, Self>::type;
// cppcheck-suppress [legacyUninitvar]
New* const result = ::new (static_cast<void*>(&self->state_))
New(absl::OTABSL_OPTION_NAMESPACE_NAME::forward<Args>(args)...);
self->index_ = NewIndex;
Expand Down Expand Up @@ -1310,6 +1312,7 @@ class VariantStateBaseDestructorNontrivial : protected VariantStateBase<T...> {
VariantStateBaseDestructorNontrivial* self;
};

// cppcheck-suppress [duplInheritedMember]
void destroy() { VisitIndices<sizeof...(T)>::Run(Destroyer{this}, index_); }

~VariantStateBaseDestructorNontrivial() { destroy(); }
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/nostd/shared_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class shared_ptr

struct alignas(kAlignment) PlacementBuffer
{
char data[kMaxSize];
char data[kMaxSize]{};
};

class shared_ptr_wrapper
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/plugin/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DynamicLibraryHandle;
class Span final : public trace::Span
{
public:
Span(std::shared_ptr<trace::Tracer> &&tracer, nostd::shared_ptr<trace::Span> span) noexcept
Span(std::shared_ptr<trace::Tracer> &&tracer, const nostd::shared_ptr<trace::Span> &span) noexcept
: tracer_{std::move(tracer)}, span_{span}
{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ static constexpr const char *kCicdPipelineRunId = "cicd.pipeline.run.id";

/**
* The human readable name of a task within a pipeline. Task here most closely aligns with a <a
* href="https://en.wikipedia.org/wiki/Pipeline_(computing)">computing process</a> in a pipeline.
* Other terms for tasks include commands, steps, and procedures.
* href="https://wikipedia.org/wiki/Pipeline_(computing)">computing process</a> in a pipeline. Other
* terms for tasks include commands, steps, and procedures.
*/
static constexpr const char *kCicdPipelineTaskName = "cicd.pipeline.task.name";

Expand All @@ -42,8 +42,8 @@ static constexpr const char *kCicdPipelineTaskName = "cicd.pipeline.task.name";
static constexpr const char *kCicdPipelineTaskRunId = "cicd.pipeline.task.run.id";

/**
* The <a href="https://en.wikipedia.org/wiki/URL">URL</a> of the pipeline run providing the
* complete address in order to locate and identify the pipeline run.
* The <a href="https://wikipedia.org/wiki/URL">URL</a> of the pipeline run providing the complete
* address in order to locate and identify the pipeline run.
*/
static constexpr const char *kCicdPipelineTaskRunUrlFull = "cicd.pipeline.task.run.url.full";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ static constexpr const char *kCloudfoundryAppId = "cloudfoundry.app.id";
* The index of the application instance. 0 when just one instance is active.
* <p>
* CloudFoundry defines the @code instance_id @endcode in the <a
* href="https://github.com/cloudfoundry/loggregator-api#v2-envelope">Loggegator v2 envelope</a>. It
* is used for logs and metrics emitted by CloudFoundry. It is supposed to contain the application
* instance index for applications deployed on the runtime. <p> Application instrumentation should
* use the value from environment variable @code CF_INSTANCE_INDEX @endcode.
* href="https://github.com/cloudfoundry/loggregator-api#v2-envelope">Loggregator v2 envelope</a>.
* It is used for logs and metrics emitted by CloudFoundry. It is
* supposed to contain the application instance index for applications
* deployed on the runtime.
* <p>
* Application instrumentation should use the value from environment
* variable @code CF_INSTANCE_INDEX @endcode.
*/
static constexpr const char *kCloudfoundryAppInstanceId = "cloudfoundry.app.instance.id";

Expand Down
42 changes: 42 additions & 0 deletions api/include/opentelemetry/semconv/incubating/container_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,48 @@ CreateAsyncDoubleMetricContainerNetworkIo(metrics::Meter *meter)
kMetricContainerNetworkIo, descrMetricContainerNetworkIo, unitMetricContainerNetworkIo);
}

/**
* The time the container has been running
* <p>
* Instrumentations SHOULD use a gauge with type @code double @endcode and measure uptime in seconds
* as a floating point number with the highest precision available. The actual accuracy would depend
* on the instrumentation and operating system. <p> gauge
*/
static constexpr const char *kMetricContainerUptime = "metric.container.uptime";
static constexpr const char *descrMetricContainerUptime = "The time the container has been running";
static constexpr const char *unitMetricContainerUptime = "s";

#if OPENTELEMETRY_ABI_VERSION_NO >= 2

static inline nostd::unique_ptr<metrics::Gauge<int64_t>> CreateSyncInt64MetricContainerUptime(
metrics::Meter *meter)
{
return meter->CreateInt64Gauge(kMetricContainerUptime, descrMetricContainerUptime,
unitMetricContainerUptime);
}

static inline nostd::unique_ptr<metrics::Gauge<double>> CreateSyncDoubleMetricContainerUptime(
metrics::Meter *meter)
{
return meter->CreateDoubleGauge(kMetricContainerUptime, descrMetricContainerUptime,
unitMetricContainerUptime);
}
#endif /* OPENTELEMETRY_ABI_VERSION_NO */

static inline nostd::shared_ptr<metrics::ObservableInstrument>
CreateAsyncInt64MetricContainerUptime(metrics::Meter *meter)
{
return meter->CreateInt64ObservableGauge(kMetricContainerUptime, descrMetricContainerUptime,
unitMetricContainerUptime);
}

static inline nostd::shared_ptr<metrics::ObservableInstrument>
CreateAsyncDoubleMetricContainerUptime(metrics::Meter *meter)
{
return meter->CreateDoubleObservableGauge(kMetricContainerUptime, descrMetricContainerUptime,
unitMetricContainerUptime);
}

} // namespace container
} // namespace semconv
OPENTELEMETRY_END_NAMESPACE
Loading

0 comments on commit eedde5c

Please sign in to comment.