Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/clang-tidy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
matrix:
include:
- cmake_options: all-options-abiv1-preview
warning_limit: 113
warning_limit: 83
- cmake_options: all-options-abiv2-preview
warning_limit: 124
warning_limit: 86
env:
CC: /usr/bin/clang-22
CXX: /usr/bin/clang++-22
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ Increment the:
* [CONFIGURATION/BUILD] Add resource detector targets and README
[#4430](https://github.com/open-telemetry/opentelemetry-cpp/pull/4430)

* [CODE HEALTH] Resolve multiple clang tidy warnings
[#4492](https://github.com/open-telemetry/opentelemetry-cpp/pull/4492)

* [SDK] `OTELResourceDetector` now percent-decodes values parsed from the
`OTEL_RESOURCE_ATTRIBUTES` environment variable, per the W3C Baggage value
grammar the resource spec defers to. A malformed escape sequence is left
Expand Down
4 changes: 2 additions & 2 deletions api/include/opentelemetry/common/attribute_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ using AttributeValue =
nostd::span<const uint8_t>>;

#if OPENTELEMETRY_ABI_VERSION_NO >= 2
enum AttributeType : std::uint8_t
enum AttributeType : std::uint8_t // NOLINT(cppcoreguidelines-use-enum-class)
#else
enum AttributeType // NOLINT(performance-enum-size)
enum AttributeType // NOLINT(performance-enum-size,cppcoreguidelines-use-enum-class)
#endif
{
kTypeBool,
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/nostd/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using Traits = std::char_traits<char>;
class string_view
{
public:
typedef std::size_t size_type;
using size_type = std::size_t;

static constexpr size_type npos = static_cast<size_type>(-1);

Expand Down
3 changes: 3 additions & 0 deletions api/include/opentelemetry/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
// Experimental: bound synchronous metric instruments (Counter, Histogram).
// This public API is available only in ABI v2 preview builds. Guard bound
// instrument code with OPENTELEMETRY_HAVE_METRICS_BOUND_INSTRUMENTS_PREVIEW.

// NOLINTBEGIN(cppcoreguidelines-macro-to-enum)
Comment thread
marcalff marked this conversation as resolved.
#if OPENTELEMETRY_ABI_VERSION_NO >= 2 && defined(ENABLE_METRICS_BOUND_INSTRUMENTS_PREVIEW)
# define OPENTELEMETRY_HAVE_METRICS_BOUND_INSTRUMENTS_PREVIEW 1
#endif
// NOLINTEND(cppcoreguidelines-macro-to-enum)
43 changes: 34 additions & 9 deletions examples/multi_processor/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <iostream>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -65,6 +64,38 @@ void CleanupTracer()
trace_sdk::Provider::SetTracerProvider(none);
}

opentelemetry::nostd::string_view SpanKindToString(trace_api::SpanKind kind)
{
switch (kind)
{
case trace_api::SpanKind::kInternal:
return "Internal";
case trace_api::SpanKind::kServer:
return "Server";
case trace_api::SpanKind::kClient:
return "Client";
case trace_api::SpanKind::kProducer:
return "Producer";
case trace_api::SpanKind::kConsumer:
return "Consumer";
}
return "Unknown";
}

opentelemetry::nostd::string_view StatusCodeToString(trace_api::StatusCode code)
{
switch (code)
{
case trace_api::StatusCode::kUnset:
return "Unset";
case trace_api::StatusCode::kOk:
return "Ok";
case trace_api::StatusCode::kError:
return "Error";
}
return "Unknown";
}

void dumpSpans(std::vector<std::unique_ptr<trace_sdk::SpanData>> &spans)
{
char span_buf[trace_api::SpanId::kSize * 2];
Expand All @@ -85,14 +116,8 @@ void dumpSpans(std::vector<std::unique_ptr<trace_sdk::SpanData>> &spans)
<< '\n';

std::cout << "\t\tDescription: " << span->GetDescription() << '\n';
std::cout << "\t\tSpan kind:"
<< static_cast<typename std::underlying_type<trace_api::SpanKind>::type>(
span->GetSpanKind())
<< '\n';
std::cout << "\t\tSpan Status: "
<< static_cast<typename std::underlying_type<trace_api::StatusCode>::type>(
span->GetStatus())
<< '\n';
std::cout << "\t\tSpan kind: " << SpanKindToString(span->GetSpanKind()) << '\n';
std::cout << "\t\tSpan Status: " << StatusCodeToString(span->GetStatus()) << '\n';
}
}
} // namespace
Expand Down
18 changes: 12 additions & 6 deletions exporters/otlp/test/otlp_grpc_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ using opentelemetry::sdk::common::setenv;
using opentelemetry::sdk::common::unsetenv;
# endif

# if defined(GRPC_CPP_VERSION_MAJOR) && \
(GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \
defined(GRPC_CALLBACK_API_NONEXPERIMENTAL)
# define OTELCPP_GRPC_ASYNC_API_IS_STABLE
# endif

using namespace testing;

OPENTELEMETRY_BEGIN_NAMESPACE
Expand All @@ -70,8 +76,7 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe
{
public:
// Some old toolchains can only use gRPC 1.33 and it's experimental.
# if defined(GRPC_CPP_VERSION_MAJOR) && \
(GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039
# if defined(OTELCPP_GRPC_ASYNC_API_IS_STABLE)
using async_interface_base =
proto::collector::trace::v1::TraceService::StubInterface::async_interface;
# else
Expand Down Expand Up @@ -104,9 +109,7 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe
}

// Some old toolchains can only use gRPC 1.33 and it's experimental.
# if defined(GRPC_CPP_VERSION_MAJOR) && \
(GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \
defined(GRPC_CALLBACK_API_NONEXPERIMENTAL)
# if defined(OTELCPP_GRPC_ASYNC_API_IS_STABLE)
void Export(
::grpc::ClientContext * /*context*/,
const ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest * /*request*/,
Expand All @@ -126,8 +129,11 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe
OtlpMockTraceServiceStub *stub_;
};

# if defined(OTELCPP_GRPC_ASYNC_API_IS_STABLE)
async_interface_base *async() override { return &async_interface_; }
async_interface_base *experimental_async() { return &async_interface_; }
# else
async_interface_base *experimental_async() override { return &async_interface_; }
# endif

::grpc::Status GetLastAsyncStatus() const noexcept { return last_async_status_; }

Expand Down
30 changes: 18 additions & 12 deletions exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ using opentelemetry::sdk::common::setenv;
using opentelemetry::sdk::common::unsetenv;
#endif

#if defined(GRPC_CPP_VERSION_MAJOR) && \
(GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \
defined(GRPC_CALLBACK_API_NONEXPERIMENTAL)
# define OTELCPP_GRPC_ASYNC_API_IS_STABLE
#endif

using namespace testing;

OPENTELEMETRY_BEGIN_NAMESPACE
Expand All @@ -80,8 +86,7 @@ namespace
class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceServiceStub
{
public:
#if defined(GRPC_CPP_VERSION_MAJOR) && \
(GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039
#if defined(OTELCPP_GRPC_ASYNC_API_IS_STABLE)
using async_interface_base =
proto::collector::trace::v1::TraceService::StubInterface::async_interface;
#else
Expand All @@ -106,9 +111,7 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe
callback(stub_->last_async_status_);
}

#if defined(GRPC_CPP_VERSION_MAJOR) && \
(GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \
defined(GRPC_CALLBACK_API_NONEXPERIMENTAL)
#if defined(OTELCPP_GRPC_ASYNC_API_IS_STABLE)
void Export(
::grpc::ClientContext * /*context*/,
const ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest * /*request*/,
Expand All @@ -128,8 +131,11 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe
OtlpMockTraceServiceStub *stub_;
};

#if defined(OTELCPP_GRPC_ASYNC_API_IS_STABLE)
async_interface_base *async() override { return &async_interface_; }
async_interface_base *experimental_async() { return &async_interface_; }
#else
async_interface_base *experimental_async() override { return &async_interface_; }
#endif

::grpc::Status GetLastAsyncStatus() const noexcept { return last_async_status_; }

Expand All @@ -141,8 +147,7 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe
class OtlpMockLogsServiceStub : public proto::collector::logs::v1::MockLogsServiceStub
{
public:
#if defined(GRPC_CPP_VERSION_MAJOR) && \
(GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039
#if defined(OTELCPP_GRPC_ASYNC_API_IS_STABLE)
using async_interface_base =
proto::collector::logs::v1::LogsService::StubInterface::async_interface;
#else
Expand All @@ -167,9 +172,7 @@ class OtlpMockLogsServiceStub : public proto::collector::logs::v1::MockLogsServi
callback(stub_->last_async_status_);
}

#if defined(GRPC_CPP_VERSION_MAJOR) && \
(GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \
defined(GRPC_CALLBACK_API_NONEXPERIMENTAL)
#if defined(OTELCPP_GRPC_ASYNC_API_IS_STABLE)
void Export(
::grpc::ClientContext * /*context*/,
const ::opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest * /*request*/,
Expand All @@ -189,8 +192,11 @@ class OtlpMockLogsServiceStub : public proto::collector::logs::v1::MockLogsServi
OtlpMockLogsServiceStub *stub_;
};

#if defined(OTELCPP_GRPC_ASYNC_API_IS_STABLE)
async_interface_base *async() override { return &async_interface_; }
async_interface_base *experimental_async() { return &async_interface_; }
#else
async_interface_base *experimental_async() override { return &async_interface_; }
#endif

::grpc::Status GetLastAsyncStatus() const noexcept { return last_async_status_; }

Expand Down
2 changes: 1 addition & 1 deletion ext/include/opentelemetry/ext/http/server/http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class HttpServer : private SocketTools::Reactor::SocketCallback
SocketTools::Socket socket;
std::string receiveBuffer;
std::string sendBuffer;
enum : std::uint8_t
enum : std::uint8_t // NOLINT(cppcoreguidelines-use-enum-class)
{
Idle,
ReceivingHeaders,
Expand Down
10 changes: 5 additions & 5 deletions ext/include/opentelemetry/ext/http/server/socket_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@ static_assert(sizeof(SocketAddr) == sizeof(sockaddr),
struct Socket
{
#ifdef _WIN32
typedef SOCKET Type;
using Type = SOCKET;
static Type const Invalid = INVALID_SOCKET;
#else
typedef int Type;
using Type = int;
static Type const Invalid = -1;
#endif

Expand Down Expand Up @@ -465,7 +465,7 @@ struct Socket
#endif
}

enum // NOLINT(performance-enum-size)
enum // NOLINT(performance-enum-size,cppcoreguidelines-use-enum-class)
{
#ifdef _WIN32
ErrorWouldBlock = WSAEWOULDBLOCK
Expand All @@ -474,7 +474,7 @@ struct Socket
#endif
};

enum // NOLINT(performance-enum-size)
enum // NOLINT(performance-enum-size,cppcoreguidelines-use-enum-class)
{
#ifdef _WIN32
ShutdownReceive = SD_RECEIVE,
Expand Down Expand Up @@ -527,7 +527,7 @@ struct Reactor : protected common::Thread
/// <summary>
/// Socket State
/// </summary>
enum State : std::uint8_t
enum State : std::uint8_t // NOLINT(cppcoreguidelines-use-enum-class)
{
Readable = 1,
Writable = 2,
Expand Down
2 changes: 1 addition & 1 deletion functional/otlp/func_grpc_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ static int parse_args(int argc, char *argv[])
return 0;
}

typedef int (*test_func_t)();
using test_func_t = int (*)();

struct test_case
{
Expand Down
4 changes: 2 additions & 2 deletions functional/otlp/func_http_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const int TEST_FAILED = 1;

namespace
{
enum test_mode : std::uint8_t
enum test_mode : std::uint8_t // NOLINT(cppcoreguidelines-use-enum-class)
{
MODE_NONE,
MODE_HTTP,
Expand Down Expand Up @@ -335,7 +335,7 @@ static int parse_args(int argc, char *argv[])
return 0;
}

typedef int (*test_func_t)();
using test_func_t = int (*)();

struct test_case
{
Expand Down
9 changes: 5 additions & 4 deletions resource_detectors/test/service_detector_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ TEST(ServiceDetectorUtilsTest, GetServiceNameFallbackUsesUnknownServicePrefix)
{
unsetenv(kOtelServiceName);

const std::string service_name = detail::GetServiceName();
if (service_name.rfind("unknown_service:", 0) == 0)
const std::string service_name = detail::GetServiceName();
const std::string unknown_service_prefix = "unknown_service:";
if (service_name.substr(0, unknown_service_prefix.size()) == unknown_service_prefix)
{
EXPECT_GT(service_name.size(), std::string{"unknown_service:"}.size());
EXPECT_GT(service_name.size(), unknown_service_prefix.size());
Comment on lines +45 to +49

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is this due to abseil-string-find-startswith? Maybe we could just disable the rule similar to abseil-string-find-str-contains since the rule suggests using abseil helpers which we don't have here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good feedback! Yes I think it is better to disable the abseil-string-find-startswith check. This check will come back in the modernize form once building with c++20

}
else
{
EXPECT_EQ(service_name, std::string{"unknown_service"});
EXPECT_EQ(service_name, "unknown_service");
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/include/opentelemetry/sdk/common/attribute_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ using OwnedAttributeValue = nostd::variant<bool,
std::vector<uint64_t>,
std::vector<uint8_t>>;

enum OwnedAttributeType : std::uint8_t
enum OwnedAttributeType : std::uint8_t // NOLINT(cppcoreguidelines-use-enum-class)
{
kTypeBool,
kTypeInt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ class ReservoirCell
friend class ReservoirCellTestPeer;
};

typedef std::shared_ptr<ExemplarData> (ReservoirCell::*MapAndResetCellType)(
const MetricAttributes &);
using MapAndResetCellType =
std::shared_ptr<ExemplarData> (ReservoirCell::*)(const MetricAttributes &);

} // namespace metrics
} // namespace sdk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
#ifdef OPENTELEMETRY_HAVE_METRICS_BOUND_INSTRUMENTS_PREVIEW
// Resolve via the unified cardinality policy so unbound and bound paths
// share one combined limit (see ResolveCardinality()).
MetricAttributes resolved = ResolveCardinality(std::move(attr));
MetricAttributes resolved = ResolveCardinality(attr);
// cppcheck-suppress accessMoved
attributes_hashmap_->GetOrSetDefault(std::move(resolved), create_default_aggregation_)
->Aggregate(value);
Expand Down Expand Up @@ -176,7 +176,7 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
MetricAttributes attr{attributes, attributes_processor_.get()};
std::lock_guard<std::mutex> guard(attribute_hashmap_lock_);
#ifdef OPENTELEMETRY_HAVE_METRICS_BOUND_INSTRUMENTS_PREVIEW
MetricAttributes resolved = ResolveCardinality(std::move(attr));
MetricAttributes resolved = ResolveCardinality(attr);
// cppcheck-suppress accessMoved
attributes_hashmap_->GetOrSetDefault(std::move(resolved), create_default_aggregation_)
->Aggregate(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ namespace metrics

using MetricAttributes = opentelemetry::sdk::metrics::FilteredOrderedAttributeMap;

typedef std::unordered_map<std::string,
bool,
opentelemetry::sdk::common::StringViewHash,
opentelemetry::sdk::common::StringViewEqual>
FilterAttributeMap;
using FilterAttributeMap = std::unordered_map<std::string,
bool,
opentelemetry::sdk::common::StringViewHash,
opentelemetry::sdk::common::StringViewEqual>;

/**
* The AttributesProcessor is responsible for customizing which
Expand Down
Loading
Loading