Skip to content

Commit 7bd5da2

Browse files
authored
[CODE HEALTH] Fix clang-tidy performance enum size warnings (open-telemetry#3923)
1 parent 6285a72 commit 7bd5da2

File tree

16 files changed

+62
-26
lines changed

16 files changed

+62
-26
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ Increment the:
4848
* [CODE HEALTH] Fix clang-tidy macro to enum warnings
4949
[#3922](https://github.com/open-telemetry/opentelemetry-cpp/pull/3922)
5050

51+
* [CODE HEALTH] Fix clang-tidy performance enum size warnings
52+
[#3923](https://github.com/open-telemetry/opentelemetry-cpp/pull/3923)
53+
5154
Important changes:
5255

5356
* [BUILD] Revisit EventLogger deprecation

api/include/opentelemetry/common/attribute_value.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ using AttributeValue =
5757
nostd::span<const uint64_t>,
5858
nostd::span<const uint8_t>>;
5959

60-
enum AttributeType
60+
#if OPENTELEMETRY_ABI_VERSION_NO >= 2
61+
enum AttributeType : std::uint8_t
62+
#else
63+
enum AttributeType // NOLINT(performance-enum-size)
64+
#endif
6165
{
6266
kTypeBool,
6367
kTypeInt,

api/include/opentelemetry/trace/span_metadata.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@
66
#include "opentelemetry/common/timestamp.h"
77
#include "opentelemetry/version.h"
88

9+
#if OPENTELEMETRY_ABI_VERSION_NO >= 2
10+
# include <cstdint>
11+
#endif
12+
913
OPENTELEMETRY_BEGIN_NAMESPACE
1014
namespace trace
1115
{
1216

13-
enum class SpanKind
17+
#if OPENTELEMETRY_ABI_VERSION_NO >= 2
18+
enum class SpanKind : std::uint8_t
19+
#else
20+
enum class SpanKind // NOLINT(performance-enum-size)
21+
#endif
1422
{
1523
kInternal,
1624
kServer,
@@ -24,7 +32,11 @@ constexpr char kSpanKey[] = "active_span";
2432
constexpr char kIsRootSpanKey[] = "is_root_span";
2533

2634
// StatusCode - Represents the canonical set of status codes of a finished Span.
27-
enum class StatusCode
35+
#if OPENTELEMETRY_ABI_VERSION_NO >= 2
36+
enum class StatusCode : std::uint8_t
37+
#else
38+
enum class StatusCode // NOLINT(performance-enum-size)
39+
#endif
2840
{
2941
kUnset, // default status
3042
kOk, // Operation has completed successfully.

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#pragma once
55

6+
#include <cstdint>
7+
68
#include "opentelemetry/nostd/string_view.h"
79
#include "opentelemetry/version.h"
810

@@ -12,14 +14,14 @@ namespace exporter
1214
namespace otlp
1315
{
1416

15-
enum class JsonBytesMappingKind
17+
enum class JsonBytesMappingKind : std::uint8_t
1618
{
1719
kHexId,
1820
kHex,
1921
kBase64,
2022
};
2123

22-
enum class HttpRequestContentType
24+
enum class HttpRequestContentType : std::uint8_t
2325
{
2426
kJson,
2527
kBinary,

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_preferred_temporality.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
#pragma once
5+
6+
#include <cstdint>
7+
58
#include "opentelemetry/version.h"
69

710
OPENTELEMETRY_BEGIN_NAMESPACE
@@ -10,7 +13,7 @@ namespace exporter
1013
namespace otlp
1114
{
1215

13-
enum class PreferredAggregationTemporality
16+
enum class PreferredAggregationTemporality : std::uint8_t
1417
{
1518
kUnspecified,
1619
kDelta,

exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter_options.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#pragma once
55

6+
#include <cstdint>
7+
68
#include "opentelemetry/ext/http/client/http_client_factory.h"
79
#include "opentelemetry/ext/http/common/url_parser.h"
810
#include "opentelemetry/sdk/common/env_variables.h"
@@ -26,7 +28,7 @@ inline const std::string GetDefaultZipkinEndpoint()
2628
return exists ? endpoint : kZipkinEndpointDefault;
2729
}
2830

29-
enum class TransportFormat
31+
enum class TransportFormat : std::uint8_t
3032
{
3133
kJson,
3234
kProtobuf

ext/include/opentelemetry/ext/http/client/http_client.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55

66
#include <chrono>
7+
#include <cstdint>
78
#include <cstring>
89
#include <map>
910
#include <memory>
@@ -67,7 +68,7 @@ namespace http
6768
namespace client
6869
{
6970

70-
enum class Method
71+
enum class Method : std::uint8_t
7172
{
7273
Get,
7374
Post,
@@ -78,7 +79,7 @@ enum class Method
7879
Delete
7980
};
8081

81-
enum class SessionState
82+
enum class SessionState : std::uint8_t
8283
{
8384
CreateFailed, // session create failed
8485
Created, // session created
@@ -97,7 +98,7 @@ enum class SessionState
9798
Cancelled // (manually) cancelled
9899
};
99100

100-
enum class Compression
101+
enum class Compression : std::uint8_t
101102
{
102103
kNone,
103104
kGzip

ext/include/opentelemetry/ext/http/server/http_server.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#pragma once
55

6+
#include <cstdint>
67
#include <functional>
78
#include <list>
89
#include <map>
@@ -95,7 +96,7 @@ class HttpServer : private SocketTools::Reactor::SocketCallback
9596
SocketTools::Socket socket;
9697
std::string receiveBuffer;
9798
std::string sendBuffer;
98-
enum
99+
enum : std::uint8_t
99100
{
100101
Idle,
101102
ReceivingHeaders,

ext/include/opentelemetry/ext/http/server/socket_tools.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <atomic>
77
#include <cassert>
88
#include <cstddef>
9+
#include <cstdint>
910
#include <cstring>
1011
#include <iostream>
1112
#include <map>
@@ -405,7 +406,7 @@ struct Socket
405406
#endif
406407
}
407408

408-
enum
409+
enum // NOLINT(performance-enum-size)
409410
{
410411
#ifdef _WIN32
411412
ErrorWouldBlock = WSAEWOULDBLOCK
@@ -414,7 +415,7 @@ struct Socket
414415
#endif
415416
};
416417

417-
enum
418+
enum // NOLINT(performance-enum-size)
418419
{
419420
#ifdef _WIN32
420421
ShutdownReceive = SD_RECEIVE,
@@ -469,7 +470,7 @@ struct Reactor : protected common::Thread
469470
/// <summary>
470471
/// Socket State
471472
/// </summary>
472-
enum State
473+
enum State : std::uint8_t
473474
{
474475
Readable = 1,
475476
Writable = 2,

sdk/include/opentelemetry/sdk/common/attribute_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ using OwnedAttributeValue = nostd::variant<bool,
4949
std::vector<uint64_t>,
5050
std::vector<uint8_t>>;
5151

52-
enum OwnedAttributeType
52+
enum OwnedAttributeType : std::uint8_t
5353
{
5454
kTypeBool,
5555
kTypeInt,

0 commit comments

Comments
 (0)