From ba0ebcd4622ff4989b517da502621274e017552a Mon Sep 17 00:00:00 2001 From: bm1549 Date: Sat, 21 Mar 2026 10:09:05 -0400 Subject: [PATCH] style: apply clang-format across entire codebase Run clang-format (Google style) on all .cpp and .h files to align existing code with the project's .clang-format configuration. This is primarily reference alignment changes (& placement) that were inconsistent with the configured Google style. 24 files, ~350 lines changed (net +17). Co-Authored-By: Claude Sonnet 4.6 (1M context) --- include/datadog/environment.h | 2 +- include/datadog/version.h | 4 +- src/datadog/common/hash.cpp | 58 ++++---- src/datadog/common/hash.h | 52 +++---- src/datadog/config_manager.h | 4 +- src/datadog/curl.cpp | 182 +++++++++++------------ src/datadog/curl.h | 84 +++++------ src/datadog/default_http_client_null.cpp | 4 +- src/datadog/environment.cpp | 8 +- src/datadog/null_logger.h | 6 +- src/datadog/parse_util.cpp | 14 +- src/datadog/platform_util_windows.cpp | 2 +- src/datadog/span_sampler_config.cpp | 36 ++--- src/datadog/trace_id.cpp | 8 +- src/datadog/trace_sampler_config.cpp | 30 ++-- src/datadog/tracer_config.cpp | 58 ++++---- test/mocks/dict_readers.h | 2 +- test/system-tests/utils.h | 2 +- test/test_cerr_logger.cpp | 10 +- test/test_curl.cpp | 84 ++++++----- test/test_span.cpp | 4 +- test/test_trace_id.cpp | 6 +- test/test_trace_segment.cpp | 4 +- test/test_tracer.cpp | 23 ++- 24 files changed, 352 insertions(+), 335 deletions(-) diff --git a/include/datadog/environment.h b/include/datadog/environment.h index f2846b37..5806edc2 100644 --- a/include/datadog/environment.h +++ b/include/datadog/environment.h @@ -95,7 +95,7 @@ enum Variable { DD_LIST_ENVIRONMENT_VARIABLES(WITH_COMMA) }; #define QUOTED_WITH_COMMA(ARG, TYPE, DEFAULT_VALUE) \ WITH_COMMA(QUOTED(ARG), TYPE, DEFAULT_VALUE) -inline const char *const variable_names[] = { +inline const char* const variable_names[] = { DD_LIST_ENVIRONMENT_VARIABLES(QUOTED_WITH_COMMA)}; #undef QUOTED diff --git a/include/datadog/version.h b/include/datadog/version.h index 3d118073..9ae344b7 100644 --- a/include/datadog/version.h +++ b/include/datadog/version.h @@ -8,12 +8,12 @@ namespace tracing { // The release version at or before this code revision, e.g. "v0.1.12". // That is, this code is at least as recent as `tracer_version`, but may be // more recent. -extern const char *const tracer_version; +extern const char* const tracer_version; // A string literal that contains `tracer_version` but also is easier to `grep` // from the output of the `strings` command line utility, e.g. "[dd-trace-cpp // version v0.1.12]". -extern const char *const tracer_version_string; +extern const char* const tracer_version_string; } // namespace tracing } // namespace datadog diff --git a/src/datadog/common/hash.cpp b/src/datadog/common/hash.cpp index dcf5736f..01e35b62 100644 --- a/src/datadog/common/hash.cpp +++ b/src/datadog/common/hash.cpp @@ -12,17 +12,17 @@ constexpr bool ALLOW_UNALIGNED_READS = true; namespace datadog::common { namespace details { -void SpookyHash::Short(const void *message, size_t length, uint64 *hash1, - uint64 *hash2) { +void SpookyHash::Short(const void* message, size_t length, uint64* hash1, + uint64* hash2) { uint64 buf[2 * sc_numVars]; union { - const uint8 *p8; - uint32 *p32; - uint64 *p64; + const uint8* p8; + uint32* p32; + uint64* p64; size_t i; } u; - u.p8 = (const uint8 *)message; + u.p8 = (const uint8*)message; if constexpr (!ALLOW_UNALIGNED_READS && (u.i & 0x7)) { memcpy(buf, message, length); @@ -36,7 +36,7 @@ void SpookyHash::Short(const void *message, size_t length, uint64 *hash1, uint64 d = sc_const; if (length > 15) { - const uint64 *end = u.p64 + (length / 32) * 4; + const uint64* end = u.p64 + (length / 32) * 4; // handle all complete sets of 32 bytes for (; u.p64 < end; u.p64 += 4) { @@ -116,8 +116,8 @@ void SpookyHash::Short(const void *message, size_t length, uint64 *hash1, } // do the whole hash in one call -void SpookyHash::Hash128(const void *message, size_t length, uint64 *hash1, - uint64 *hash2) { +void SpookyHash::Hash128(const void* message, size_t length, uint64* hash1, + uint64* hash2) { if (length < sc_bufSize) { Short(message, length, hash1, hash2); return; @@ -125,10 +125,10 @@ void SpookyHash::Hash128(const void *message, size_t length, uint64 *hash1, uint64 h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11; uint64 buf[sc_numVars]; - uint64 *end; + uint64* end; union { - const uint8 *p8; - uint64 *p64; + const uint8* p8; + uint64* p64; size_t i; } u; size_t remainder; @@ -137,7 +137,7 @@ void SpookyHash::Hash128(const void *message, size_t length, uint64 *hash1, h1 = h4 = h7 = h10 = *hash2; h2 = h5 = h8 = h11 = sc_const; - u.p8 = (const uint8 *)message; + u.p8 = (const uint8*)message; end = u.p64 + (length / sc_blockSize) * sc_numVars; // handle all whole sc_blockSize blocks of bytes @@ -155,10 +155,10 @@ void SpookyHash::Hash128(const void *message, size_t length, uint64 *hash1, } // handle the last partial block of sc_blockSize bytes - remainder = (length - ((const uint8 *)end - (const uint8 *)message)); + remainder = (length - ((const uint8*)end - (const uint8*)message)); memcpy(buf, end, remainder); - memset(((uint8 *)buf) + remainder, 0, sc_blockSize - remainder); - ((uint8 *)buf)[sc_blockSize - 1] = remainder; + memset(((uint8*)buf) + remainder, 0, sc_blockSize - remainder); + ((uint8*)buf)[sc_blockSize - 1] = remainder; // do some final mixing End(buf, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); @@ -175,20 +175,20 @@ void SpookyHash::Init(uint64 seed1, uint64 seed2) { } // add a message fragment to the state -void SpookyHash::Update(const void *message, size_t length) { +void SpookyHash::Update(const void* message, size_t length) { uint64 h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11; size_t newLength = length + m_remainder; uint8 remainder; union { - const uint8 *p8; - uint64 *p64; + const uint8* p8; + uint64* p64; size_t i; } u; - const uint64 *end; + const uint64* end; // Is this message fragment too short? If it is, stuff it away. if (newLength < sc_bufSize) { - memcpy(&((uint8 *)m_data)[m_remainder], message, length); + memcpy(&((uint8*)m_data)[m_remainder], message, length); m_length = length + m_length; m_remainder = (uint8)newLength; return; @@ -218,19 +218,19 @@ void SpookyHash::Update(const void *message, size_t length) { // if we've got anything stuffed away, use it now if (m_remainder) { uint8 prefix = sc_bufSize - m_remainder; - memcpy(&(((uint8 *)m_data)[m_remainder]), message, prefix); + memcpy(&(((uint8*)m_data)[m_remainder]), message, prefix); u.p64 = m_data; Mix(u.p64, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); Mix(&u.p64[sc_numVars], h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); - u.p8 = ((const uint8 *)message) + prefix; + u.p8 = ((const uint8*)message) + prefix; length -= prefix; } else { - u.p8 = (const uint8 *)message; + u.p8 = (const uint8*)message; } // handle all whole blocks of sc_blockSize bytes end = u.p64 + (length / sc_blockSize) * sc_numVars; - remainder = (uint8)(length - ((const uint8 *)end - u.p8)); + remainder = (uint8)(length - ((const uint8*)end - u.p8)); if constexpr (ALLOW_UNALIGNED_READS || (u.i & 0x7) == 0) { while (u.p64 < end) { Mix(u.p64, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); @@ -264,7 +264,7 @@ void SpookyHash::Update(const void *message, size_t length) { } // report the hash for the concatenation of all message fragments so far -void SpookyHash::Final(uint64 *hash1, uint64 *hash2) { +void SpookyHash::Final(uint64* hash1, uint64* hash2) { // init the variables if (m_length < sc_bufSize) { *hash1 = m_state[0]; @@ -273,7 +273,7 @@ void SpookyHash::Final(uint64 *hash1, uint64 *hash2) { return; } - const uint64 *data = (const uint64 *)m_data; + const uint64* data = (const uint64*)m_data; uint8 remainder = m_remainder; uint64 h0 = m_state[0]; @@ -297,9 +297,9 @@ void SpookyHash::Final(uint64 *hash1, uint64 *hash2) { } // mix in the last partial block, and the length mod sc_blockSize - memset(&((uint8 *)data)[remainder], 0, (sc_blockSize - remainder)); + memset(&((uint8*)data)[remainder], 0, (sc_blockSize - remainder)); - ((uint8 *)data)[sc_blockSize - 1] = remainder; + ((uint8*)data)[sc_blockSize - 1] = remainder; // do some final mixing End(data, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); diff --git a/src/datadog/common/hash.h b/src/datadog/common/hash.h index 3d2155d8..c179740d 100644 --- a/src/datadog/common/hash.h +++ b/src/datadog/common/hash.h @@ -54,15 +54,15 @@ class SpookyHash { // // SpookyHash: hash a single message in one call, produce 128-bit output // - static void Hash128(const void *message, // message to hash + static void Hash128(const void* message, // message to hash size_t length, // length of message in bytes - uint64 *hash1, // in/out: in seed 1, out hash value 1 - uint64 *hash2); // in/out: in seed 2, out hash value 2 + uint64* hash1, // in/out: in seed 1, out hash value 1 + uint64* hash2); // in/out: in seed 2, out hash value 2 // // Hash64: hash a single message in one call, return 64-bit output // - static uint64 Hash64(const void *message, // message to hash + static uint64 Hash64(const void* message, // message to hash size_t length, // length of message in bytes uint64 seed) // seed { @@ -74,7 +74,7 @@ class SpookyHash { // // Hash32: hash a single message in one call, produce 32-bit output // - static uint32 Hash32(const void *message, // message to hash + static uint32 Hash32(const void* message, // message to hash size_t length, // length of message in bytes uint32 seed) // seed { @@ -92,7 +92,7 @@ class SpookyHash { // // Update: add a piece of a message to a SpookyHash state // - void Update(const void *message, // message fragment + void Update(const void* message, // message fragment size_t length); // length of message fragment in bytes // @@ -103,8 +103,8 @@ class SpookyHash { // The result is the same as if SpookyHash() had been called with // all the pieces concatenated into one message. // - void Final(uint64 *hash1, // out only: first 64 bits of hash value. - uint64 *hash2); // out only: second 64 bits of hash value. + void Final(uint64* hash1, // out only: first 64 bits of hash value. + uint64* hash2); // out only: second 64 bits of hash value. // // left rotate a 64-bit value by k bytes @@ -126,10 +126,10 @@ class SpookyHash { // When run forward or backwards one Mix // I tried 3 pairs of each; they all differed by at least 212 bits. // - static INLINE void Mix(const uint64 *data, uint64 &s0, uint64 &s1, uint64 &s2, - uint64 &s3, uint64 &s4, uint64 &s5, uint64 &s6, - uint64 &s7, uint64 &s8, uint64 &s9, uint64 &s10, - uint64 &s11) { + static INLINE void Mix(const uint64* data, uint64& s0, uint64& s1, uint64& s2, + uint64& s3, uint64& s4, uint64& s5, uint64& s6, + uint64& s7, uint64& s8, uint64& s9, uint64& s10, + uint64& s11) { s0 += data[0]; s2 ^= s10; s11 ^= s0; @@ -208,10 +208,10 @@ class SpookyHash { // Two iterations was almost good enough for a 64-bit result, but a // 128-bit result is reported, so End() does three iterations. // - static INLINE void EndPartial(uint64 &h0, uint64 &h1, uint64 &h2, uint64 &h3, - uint64 &h4, uint64 &h5, uint64 &h6, uint64 &h7, - uint64 &h8, uint64 &h9, uint64 &h10, - uint64 &h11) { + static INLINE void EndPartial(uint64& h0, uint64& h1, uint64& h2, uint64& h3, + uint64& h4, uint64& h5, uint64& h6, uint64& h7, + uint64& h8, uint64& h9, uint64& h10, + uint64& h11) { h11 += h1; h2 ^= h11; h1 = Rot64(h1, 44); @@ -250,10 +250,10 @@ class SpookyHash { h0 = Rot64(h0, 54); } - static INLINE void End(const uint64 *data, uint64 &h0, uint64 &h1, uint64 &h2, - uint64 &h3, uint64 &h4, uint64 &h5, uint64 &h6, - uint64 &h7, uint64 &h8, uint64 &h9, uint64 &h10, - uint64 &h11) { + static INLINE void End(const uint64* data, uint64& h0, uint64& h1, uint64& h2, + uint64& h3, uint64& h4, uint64& h5, uint64& h6, + uint64& h7, uint64& h8, uint64& h9, uint64& h10, + uint64& h11) { h0 += data[0]; h1 += data[1]; h2 += data[2]; @@ -286,7 +286,7 @@ class SpookyHash { // with diffs defined by either xor or subtraction // with a base of all zeros plus a counter, or plus another bit, or random // - static INLINE void ShortMix(uint64 &h0, uint64 &h1, uint64 &h2, uint64 &h3) { + static INLINE void ShortMix(uint64& h0, uint64& h1, uint64& h2, uint64& h3) { h2 = Rot64(h2, 50); h2 += h3; h0 ^= h2; @@ -337,7 +337,7 @@ class SpookyHash { // For every pair of input bits, // with probability 50 +- .75% (the worst case is approximately that) // - static INLINE void ShortEnd(uint64 &h0, uint64 &h1, uint64 &h2, uint64 &h3) { + static INLINE void ShortEnd(uint64& h0, uint64& h1, uint64& h2, uint64& h3) { h3 ^= h2; h2 = Rot64(h2, 15); h3 += h2; @@ -381,10 +381,10 @@ class SpookyHash { // held to the same quality bar. // static void Short( - const void *message, // message (array of bytes, not necessarily aligned) + const void* message, // message (array of bytes, not necessarily aligned) size_t length, // length of message (in bytes) - uint64 *hash1, // in/out: in the seed, out the hash value - uint64 *hash2); // in/out: in the seed, out the hash value + uint64* hash1, // in/out: in the seed, out the hash value + uint64* hash2); // in/out: in the seed, out the hash value // number of uint64's in internal state static const size_t sc_numVars = 12; @@ -430,7 +430,7 @@ class FastHash final { /// /// @param data Pointer to the data to hash. /// @param length Size of the data in bytes. - void append(const void *data, size_t length) { hasher_.Update(data, length); } + void append(const void* data, size_t length) { hasher_.Update(data, length); } /// Finalizes the hash computation and returns a 64-bit hash value. /// diff --git a/src/datadog/config_manager.h b/src/datadog/config_manager.h index 997f4036..01ad479a 100644 --- a/src/datadog/config_manager.h +++ b/src/datadog/config_manager.h @@ -82,7 +82,7 @@ class ConfigManager : public remote_config::Listener { public: ConfigManager(const FinalizedTracerConfig& config); - ~ConfigManager() override{}; + ~ConfigManager() override {}; remote_config::Products get_products() override; remote_config::Capabilities get_capabilities() override; @@ -90,7 +90,7 @@ class ConfigManager : public remote_config::Listener { Optional on_update( const Listener::Configuration& config) override; void on_revert(const Listener::Configuration& config) override; - void on_post_process() override{}; + void on_post_process() override {}; // Return the `TraceSampler` consistent with the most recent configuration. std::shared_ptr trace_sampler(); diff --git a/src/datadog/curl.cpp b/src/datadog/curl.cpp index e8f40783..c40be4b2 100644 --- a/src/datadog/curl.cpp +++ b/src/datadog/curl.cpp @@ -31,75 +31,75 @@ CurlLibrary libcurl; } // namespace -CURL *CurlLibrary::easy_init() { return curl_easy_init(); } +CURL* CurlLibrary::easy_init() { return curl_easy_init(); } -void CurlLibrary::easy_cleanup(CURL *handle) { curl_easy_cleanup(handle); } +void CurlLibrary::easy_cleanup(CURL* handle) { curl_easy_cleanup(handle); } -CURLcode CurlLibrary::easy_getinfo_private(CURL *curl, char **user_data) { +CURLcode CurlLibrary::easy_getinfo_private(CURL* curl, char** user_data) { return curl_easy_getinfo(curl, CURLINFO_PRIVATE, user_data); } -CURLcode CurlLibrary::easy_getinfo_response_code(CURL *curl, long *code) { +CURLcode CurlLibrary::easy_getinfo_response_code(CURL* curl, long* code) { return curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, code); } -CURLcode CurlLibrary::easy_setopt_errorbuffer(CURL *handle, char *buffer) { +CURLcode CurlLibrary::easy_setopt_errorbuffer(CURL* handle, char* buffer) { return curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, buffer); } -CURLcode CurlLibrary::easy_setopt_headerdata(CURL *handle, void *data) { +CURLcode CurlLibrary::easy_setopt_headerdata(CURL* handle, void* data) { return curl_easy_setopt(handle, CURLOPT_HEADERDATA, data); } -CURLcode CurlLibrary::easy_setopt_headerfunction(CURL *handle, +CURLcode CurlLibrary::easy_setopt_headerfunction(CURL* handle, HeaderCallback on_header) { return curl_easy_setopt(handle, CURLOPT_HEADERFUNCTION, on_header); } -CURLcode CurlLibrary::easy_setopt_httpheader(CURL *handle, - curl_slist *headers) { +CURLcode CurlLibrary::easy_setopt_httpheader(CURL* handle, + curl_slist* headers) { return curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); } -CURLcode CurlLibrary::easy_setopt_post(CURL *handle, long post) { +CURLcode CurlLibrary::easy_setopt_post(CURL* handle, long post) { return curl_easy_setopt(handle, CURLOPT_POST, post); } -CURLcode CurlLibrary::easy_setopt_postfields(CURL *handle, const char *data) { +CURLcode CurlLibrary::easy_setopt_postfields(CURL* handle, const char* data) { return curl_easy_setopt(handle, CURLOPT_POSTFIELDS, data); } -CURLcode CurlLibrary::easy_setopt_postfieldsize(CURL *handle, long size) { +CURLcode CurlLibrary::easy_setopt_postfieldsize(CURL* handle, long size) { return curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, size); } -CURLcode CurlLibrary::easy_setopt_private(CURL *handle, void *pointer) { +CURLcode CurlLibrary::easy_setopt_private(CURL* handle, void* pointer) { return curl_easy_setopt(handle, CURLOPT_PRIVATE, pointer); } -CURLcode CurlLibrary::easy_setopt_unix_socket_path(CURL *handle, - const char *path) { +CURLcode CurlLibrary::easy_setopt_unix_socket_path(CURL* handle, + const char* path) { return curl_easy_setopt(handle, CURLOPT_UNIX_SOCKET_PATH, path); } -CURLcode CurlLibrary::easy_setopt_url(CURL *handle, const char *url) { +CURLcode CurlLibrary::easy_setopt_url(CURL* handle, const char* url) { return curl_easy_setopt(handle, CURLOPT_URL, url); } -CURLcode CurlLibrary::easy_setopt_writedata(CURL *handle, void *data) { +CURLcode CurlLibrary::easy_setopt_writedata(CURL* handle, void* data) { return curl_easy_setopt(handle, CURLOPT_WRITEDATA, data); } -CURLcode CurlLibrary::easy_setopt_writefunction(CURL *handle, +CURLcode CurlLibrary::easy_setopt_writefunction(CURL* handle, WriteCallback on_write) { return curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, on_write); } -CURLcode CurlLibrary::easy_setopt_timeout_ms(CURL *handle, long timeout_ms) { +CURLcode CurlLibrary::easy_setopt_timeout_ms(CURL* handle, long timeout_ms) { return curl_easy_setopt(handle, CURLOPT_TIMEOUT_MS, timeout_ms); } -const char *CurlLibrary::easy_strerror(CURLcode error) { +const char* CurlLibrary::easy_strerror(CURLcode error) { return curl_easy_strerror(error); } @@ -109,51 +109,51 @@ CURLcode CurlLibrary::global_init(long flags) { return curl_global_init(flags); } -CURLMcode CurlLibrary::multi_add_handle(CURLM *multi_handle, - CURL *easy_handle) { +CURLMcode CurlLibrary::multi_add_handle(CURLM* multi_handle, + CURL* easy_handle) { return curl_multi_add_handle(multi_handle, easy_handle); } -CURLMcode CurlLibrary::multi_cleanup(CURLM *multi_handle) { +CURLMcode CurlLibrary::multi_cleanup(CURLM* multi_handle) { return curl_multi_cleanup(multi_handle); } -CURLMsg *CurlLibrary::multi_info_read(CURLM *multi_handle, int *msgs_in_queue) { +CURLMsg* CurlLibrary::multi_info_read(CURLM* multi_handle, int* msgs_in_queue) { return curl_multi_info_read(multi_handle, msgs_in_queue); } -CURLM *CurlLibrary::multi_init() { return curl_multi_init(); } +CURLM* CurlLibrary::multi_init() { return curl_multi_init(); } -CURLMcode CurlLibrary::multi_perform(CURLM *multi_handle, - int *running_handles) { +CURLMcode CurlLibrary::multi_perform(CURLM* multi_handle, + int* running_handles) { return curl_multi_perform(multi_handle, running_handles); } -CURLMcode CurlLibrary::multi_poll(CURLM *multi_handle, curl_waitfd extra_fds[], +CURLMcode CurlLibrary::multi_poll(CURLM* multi_handle, curl_waitfd extra_fds[], unsigned extra_nfds, int timeout_ms, - int *numfds) { + int* numfds) { return curl_multi_poll(multi_handle, extra_fds, extra_nfds, timeout_ms, numfds); } -CURLMcode CurlLibrary::multi_remove_handle(CURLM *multi_handle, - CURL *easy_handle) { +CURLMcode CurlLibrary::multi_remove_handle(CURLM* multi_handle, + CURL* easy_handle) { return curl_multi_remove_handle(multi_handle, easy_handle); } -const char *CurlLibrary::multi_strerror(CURLMcode error) { +const char* CurlLibrary::multi_strerror(CURLMcode error) { return curl_multi_strerror(error); } -CURLMcode CurlLibrary::multi_wakeup(CURLM *multi_handle) { +CURLMcode CurlLibrary::multi_wakeup(CURLM* multi_handle) { return curl_multi_wakeup(multi_handle); } -curl_slist *CurlLibrary::slist_append(curl_slist *list, const char *string) { +curl_slist* CurlLibrary::slist_append(curl_slist* list, const char* string) { return curl_slist_append(list, string); } -void CurlLibrary::slist_free_all(curl_slist *list) { +void CurlLibrary::slist_free_all(curl_slist* list) { curl_slist_free_all(list); } @@ -164,20 +164,20 @@ using URL = HTTPClient::URL; class CurlImpl { std::mutex mutex_; - CurlLibrary &curl_; + CurlLibrary& curl_; const std::shared_ptr logger_; Clock clock_; - CURLM *multi_handle_; - std::unordered_set request_handles_; - std::list new_handles_; + CURLM* multi_handle_; + std::unordered_set request_handles_; + std::list new_handles_; bool shutting_down_; int num_active_handles_; std::condition_variable no_requests_; std::thread event_loop_; struct Request { - CurlLibrary *curl = nullptr; - curl_slist *request_headers = nullptr; + CurlLibrary* curl = nullptr; + curl_slist* request_headers = nullptr; std::string request_body; ResponseHandler on_response; ErrorHandler on_error; @@ -190,45 +190,45 @@ class CurlImpl { }; class HeaderWriter : public DictWriter { - curl_slist *list_ = nullptr; + curl_slist* list_ = nullptr; std::string buffer_; - CurlLibrary &curl_; + CurlLibrary& curl_; public: - explicit HeaderWriter(CurlLibrary &curl); + explicit HeaderWriter(CurlLibrary& curl); ~HeaderWriter(); - curl_slist *release(); + curl_slist* release(); void set(StringView key, StringView value) override; }; class HeaderReader : public DictReader { - std::unordered_map *response_headers_lower_; + std::unordered_map* response_headers_lower_; mutable std::string buffer_; public: explicit HeaderReader( - std::unordered_map *response_headers_lower); + std::unordered_map* response_headers_lower); Optional lookup(StringView key) const override; - void visit(const std::function - &visitor) const override; + void visit(const std::function& + visitor) const override; }; void run(); - void handle_message(const CURLMsg &); + void handle_message(const CURLMsg&); CURLcode log_on_error(CURLcode result); CURLMcode log_on_error(CURLMcode result); - static std::size_t on_read_header(char *data, std::size_t, std::size_t length, - void *user_data); - static std::size_t on_read_body(char *data, std::size_t, std::size_t length, - void *user_data); + static std::size_t on_read_header(char* data, std::size_t, std::size_t length, + void* user_data); + static std::size_t on_read_body(char* data, std::size_t, std::size_t length, + void* user_data); public: - explicit CurlImpl(const std::shared_ptr &, const Clock &, - CurlLibrary &, const Curl::ThreadGenerator &); + explicit CurlImpl(const std::shared_ptr&, const Clock&, CurlLibrary&, + const Curl::ThreadGenerator&); ~CurlImpl(); - Expected post(const URL &url, HeadersSetter set_headers, + Expected post(const URL& url, HeadersSetter set_headers, std::string body, ResponseHandler on_response, ErrorHandler on_error, std::chrono::steady_clock::time_point deadline); @@ -248,21 +248,21 @@ void throw_on_error(CURLcode result) { } // namespace -Curl::Curl(const std::shared_ptr &logger, const Clock &clock) +Curl::Curl(const std::shared_ptr& logger, const Clock& clock) : Curl(logger, clock, libcurl) {} -Curl::Curl(const std::shared_ptr &logger, const Clock &clock, - CurlLibrary &curl) +Curl::Curl(const std::shared_ptr& logger, const Clock& clock, + CurlLibrary& curl) : Curl(logger, clock, curl, - [](auto &&func) { return std::thread(std::move(func)); }) {} + [](auto&& func) { return std::thread(std::move(func)); }) {} -Curl::Curl(const std::shared_ptr &logger, const Clock &clock, - CurlLibrary &curl, const Curl::ThreadGenerator &make_thread) +Curl::Curl(const std::shared_ptr& logger, const Clock& clock, + CurlLibrary& curl, const Curl::ThreadGenerator& make_thread) : impl_(new CurlImpl{logger, clock, curl, make_thread}) {} Curl::~Curl() { delete impl_; } -Expected Curl::post(const URL &url, HeadersSetter set_headers, +Expected Curl::post(const URL& url, HeadersSetter set_headers, std::string body, ResponseHandler on_response, ErrorHandler on_error, std::chrono::steady_clock::time_point deadline) { @@ -277,8 +277,8 @@ std::string Curl::config() const { return nlohmann::json::object({{"type", "datadog::tracing::Curl"}}).dump(); } -CurlImpl::CurlImpl(const std::shared_ptr &logger, const Clock &clock, - CurlLibrary &curl, const Curl::ThreadGenerator &make_thread) +CurlImpl::CurlImpl(const std::shared_ptr& logger, const Clock& clock, + CurlLibrary& curl, const Curl::ThreadGenerator& make_thread) : curl_(curl), logger_(logger), clock_(clock), @@ -295,7 +295,7 @@ CurlImpl::CurlImpl(const std::shared_ptr &logger, const Clock &clock, try { event_loop_ = make_thread([this]() { run(); }); - } catch (const std::system_error &error) { + } catch (const std::system_error& error) { logger_->log_error( Error{Error::CURL_HTTP_CLIENT_SETUP_FAILED, error.what()}); @@ -327,7 +327,7 @@ CurlImpl::~CurlImpl() { } Expected CurlImpl::post( - const HTTPClient::URL &url, HeadersSetter set_headers, std::string body, + const HTTPClient::URL& url, HeadersSetter set_headers, std::string body, ResponseHandler on_response, ErrorHandler on_error, std::chrono::steady_clock::time_point deadline) try { if (multi_handle_ == nullptr) { @@ -404,11 +404,11 @@ Expected CurlImpl::post( } void CurlImpl::clear_requests() { - for (const auto &handle : request_handles_) { - char *user_data; + for (const auto& handle : request_handles_) { + char* user_data; if (log_on_error(curl_.easy_getinfo_private(handle, &user_data)) == CURLE_OK) { - delete reinterpret_cast(user_data); + delete reinterpret_cast(user_data); } log_on_error(curl_.multi_remove_handle(multi_handle_, handle)); @@ -430,9 +430,9 @@ void CurlImpl::drain(std::chrono::steady_clock::time_point deadline) { log_on_error(curl_.multi_wakeup(multi_handle_)); } -std::size_t CurlImpl::on_read_header(char *data, std::size_t, - std::size_t length, void *user_data) { - const auto request = static_cast(user_data); +std::size_t CurlImpl::on_read_header(char* data, std::size_t, + std::size_t length, void* user_data) { + const auto request = static_cast(user_data); // The idea is: // // " Foo-Bar : thingy, thingy, thing \r\n" @@ -460,9 +460,9 @@ std::size_t CurlImpl::on_read_header(char *data, std::size_t, return length; } -std::size_t CurlImpl::on_read_body(char *data, std::size_t, std::size_t length, - void *user_data) { - const auto request = static_cast(user_data); +std::size_t CurlImpl::on_read_body(char* data, std::size_t, std::size_t length, + void* user_data) { + const auto request = static_cast(user_data); request->response_body.append(data, length); return length; } @@ -488,11 +488,11 @@ void CurlImpl::run() { int num_messages_remaining = 0; bool shutting_down = false; - CURLMsg *message = nullptr; + CURLMsg* message = nullptr; constexpr int max_wait_milliseconds = 10'000; std::unique_lock lock(mutex_, std::defer_lock); - std::list handles_to_process; + std::list handles_to_process; while (true) { lock.lock(); @@ -509,15 +509,15 @@ void CurlImpl::run() { // New requests might have been added while we were sleeping. for (; !handles_to_process.empty(); handles_to_process.pop_front()) { - CURL *handle = handles_to_process.front(); - char *user_data; + CURL* handle = handles_to_process.front(); + char* user_data; if (log_on_error(curl_.easy_getinfo_private(handle, &user_data)) != CURLE_OK) { curl_.easy_cleanup(handle); continue; } - auto *request = reinterpret_cast(user_data); + auto* request = reinterpret_cast(user_data); const auto timeout = request->deadline - clock_().tick; if (timeout <= std::chrono::steady_clock::time_point::duration::zero()) { std::string error_message; @@ -566,18 +566,18 @@ void CurlImpl::run() { clear_requests(); } -void CurlImpl::handle_message(const CURLMsg &message) { +void CurlImpl::handle_message(const CURLMsg& message) { if (message.msg != CURLMSG_DONE) { return; } - auto *const request_handle = message.easy_handle; - char *user_data; + auto* const request_handle = message.easy_handle; + char* user_data; if (log_on_error(curl_.easy_getinfo_private(request_handle, &user_data)) != CURLE_OK) { return; } - auto &request = *reinterpret_cast(user_data); + auto& request = *reinterpret_cast(user_data); // `request` is done. If we got a response, then call the response // handler. If an error occurred, then call the error handler. @@ -609,11 +609,11 @@ void CurlImpl::handle_message(const CURLMsg &message) { CurlImpl::Request::~Request() { curl->slist_free_all(request_headers); } -CurlImpl::HeaderWriter::HeaderWriter(CurlLibrary &curl) : curl_(curl) {} +CurlImpl::HeaderWriter::HeaderWriter(CurlLibrary& curl) : curl_(curl) {} CurlImpl::HeaderWriter::~HeaderWriter() { curl_.slist_free_all(list_); } -curl_slist *CurlImpl::HeaderWriter::release() { +curl_slist* CurlImpl::HeaderWriter::release() { auto list = list_; list_ = nullptr; return list; @@ -629,7 +629,7 @@ void CurlImpl::HeaderWriter::set(StringView key, StringView value) { } CurlImpl::HeaderReader::HeaderReader( - std::unordered_map *response_headers_lower) + std::unordered_map* response_headers_lower) : response_headers_lower_(response_headers_lower) {} Optional CurlImpl::HeaderReader::lookup(StringView key) const { @@ -643,9 +643,9 @@ Optional CurlImpl::HeaderReader::lookup(StringView key) const { } void CurlImpl::HeaderReader::visit( - const std::function &visitor) + const std::function& visitor) const { - for (const auto &[key, value] : *response_headers_lower_) { + for (const auto& [key, value] : *response_headers_lower_) { visitor(key, value); } } diff --git a/src/datadog/curl.h b/src/datadog/curl.h index bbaf380a..4ab2fca1 100644 --- a/src/datadog/curl.h +++ b/src/datadog/curl.h @@ -35,66 +35,66 @@ namespace tracing { // tests override some of the member functions. class CurlLibrary { public: - typedef size_t (*WriteCallback)(char *ptr, size_t size, size_t nmemb, - void *userdata); - typedef size_t (*HeaderCallback)(char *buffer, size_t size, size_t nitems, - void *userdata); + typedef size_t (*WriteCallback)(char* ptr, size_t size, size_t nmemb, + void* userdata); + typedef size_t (*HeaderCallback)(char* buffer, size_t size, size_t nitems, + void* userdata); virtual ~CurlLibrary() = default; - virtual void easy_cleanup(CURL *handle); - virtual CURL *easy_init(); - virtual CURLcode easy_getinfo_private(CURL *curl, char **user_data); - virtual CURLcode easy_getinfo_response_code(CURL *curl, long *code); - virtual CURLcode easy_setopt_errorbuffer(CURL *handle, char *buffer); - virtual CURLcode easy_setopt_headerdata(CURL *handle, void *data); - virtual CURLcode easy_setopt_headerfunction(CURL *handle, HeaderCallback); - virtual CURLcode easy_setopt_httpheader(CURL *handle, curl_slist *headers); - virtual CURLcode easy_setopt_post(CURL *handle, long post); - virtual CURLcode easy_setopt_postfields(CURL *handle, const char *data); - virtual CURLcode easy_setopt_postfieldsize(CURL *handle, long size); - virtual CURLcode easy_setopt_private(CURL *handle, void *pointer); - virtual CURLcode easy_setopt_unix_socket_path(CURL *handle, const char *path); - virtual CURLcode easy_setopt_url(CURL *handle, const char *url); - virtual CURLcode easy_setopt_writedata(CURL *handle, void *data); - virtual CURLcode easy_setopt_writefunction(CURL *handle, WriteCallback); - virtual CURLcode easy_setopt_timeout_ms(CURL *handle, long timeout_ms); - virtual const char *easy_strerror(CURLcode error); + virtual void easy_cleanup(CURL* handle); + virtual CURL* easy_init(); + virtual CURLcode easy_getinfo_private(CURL* curl, char** user_data); + virtual CURLcode easy_getinfo_response_code(CURL* curl, long* code); + virtual CURLcode easy_setopt_errorbuffer(CURL* handle, char* buffer); + virtual CURLcode easy_setopt_headerdata(CURL* handle, void* data); + virtual CURLcode easy_setopt_headerfunction(CURL* handle, HeaderCallback); + virtual CURLcode easy_setopt_httpheader(CURL* handle, curl_slist* headers); + virtual CURLcode easy_setopt_post(CURL* handle, long post); + virtual CURLcode easy_setopt_postfields(CURL* handle, const char* data); + virtual CURLcode easy_setopt_postfieldsize(CURL* handle, long size); + virtual CURLcode easy_setopt_private(CURL* handle, void* pointer); + virtual CURLcode easy_setopt_unix_socket_path(CURL* handle, const char* path); + virtual CURLcode easy_setopt_url(CURL* handle, const char* url); + virtual CURLcode easy_setopt_writedata(CURL* handle, void* data); + virtual CURLcode easy_setopt_writefunction(CURL* handle, WriteCallback); + virtual CURLcode easy_setopt_timeout_ms(CURL* handle, long timeout_ms); + virtual const char* easy_strerror(CURLcode error); virtual void global_cleanup(); virtual CURLcode global_init(long flags); - virtual CURLMcode multi_add_handle(CURLM *multi_handle, CURL *easy_handle); - virtual CURLMcode multi_cleanup(CURLM *multi_handle); - virtual CURLMsg *multi_info_read(CURLM *multi_handle, int *msgs_in_queue); - virtual CURLM *multi_init(); - virtual CURLMcode multi_perform(CURLM *multi_handle, int *running_handles); - virtual CURLMcode multi_poll(CURLM *multi_handle, curl_waitfd extra_fds[], + virtual CURLMcode multi_add_handle(CURLM* multi_handle, CURL* easy_handle); + virtual CURLMcode multi_cleanup(CURLM* multi_handle); + virtual CURLMsg* multi_info_read(CURLM* multi_handle, int* msgs_in_queue); + virtual CURLM* multi_init(); + virtual CURLMcode multi_perform(CURLM* multi_handle, int* running_handles); + virtual CURLMcode multi_poll(CURLM* multi_handle, curl_waitfd extra_fds[], unsigned extra_nfds, int timeout_ms, - int *numfds); - virtual CURLMcode multi_remove_handle(CURLM *multi_handle, CURL *easy_handle); - virtual const char *multi_strerror(CURLMcode error); - virtual CURLMcode multi_wakeup(CURLM *multi_handle); - virtual curl_slist *slist_append(curl_slist *list, const char *string); - virtual void slist_free_all(curl_slist *list); + int* numfds); + virtual CURLMcode multi_remove_handle(CURLM* multi_handle, CURL* easy_handle); + virtual const char* multi_strerror(CURLMcode error); + virtual CURLMcode multi_wakeup(CURLM* multi_handle); + virtual curl_slist* slist_append(curl_slist* list, const char* string); + virtual void slist_free_all(curl_slist* list); }; class CurlImpl; class Logger; class Curl : public HTTPClient { - CurlImpl *impl_; + CurlImpl* impl_; public: - using ThreadGenerator = std::function &&)>; + using ThreadGenerator = std::function&&)>; - explicit Curl(const std::shared_ptr &, const Clock &); - Curl(const std::shared_ptr &, const Clock &, CurlLibrary &); - Curl(const std::shared_ptr &, const Clock &, CurlLibrary &, - const ThreadGenerator &); + explicit Curl(const std::shared_ptr&, const Clock&); + Curl(const std::shared_ptr&, const Clock&, CurlLibrary&); + Curl(const std::shared_ptr&, const Clock&, CurlLibrary&, + const ThreadGenerator&); ~Curl(); - Curl(const Curl &) = delete; + Curl(const Curl&) = delete; - Expected post(const URL &url, HeadersSetter set_headers, + Expected post(const URL& url, HeadersSetter set_headers, std::string body, ResponseHandler on_response, ErrorHandler on_error, std::chrono::steady_clock::time_point deadline) override; diff --git a/src/datadog/default_http_client_null.cpp b/src/datadog/default_http_client_null.cpp index b5a73ece..940daa22 100644 --- a/src/datadog/default_http_client_null.cpp +++ b/src/datadog/default_http_client_null.cpp @@ -9,8 +9,8 @@ namespace datadog { namespace tracing { -std::shared_ptr default_http_client(const std::shared_ptr &, - const Clock &) { +std::shared_ptr default_http_client(const std::shared_ptr&, + const Clock&) { return nullptr; } diff --git a/src/datadog/environment.cpp b/src/datadog/environment.cpp index 4dc3eb3f..ad6611f5 100644 --- a/src/datadog/environment.cpp +++ b/src/datadog/environment.cpp @@ -11,8 +11,8 @@ namespace environment { StringView name(Variable variable) { return variable_names[variable]; } Optional lookup(Variable variable) { - const char *name = variable_names[variable]; - const char *value = std::getenv(name); + const char* name = variable_names[variable]; + const char* value = std::getenv(name); if (!value) { return nullopt; } @@ -22,8 +22,8 @@ Optional lookup(Variable variable) { std::string to_json() { auto result = nlohmann::json::object({}); - for (const char *name : variable_names) { - if (const char *value = std::getenv(name)) { + for (const char* name : variable_names) { + if (const char* value = std::getenv(name)) { result[name] = value; } } diff --git a/src/datadog/null_logger.h b/src/datadog/null_logger.h index 2c55459c..73bb4918 100644 --- a/src/datadog/null_logger.h +++ b/src/datadog/null_logger.h @@ -14,10 +14,10 @@ namespace tracing { class NullLogger : public Logger { public: - void log_error(const LogFunc&) override{}; - void log_startup(const LogFunc&) override{}; + void log_error(const LogFunc&) override {}; + void log_startup(const LogFunc&) override {}; - void log_error(const Error&) override{}; + void log_error(const Error&) override {}; void log_error(StringView) override{}; }; diff --git a/src/datadog/parse_util.cpp b/src/datadog/parse_util.cpp index 60550115..48e63881 100644 --- a/src/datadog/parse_util.cpp +++ b/src/datadog/parse_util.cpp @@ -19,7 +19,7 @@ namespace { template Expected parse_integer(StringView input, int base, StringView kind) { Integer value; - const char *const end = input.data() + input.size(); + const char* const end = input.data() + input.size(); const auto status = std::from_chars(input.data(), end, value, base); if (status.ec == std::errc::invalid_argument) { std::string message; @@ -103,12 +103,12 @@ std::vector parse_list(StringView input) { return items; } - const char *const end = input.data() + input.size(); - const char *current = input.data(); + const char* const end = input.data() + input.size(); + const char* current = input.data(); - const char *begin_delim; + const char* begin_delim; do { - const char *begin_item = + const char* begin_item = std::find_if(current, end, [](uchar ch) { return !std::isspace(ch); }); begin_delim = std::find_if(begin_item, end, [](uchar ch) { return std::isspace(ch) || ch == ','; @@ -116,7 +116,7 @@ std::vector parse_list(StringView input) { items.emplace_back(begin_item, std::size_t(begin_delim - begin_item)); - const char *end_delim = std::find_if( + const char* end_delim = std::find_if( begin_delim, end, [](uchar ch) { return !std::isspace(ch); }); if (end_delim != end && *end_delim == ',') { @@ -136,7 +136,7 @@ Expected> parse_tags( std::string key; std::string value; - for (const StringView &token : list) { + for (const StringView& token : list) { const auto separator = token.find(':'); if (separator == std::string::npos) { diff --git a/src/datadog/platform_util_windows.cpp b/src/datadog/platform_util_windows.cpp index 38295df9..1cda0609 100644 --- a/src/datadog/platform_util_windows.cpp +++ b/src/datadog/platform_util_windows.cpp @@ -23,7 +23,7 @@ std::tuple get_windows_info() { // application manifest, which is the lowest version supported by the // application. Use `RtlGetVersion` to obtain the accurate OS version // regardless of the manifest. - using RtlGetVersion = auto(*)(LPOSVERSIONINFOEXW)->NTSTATUS; + using RtlGetVersion = auto (*)(LPOSVERSIONINFOEXW)->NTSTATUS; RtlGetVersion func = (RtlGetVersion)GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion"); diff --git a/src/datadog/span_sampler_config.cpp b/src/datadog/span_sampler_config.cpp index cf1b60fb..ef71d9b4 100644 --- a/src/datadog/span_sampler_config.cpp +++ b/src/datadog/span_sampler_config.cpp @@ -14,9 +14,9 @@ namespace datadog { namespace tracing { namespace { -std::string to_string(const std::vector &rules) { +std::string to_string(const std::vector& rules) { nlohmann::json res; - for (const auto &r : rules) { + for (const auto& r : rules) { nlohmann::json j = r; j["sample_rate"] = r.sample_rate; if (r.max_per_second) { @@ -37,7 +37,7 @@ Expected> parse_rules(StringView rules_raw, try { json_rules = nlohmann::json::parse(rules_raw); - } catch (const nlohmann::json::parse_error &error) { + } catch (const nlohmann::json::parse_error& error) { std::string message; message += "Unable to parse JSON from "; append(message, env_var); @@ -63,9 +63,9 @@ Expected> parse_rules(StringView rules_raw, const std::unordered_set allowed_properties{ "service", "name", "resource", "tags", "sample_rate", "max_per_second"}; - for (const auto &json_rule : json_rules) { + for (const auto& json_rule : json_rules) { auto matcher = from_json(json_rule); - if (auto *error = matcher.if_error()) { + if (auto* error = matcher.if_error()) { std::string prefix; prefix += "Unable to create a rule from "; append(prefix, env_var); @@ -118,7 +118,7 @@ Expected> parse_rules(StringView rules_raw, } // Look for unexpected properties. - for (const auto &[key, value] : json_rule.items()) { + for (const auto& [key, value] : json_rule.items()) { if (allowed_properties.count(key)) { continue; } @@ -143,14 +143,14 @@ Expected> parse_rules(StringView rules_raw, return rules; } -Expected load_span_sampler_env_config(Logger &logger) { +Expected load_span_sampler_env_config(Logger& logger) { SpanSamplerConfig env_config; auto rules_env = lookup(environment::DD_SPAN_SAMPLING_RULES); if (rules_env) { auto maybe_rules = parse_rules(*rules_env, name(environment::DD_SPAN_SAMPLING_RULES)); - if (auto *error = maybe_rules.if_error()) { + if (auto* error = maybe_rules.if_error()) { return std::move(*error); } env_config.rules = std::move(*maybe_rules); @@ -174,7 +174,7 @@ Expected load_span_sampler_env_config(Logger &logger) { } else { const auto span_rules_file = std::string(*file_env); - const auto file_error = [&](const char *operation) { + const auto file_error = [&](const char* operation) { std::string message; message += "Unable to "; message += operation; @@ -199,7 +199,7 @@ Expected load_span_sampler_env_config(Logger &logger) { auto maybe_rules = parse_rules( rules_stream.str(), name(environment::DD_SPAN_SAMPLING_RULES_FILE)); - if (auto *error = maybe_rules.if_error()) { + if (auto* error = maybe_rules.if_error()) { std::string prefix; prefix += "With "; append(prefix, name(environment::DD_SPAN_SAMPLING_RULES_FILE)); @@ -218,10 +218,10 @@ Expected load_span_sampler_env_config(Logger &logger) { } // namespace -SpanSamplerConfig::Rule::Rule(const SpanMatcher &base) : SpanMatcher(base) {} +SpanSamplerConfig::Rule::Rule(const SpanMatcher& base) : SpanMatcher(base) {} Expected finalize_config( - const SpanSamplerConfig &user_config, Logger &logger) { + const SpanSamplerConfig& user_config, Logger& logger) { Expected env_config = load_span_sampler_env_config(logger); if (auto error = env_config.if_error()) { return *error; @@ -239,13 +239,13 @@ Expected finalize_config( std::vector rules = resolve_and_record_config( env_rules, user_rules, &result.metadata, ConfigName::SPAN_SAMPLING_RULES, - nullptr, [](const std::vector &r) { + nullptr, [](const std::vector& r) { return to_string(r); }); - for (const auto &rule : rules) { + for (const auto& rule : rules) { auto maybe_rate = Rate::from(rule.sample_rate); - if (auto *error = maybe_rate.if_error()) { + if (auto* error = maybe_rate.if_error()) { std::string prefix; prefix += "Unable to parse sample_rate in span sampling rule with span " @@ -272,7 +272,7 @@ Expected finalize_config( } FinalizedSpanSamplerConfig::Rule finalized; - static_cast(finalized) = rule; + static_cast(finalized) = rule; finalized.sample_rate = *maybe_rate; finalized.max_per_second = rule.max_per_second; result.rules.push_back(std::move(finalized)); @@ -280,9 +280,9 @@ Expected finalize_config( return result; } -std::string to_string(const FinalizedSpanSamplerConfig::Rule &rule) { +std::string to_string(const FinalizedSpanSamplerConfig::Rule& rule) { // Get the base class's fields, then add our own. - nlohmann::json result = static_cast(rule); + nlohmann::json result = static_cast(rule); result["sample_rate"] = double(rule.sample_rate); if (rule.max_per_second) { result["max_per_second"] = *rule.max_per_second; diff --git a/src/datadog/trace_id.cpp b/src/datadog/trace_id.cpp index 4eaff241..d145c352 100644 --- a/src/datadog/trace_id.cpp +++ b/src/datadog/trace_id.cpp @@ -29,7 +29,7 @@ Expected TraceID::parse_hex(StringView input) { const auto parse_hex_piece = [input](StringView piece) -> Expected { auto result = parse_uint64(piece, 16); - if (auto *error = result.if_error()) { + if (auto* error = result.if_error()) { std::string prefix = "Unable to parse trace ID from \""; append(prefix, input); prefix += "\": "; @@ -42,7 +42,7 @@ Expected TraceID::parse_hex(StringView input) { // longer than that, then it will all fit in `TraceID::low`. if (input.size() <= 16) { auto result = parse_hex_piece(input); - if (auto *error = result.if_error()) { + if (auto* error = result.if_error()) { return std::move(*error); } return TraceID(*result); @@ -56,13 +56,13 @@ Expected TraceID::parse_hex(StringView input) { TraceID trace_id; auto result = parse_hex_piece(low_hex); - if (auto *error = result.if_error()) { + if (auto* error = result.if_error()) { return std::move(*error); } trace_id.low = *result; result = parse_hex_piece(high_hex); - if (auto *error = result.if_error()) { + if (auto* error = result.if_error()) { return std::move(*error); } trace_id.high = *result; diff --git a/src/datadog/trace_sampler_config.cpp b/src/datadog/trace_sampler_config.cpp index 698731db..c070264d 100644 --- a/src/datadog/trace_sampler_config.cpp +++ b/src/datadog/trace_sampler_config.cpp @@ -22,7 +22,7 @@ Expected load_trace_sampler_env_config() { nlohmann::json json_rules; try { json_rules = nlohmann::json::parse(*rules_env); - } catch (const nlohmann::json::parse_error &error) { + } catch (const nlohmann::json::parse_error& error) { std::string message; message += "Unable to parse JSON from "; append(message, name(environment::DD_TRACE_SAMPLING_RULES)); @@ -49,9 +49,9 @@ Expected load_trace_sampler_env_config() { const std::unordered_set allowed_properties{ "service", "name", "resource", "tags", "sample_rate"}; - for (const auto &json_rule : json_rules) { + for (const auto& json_rule : json_rules) { auto matcher = from_json(json_rule); - if (auto *error = matcher.if_error()) { + if (auto* error = matcher.if_error()) { std::string prefix; prefix += "Unable to create a rule from "; append(prefix, name(environment::DD_TRACE_SAMPLING_RULES)); @@ -84,7 +84,7 @@ Expected load_trace_sampler_env_config() { } // Look for unexpected properties. - for (const auto &[key, value] : json_rule.items()) { + for (const auto& [key, value] : json_rule.items()) { if (allowed_properties.count(key)) { continue; } @@ -109,7 +109,7 @@ Expected load_trace_sampler_env_config() { if (auto sample_rate_env = lookup(environment::DD_TRACE_SAMPLE_RATE)) { auto maybe_sample_rate = parse_double(*sample_rate_env); - if (auto *error = maybe_sample_rate.if_error()) { + if (auto* error = maybe_sample_rate.if_error()) { std::string prefix; prefix += "While parsing "; append(prefix, name(environment::DD_TRACE_SAMPLE_RATE)); @@ -121,7 +121,7 @@ Expected load_trace_sampler_env_config() { if (auto limit_env = lookup(environment::DD_TRACE_RATE_LIMIT)) { auto maybe_max_per_second = parse_double(*limit_env); - if (auto *error = maybe_max_per_second.if_error()) { + if (auto* error = maybe_max_per_second.if_error()) { std::string prefix; prefix += "While parsing "; append(prefix, name(environment::DD_TRACE_RATE_LIMIT)); @@ -134,9 +134,9 @@ Expected load_trace_sampler_env_config() { return env_config; } -std::string to_string(const std::vector &rules) { +std::string to_string(const std::vector& rules) { nlohmann::json res; - for (const auto &r : rules) { + for (const auto& r : rules) { auto j = nlohmann::json(static_cast(r)); j["sample_rate"] = r.sample_rate; res.emplace_back(std::move(j)); @@ -147,10 +147,10 @@ std::string to_string(const std::vector &rules) { } // namespace -TraceSamplerConfig::Rule::Rule(const SpanMatcher &base) : SpanMatcher(base) {} +TraceSamplerConfig::Rule::Rule(const SpanMatcher& base) : SpanMatcher(base) {} Expected finalize_config( - const TraceSamplerConfig &config) { + const TraceSamplerConfig& config) { Expected env_config = load_trace_sampler_env_config(); if (auto error = env_config.if_error()) { return *error; @@ -172,9 +172,9 @@ Expected finalize_config( ConfigMetadata::Origin::CODE)}; } - for (const auto &rule : rules) { + for (const auto& rule : rules) { auto maybe_rate = Rate::from(rule.sample_rate); - if (auto *error = maybe_rate.if_error()) { + if (auto* error = maybe_rate.if_error()) { std::string prefix; prefix += "Unable to parse sample_rate in trace sampling rule with root span " @@ -194,7 +194,7 @@ Expected finalize_config( Optional sample_rate = resolve_and_record_config( env_config->sample_rate, config.sample_rate, &result.metadata, ConfigName::TRACE_SAMPLING_RATE, 1.0, - [](const double &d) { return to_string(d, 1); }); + [](const double& d) { return to_string(d, 1); }); bool is_sample_rate_provided = env_config->sample_rate || config.sample_rate; // If `sample_rate` was specified, then it translates to a "catch-all" rule @@ -202,7 +202,7 @@ Expected finalize_config( // sample rate is valid. if (sample_rate && is_sample_rate_provided) { auto maybe_rate = Rate::from(*sample_rate); - if (auto *error = maybe_rate.if_error()) { + if (auto* error = maybe_rate.if_error()) { return error->with_prefix( "Unable to parse overall sample_rate for trace sampling: "); } @@ -217,7 +217,7 @@ Expected finalize_config( double max_per_second = resolve_and_record_config( env_config->max_per_second, config.max_per_second, &result.metadata, ConfigName::TRACE_SAMPLING_LIMIT, 100.0, - [](const double &d) { return std::to_string(d); }); + [](const double& d) { return std::to_string(d); }); const auto allowed_types = {FP_NORMAL, FP_SUBNORMAL}; if (!(max_per_second > 0) || diff --git a/src/datadog/tracer_config.cpp b/src/datadog/tracer_config.cpp index a10b17a8..834a0889 100644 --- a/src/datadog/tracer_config.cpp +++ b/src/datadog/tracer_config.cpp @@ -43,7 +43,7 @@ Expected> parse_propagation_styles( }; // Style names are separated by spaces, or a comma, or some combination. - for (const StringView &item : parse_list(input)) { + for (const StringView& item : parse_list(input)) { if (const auto style = parse_propagation_style(item)) { styles.push_back(*style); } else { @@ -76,7 +76,7 @@ Optional> styles_from_env( } auto styles = parse_propagation_styles(*styles_env); - if (auto *error = styles.if_error()) { + if (auto* error = styles.if_error()) { std::string prefix; prefix += "Unable to parse "; append(prefix, name(env_var)); @@ -92,7 +92,7 @@ std::string json_quoted(StringView text) { return nlohmann::json(std::move(unquoted)).dump(); } -Expected load_tracer_env_config(Logger &logger) { +Expected load_tracer_env_config(Logger& logger) { TracerConfig env_cfg; if (auto service_env = lookup(environment::DD_SERVICE)) { @@ -108,7 +108,7 @@ Expected load_tracer_env_config(Logger &logger) { if (auto tags_env = lookup(environment::DD_TAGS)) { auto tags = parse_tags(*tags_env); - if (auto *error = tags.if_error()) { + if (auto* error = tags.if_error()) { std::string prefix; prefix += "Unable to parse "; append(prefix, name(environment::DD_TAGS)); @@ -147,7 +147,7 @@ Expected load_tracer_env_config(Logger &logger) { if (auto baggage_items_env = lookup(environment::DD_TRACE_BAGGAGE_MAX_ITEMS)) { auto maybe_value = parse_uint64(*baggage_items_env, 10); - if (auto *error = maybe_value.if_error()) { + if (auto* error = maybe_value.if_error()) { return *error; } @@ -157,7 +157,7 @@ Expected load_tracer_env_config(Logger &logger) { if (auto baggage_bytes_env = lookup(environment::DD_TRACE_BAGGAGE_MAX_BYTES)) { auto maybe_value = parse_uint64(*baggage_bytes_env, 10); - if (auto *error = maybe_value.if_error()) { + if (auto* error = maybe_value.if_error()) { return *error; } @@ -216,7 +216,7 @@ Expected load_tracer_env_config(Logger &logger) { return message; }; - for (const auto &[var, var_override] : questionable_combinations) { + for (const auto& [var, var_override] : questionable_combinations) { const auto value = lookup(var); if (!value) { continue; @@ -257,7 +257,7 @@ Expected load_tracer_env_config(Logger &logger) { } else { env_cfg.injection_styles = global_styles; } - } catch (Error &error) { + } catch (Error& error) { return std::move(error); } @@ -266,12 +266,12 @@ Expected load_tracer_env_config(Logger &logger) { } // namespace -Expected finalize_config(const TracerConfig &config) { +Expected finalize_config(const TracerConfig& config) { return finalize_config(config, default_clock); } -Expected finalize_config(const TracerConfig &user_config, - const Clock &clock) { +Expected finalize_config(const TracerConfig& user_config, + const Clock& clock) { auto logger = user_config.logger ? user_config.logger : std::make_shared(); @@ -310,7 +310,7 @@ Expected finalize_config(const TracerConfig &user_config, final_config.defaults.tags = resolve_and_record_config( env_config->tags, user_config.tags, &final_config.metadata, ConfigName::TAGS, std::unordered_map{}, - [](const auto &tags) { return join_tags(tags); }); + [](const auto& tags) { return join_tags(tags); }); // Extraction Styles const std::vector default_propagation_styles{ @@ -321,7 +321,7 @@ Expected finalize_config(const TracerConfig &user_config, env_config->extraction_styles, user_config.extraction_styles, &final_config.metadata, ConfigName::EXTRACTION_STYLES, default_propagation_styles, - [](const std::vector &styles) { + [](const std::vector& styles) { return join_propagation_styles(styles); }); @@ -335,7 +335,7 @@ Expected finalize_config(const TracerConfig &user_config, env_config->injection_styles, user_config.injection_styles, &final_config.metadata, ConfigName::INJECTION_STYLES, default_propagation_styles, - [](const std::vector &styles) { + [](const std::vector& styles) { return join_propagation_styles(styles); }); @@ -348,13 +348,13 @@ Expected finalize_config(const TracerConfig &user_config, final_config.log_on_startup = resolve_and_record_config( env_config->log_on_startup, user_config.log_on_startup, &final_config.metadata, ConfigName::STARTUP_LOGS, true, - [](const bool &b) { return to_string(b); }); + [](const bool& b) { return to_string(b); }); // Report traces final_config.report_traces = resolve_and_record_config( env_config->report_traces, user_config.report_traces, &final_config.metadata, ConfigName::REPORT_TRACES, true, - [](const bool &b) { return to_string(b); }); + [](const bool& b) { return to_string(b); }); // Report hostname final_config.report_hostname = @@ -369,7 +369,7 @@ Expected finalize_config(const TracerConfig &user_config, env_config->generate_128bit_trace_ids, user_config.generate_128bit_trace_ids, &final_config.metadata, ConfigName::GENEREATE_128BIT_TRACE_IDS, true, - [](const bool &b) { return to_string(b); }); + [](const bool& b) { return to_string(b); }); // Integration name & version final_config.integration_name = value_or( @@ -382,13 +382,13 @@ Expected finalize_config(const TracerConfig &user_config, final_config.baggage_opts.max_items = resolve_and_record_config( env_config->baggage_max_items, user_config.baggage_max_items, &final_config.metadata, ConfigName::TRACE_BAGGAGE_MAX_ITEMS, 64UL, - [](const size_t &i) { return std::to_string(i); }); + [](const size_t& i) { return std::to_string(i); }); // Baggage - max bytes final_config.baggage_opts.max_bytes = resolve_and_record_config( env_config->baggage_max_bytes, user_config.baggage_max_bytes, &final_config.metadata, ConfigName::TRACE_BAGGAGE_MAX_BYTES, 8192UL, - [](const size_t &i) { return std::to_string(i); }); + [](const size_t& i) { return std::to_string(i); }); if (final_config.baggage_opts.max_items <= 0 || final_config.baggage_opts.max_bytes < 3) { @@ -411,14 +411,14 @@ Expected finalize_config(const TracerConfig &user_config, auto agent_finalized = finalize_config(user_config.agent, final_config.logger, clock); - if (auto *error = agent_finalized.if_error()) { + if (auto* error = agent_finalized.if_error()) { return std::move(*error); } if (auto trace_sampler_config = finalize_config(user_config.trace_sampler)) { // Merge metadata vectors - for (auto &[key, values] : trace_sampler_config->metadata) { - auto &dest = final_config.metadata[key]; + for (auto& [key, values] : trace_sampler_config->metadata) { + auto& dest = final_config.metadata[key]; dest.insert(dest.end(), values.begin(), values.end()); } final_config.trace_sampler = std::move(*trace_sampler_config); @@ -429,8 +429,8 @@ Expected finalize_config(const TracerConfig &user_config, if (auto span_sampler_config = finalize_config(user_config.span_sampler, *logger)) { // Merge metadata vectors - for (auto &[key, values] : span_sampler_config->metadata) { - auto &dest = final_config.metadata[key]; + for (auto& [key, values] : span_sampler_config->metadata) { + auto& dest = final_config.metadata[key]; dest.insert(dest.end(), values.begin(), values.end()); } final_config.span_sampler = std::move(*span_sampler_config); @@ -464,7 +464,7 @@ Expected finalize_config(const TracerConfig &user_config, final_config.tracing_enabled = resolve_and_record_config( env_config->tracing_enabled, user_config.tracing_enabled, &final_config.metadata, ConfigName::APM_TRACING_ENABLED, true, - [](const bool &b) { return to_string(b); }); + [](const bool& b) { return to_string(b); }); { // Resource Renaming Enabled @@ -472,7 +472,7 @@ Expected finalize_config(const TracerConfig &user_config, env_config->resource_renaming_enabled, user_config.resource_renaming_enabled, &final_config.metadata, ConfigName::TRACE_RESOURCE_RENAMING_ENABLED, false, - [](const bool &b) { return to_string(b); }); + [](const bool& b) { return to_string(b); }); // Resource Renaming Always Simplified Endpoint const bool resource_renaming_always_simplified_endpoint = @@ -481,7 +481,7 @@ Expected finalize_config(const TracerConfig &user_config, user_config.resource_renaming_always_simplified_endpoint, &final_config.metadata, ConfigName::TRACE_RESOURCE_RENAMING_ALWAYS_SIMPLIFIED_ENDPOINT, - false, [](const bool &b) { return to_string(b); }); + false, [](const bool& b) { return to_string(b); }); if (!resource_renaming_enabled) { final_config.resource_renaming_mode = @@ -511,8 +511,8 @@ Expected finalize_config(const TracerConfig &user_config, if (!user_config.collector) { final_config.collector = *agent_finalized; // Merge metadata vectors - for (auto &[key, values] : agent_finalized->metadata) { - auto &dest = final_config.metadata[key]; + for (auto& [key, values] : agent_finalized->metadata) { + auto& dest = final_config.metadata[key]; dest.insert(dest.end(), values.begin(), values.end()); } } else { diff --git a/test/mocks/dict_readers.h b/test/mocks/dict_readers.h index e7a162af..a0ceb33e 100644 --- a/test/mocks/dict_readers.h +++ b/test/mocks/dict_readers.h @@ -11,7 +11,7 @@ class MockDictReader : public DictReader { const std::unordered_map* map_; public: - MockDictReader() : map_(nullptr){}; + MockDictReader() : map_(nullptr) {}; explicit MockDictReader( const std::unordered_map& map) : map_(&map) {} diff --git a/test/system-tests/utils.h b/test/system-tests/utils.h index dd4a5c84..18a9cc29 100644 --- a/test/system-tests/utils.h +++ b/test/system-tests/utils.h @@ -58,7 +58,7 @@ class HeaderWriter final : public dd::DictWriter { nlohmann::json& j_; public: - HeaderWriter(nlohmann::json& headers) : j_(headers){}; + HeaderWriter(nlohmann::json& headers) : j_(headers) {}; ~HeaderWriter() = default; // Associate the specified `value` with the specified `key`. An diff --git a/test/test_cerr_logger.cpp b/test/test_cerr_logger.cpp index 472ae60b..3c1dc7b6 100644 --- a/test/test_cerr_logger.cpp +++ b/test/test_cerr_logger.cpp @@ -15,11 +15,11 @@ namespace { // Replace the `streambuf` associated with a specified `std::ios` for the // lifetime of this object. Restore the previous `streambuf` afterward. class StreambufGuard { - std::ios *stream_; - std::streambuf *buffer_; + std::ios* stream_; + std::streambuf* buffer_; public: - StreambufGuard(std::ios &stream, std::streambuf *buffer) + StreambufGuard(std::ios& stream, std::streambuf* buffer) : stream_(&stream), buffer_(stream.rdbuf()) { stream.rdbuf(buffer); } @@ -35,13 +35,13 @@ TEST_CASE("CerrLogger") { CerrLogger logger; SECTION("log_error func") { - logger.log_error([](std::ostream &stream) { stream << "hello!"; }); + logger.log_error([](std::ostream& stream) { stream << "hello!"; }); // Note the appended newline. REQUIRE(stream.str() == "hello!\n"); } SECTION("log_startup func") { - logger.log_startup([](std::ostream &stream) { stream << "hello!"; }); + logger.log_startup([](std::ostream& stream) { stream << "hello!"; }); REQUIRE(stream.str() == "hello!\n"); } diff --git a/test/test_curl.cpp b/test/test_curl.cpp index 3c88ef88..2796605d 100644 --- a/test/test_curl.cpp +++ b/test/test_curl.cpp @@ -20,11 +20,11 @@ using namespace datadog::tracing; class SingleRequestMockCurlLibrary : public CurlLibrary { public: - void *user_data_on_header_ = nullptr; + void* user_data_on_header_ = nullptr; HeaderCallback on_header_ = nullptr; - void *user_data_on_write_ = nullptr; + void* user_data_on_write_ = nullptr; WriteCallback on_write_ = nullptr; - CURL *added_handle_ = nullptr; + CURL* added_handle_ = nullptr; CURLMsg message_; enum class state { unknown, @@ -34,8 +34,8 @@ class SingleRequestMockCurlLibrary : public CurlLibrary { } state_ = state::unknown; // Since `SingleRequestMockCurlLibrary` supports at most one request, // `created_handles_` and `destroyed_handles_` will have size zero or one. - std::unordered_multiset created_handles_; - std::unordered_multiset destroyed_handles_; + std::unordered_multiset created_handles_; + std::unordered_multiset destroyed_handles_; // `message_result_` is the success/error code associated with the "done" // message sent to the event loop when the request has finished. CURLcode message_result_ = CURLE_OK; @@ -45,48 +45,48 @@ class SingleRequestMockCurlLibrary : public CurlLibrary { bool delay_message_ = false; std::function on_multi_perform = nullptr; - void easy_cleanup(CURL *handle) override { + void easy_cleanup(CURL* handle) override { destroyed_handles_.insert(handle); CurlLibrary::easy_cleanup(handle); } - CURL *easy_init() override { - CURL *handle = CurlLibrary::easy_init(); + CURL* easy_init() override { + CURL* handle = CurlLibrary::easy_init(); created_handles_.insert(handle); return handle; } - CURLcode easy_getinfo_response_code(CURL *, long *code) override { + CURLcode easy_getinfo_response_code(CURL*, long* code) override { *code = 200; return CURLE_OK; } - CURLcode easy_setopt_headerdata(CURL *, void *data) override { + CURLcode easy_setopt_headerdata(CURL*, void* data) override { user_data_on_header_ = data; return CURLE_OK; } - CURLcode easy_setopt_headerfunction(CURL *, + CURLcode easy_setopt_headerfunction(CURL*, HeaderCallback on_header) override { on_header_ = on_header; return CURLE_OK; } - CURLcode easy_setopt_writedata(CURL *, void *data) override { + CURLcode easy_setopt_writedata(CURL*, void* data) override { user_data_on_write_ = data; return CURLE_OK; } - CURLcode easy_setopt_writefunction(CURL *, WriteCallback on_write) override { + CURLcode easy_setopt_writefunction(CURL*, WriteCallback on_write) override { on_write_ = on_write; return CURLE_OK; } - CURLcode easy_setopt_timeout_ms(CURL *, long) override { return CURLE_OK; } + CURLcode easy_setopt_timeout_ms(CURL*, long) override { return CURLE_OK; } - CURLMcode multi_add_handle(CURLM *, CURL *easy_handle) override { + CURLMcode multi_add_handle(CURLM*, CURL* easy_handle) override { added_handle_ = easy_handle; state_ = state::added; return CURLM_OK; } - CURLMsg *multi_info_read(CURLM *, int *msgs_in_queue) override { + CURLMsg* multi_info_read(CURLM*, int* msgs_in_queue) override { if (delay_message_) { *msgs_in_queue = 0; return nullptr; @@ -102,7 +102,7 @@ class SingleRequestMockCurlLibrary : public CurlLibrary { return &message_; } - CURLMcode multi_perform(CURLM *, int *running_handles) override { + CURLMcode multi_perform(CURLM*, int* running_handles) override { if (!added_handle_) { *running_handles = 0; return CURLM_OK; @@ -143,7 +143,7 @@ class SingleRequestMockCurlLibrary : public CurlLibrary { state_ = state::performed; return CURLM_OK; } - CURLMcode multi_remove_handle(CURLM *, CURL *easy_handle) override { + CURLMcode multi_remove_handle(CURLM*, CURL* easy_handle) override { REQUIRE(easy_handle == added_handle_); added_handle_ = nullptr; return CURLM_OK; @@ -152,7 +152,7 @@ class SingleRequestMockCurlLibrary : public CurlLibrary { #define CURL_TEST(x) TEST_CASE(x, "[curl]") -const auto ignore = [](auto &&...) {}; +const auto ignore = [](auto&&...) {}; using namespace std::chrono_literals; @@ -190,7 +190,7 @@ CURL_TEST("parse response headers and body") { const HTTPClient::URL url = {"http", "whatever", "", ""}; const auto result = client->post( url, ignore, "whatever", - [&](int status, const DictReader &headers, std::string body) { + [&](int status, const DictReader& headers, std::string body) { try { REQUIRE(status == 200); REQUIRE(headers.lookup("foo-bar") == "baz"); @@ -211,7 +211,7 @@ CURL_TEST("parse response headers and body") { exception = std::current_exception(); } }, - [&](const Error &error) { post_error = error; }, + [&](const Error& error) { post_error = error; }, clock().tick + std::chrono::seconds(10)); REQUIRE(result); @@ -227,7 +227,7 @@ CURL_TEST("bad multi-handle means error mode") { // If libcurl fails to allocate a multi-handle, then the HTTP client enters a // mode where calls to `post` always return an error. class MockCurlLibrary : public CurlLibrary { - CURLM *multi_init() override { return nullptr; } + CURLM* multi_init() override { return nullptr; } }; const auto clock = default_clock; @@ -250,8 +250,8 @@ CURL_TEST("bad std::thread means error mode") { const auto clock = default_clock; const auto logger = std::make_shared(); CurlLibrary libcurl; // the default implementation - const auto client = std::make_shared( - logger, clock, libcurl, [](auto &&) -> std::thread { + const auto client = + std::make_shared(logger, clock, libcurl, [](auto&&) -> std::thread { throw std::system_error( std::make_error_code(std::errc::resource_unavailable_try_again)); }); @@ -270,7 +270,7 @@ CURL_TEST("fail to allocate request handle") { // then `post` immediately returns an error. class MockCurlLibrary : public CurlLibrary { public: - CURL *easy_init() override { return nullptr; } + CURL* easy_init() override { return nullptr; } }; const auto clock = default_clock; @@ -295,73 +295,73 @@ CURL_TEST("setopt failures") { CURLoption fail = CURLOPT_LASTENTRY; CURLcode error = CURLE_OUT_OF_MEMORY; - CURLcode easy_setopt_errorbuffer(CURL *, char *) override { + CURLcode easy_setopt_errorbuffer(CURL*, char*) override { if (fail == CURLOPT_ERRORBUFFER) { return error; } return CURLE_OK; } - CURLcode easy_setopt_headerdata(CURL *, void *) override { + CURLcode easy_setopt_headerdata(CURL*, void*) override { if (fail == CURLOPT_HEADERDATA) { return error; } return CURLE_OK; } - CURLcode easy_setopt_headerfunction(CURL *, HeaderCallback) override { + CURLcode easy_setopt_headerfunction(CURL*, HeaderCallback) override { if (fail == CURLOPT_HEADERFUNCTION) { return error; } return CURLE_OK; } - CURLcode easy_setopt_httpheader(CURL *, curl_slist *) override { + CURLcode easy_setopt_httpheader(CURL*, curl_slist*) override { if (fail == CURLOPT_HTTPHEADER) { return error; } return CURLE_OK; } - CURLcode easy_setopt_post(CURL *, long) override { + CURLcode easy_setopt_post(CURL*, long) override { if (fail == CURLOPT_POST) { return error; } return CURLE_OK; } - CURLcode easy_setopt_postfields(CURL *, const char *) override { + CURLcode easy_setopt_postfields(CURL*, const char*) override { if (fail == CURLOPT_POSTFIELDS) { return error; } return CURLE_OK; } - CURLcode easy_setopt_postfieldsize(CURL *, long) override { + CURLcode easy_setopt_postfieldsize(CURL*, long) override { if (fail == CURLOPT_POSTFIELDSIZE) { return error; } return CURLE_OK; } - CURLcode easy_setopt_private(CURL *, void *) override { + CURLcode easy_setopt_private(CURL*, void*) override { if (fail == CURLOPT_PRIVATE) { return error; } return CURLE_OK; } - CURLcode easy_setopt_unix_socket_path(CURL *, const char *) override { + CURLcode easy_setopt_unix_socket_path(CURL*, const char*) override { if (fail == CURLOPT_UNIX_SOCKET_PATH) { return error; } return CURLE_OK; } - CURLcode easy_setopt_url(CURL *, const char *) override { + CURLcode easy_setopt_url(CURL*, const char*) override { if (fail == CURLOPT_URL) { return error; } return CURLE_OK; } - CURLcode easy_setopt_writedata(CURL *, void *) override { + CURLcode easy_setopt_writedata(CURL*, void*) override { if (fail == CURLOPT_WRITEDATA) { return error; } return CURLE_OK; } - CURLcode easy_setopt_writefunction(CURL *, WriteCallback) override { + CURLcode easy_setopt_writefunction(CURL*, WriteCallback) override { if (fail == CURLOPT_WRITEFUNCTION) { return error; } @@ -375,7 +375,9 @@ CURL_TEST("setopt failures") { }; #define CASE(OPTION) \ - { OPTION, #OPTION } + { \ + OPTION, #OPTION \ + } auto test_case = GENERATE( values({CASE(CURLOPT_ERRORBUFFER), CASE(CURLOPT_HEADERDATA), @@ -425,7 +427,7 @@ CURL_TEST("handles are always cleaned up") { const auto dummy_deadline = clock().tick + std::chrono::seconds(10); const auto result = client->post( url, ignore, "whatever", - [&](int status, const DictReader & /*headers*/, std::string body) { + [&](int status, const DictReader& /*headers*/, std::string body) { try { REQUIRE(status == 200); REQUIRE(body == @@ -434,7 +436,7 @@ CURL_TEST("handles are always cleaned up") { exception = std::current_exception(); } }, - [&](const Error &error) { post_error = error; }, dummy_deadline); + [&](const Error& error) { post_error = error; }, dummy_deadline); REQUIRE(result); client->drain(clock().tick + std::chrono::seconds(1)); @@ -451,7 +453,7 @@ CURL_TEST("handles are always cleaned up") { library.message_result_ = CURLE_COULDNT_CONNECT; // any error would do const auto result = client->post( url, ignore, "whatever", ignore, - [&](const Error &error) { post_error = error; }, dummy_deadline); + [&](const Error& error) { post_error = error; }, dummy_deadline); REQUIRE(result); client->drain(clock().tick + std::chrono::seconds(1)); diff --git a/test/test_span.cpp b/test/test_span.cpp index 65a79c30..2fcad5ab 100644 --- a/test/test_span.cpp +++ b/test/test_span.cpp @@ -499,7 +499,9 @@ TEST_SPAN("injection") { REQUIRE(writer.items.empty() == false); // Consume the span that MUST be kept for service liveness. - { apm_disabled_tracer.create_span(); } + { + apm_disabled_tracer.create_span(); + } auto span = apm_disabled_tracer.create_span(); diff --git a/test/test_trace_id.cpp b/test/test_trace_id.cpp index 5995cf02..122178b0 100644 --- a/test/test_trace_id.cpp +++ b/test/test_trace_id.cpp @@ -113,8 +113,10 @@ TEST_CASE("TraceID serialization") { std::string expected_hex; }; -#define CASE(TRACE_ID, HEX) \ - { __LINE__, #TRACE_ID, TRACE_ID, HEX } +#define CASE(TRACE_ID, HEX) \ + { \ + __LINE__, #TRACE_ID, TRACE_ID, HEX \ + } // clang-format off const auto test_case = GENERATE(values({ CASE(TraceID(), "00000000000000000000000000000000"), diff --git a/test/test_trace_segment.cpp b/test/test_trace_segment.cpp index 8da35261..608f9fad 100644 --- a/test/test_trace_segment.cpp +++ b/test/test_trace_segment.cpp @@ -238,7 +238,9 @@ TEST_CASE("TraceSegment finalization of spans") { {"x-datadog-sampling-priority", std::to_string(sampling_priority)}, }; MockDictReader reader{headers}; - { auto span = tracer.extract_span(reader); } + { + auto span = tracer.extract_span(reader); + } REQUIRE(collector->span_count() == 1); REQUIRE(collector->first_span().numeric_tags.at( tags::internal::sampling_priority) == sampling_priority); diff --git a/test/test_tracer.cpp b/test/test_tracer.cpp index 26a2b233..daaab752 100644 --- a/test/test_tracer.cpp +++ b/test/test_tracer.cpp @@ -1265,7 +1265,8 @@ TEST_TRACER("span extraction") { auto test_case = GENERATE(values({ { - __LINE__, "identical trace info", + __LINE__, + "identical trace info", "00-11111111111111110000000000000001-000000003ade68b1-" "01", // traceparent "dd=s:2;p:000000003ade68b1,foo=1", // tracestate @@ -1277,7 +1278,8 @@ TEST_TRACER("span extraction") { }, { - __LINE__, "trace ids do not match", + __LINE__, + "trace ids do not match", "00-11111111111111110000000000000002-000000003ade68b1-" "01", // traceparent "dd=s:2;p:000000000000000a,foo=1", // tracestate @@ -1289,7 +1291,8 @@ TEST_TRACER("span extraction") { }, { - __LINE__, "same trace, non-matching parent ids", + __LINE__, + "same trace, non-matching parent ids", "00-11111111111111110000000000000003-000000003ade68b1-" "01", // traceparent "dd=s:2;p:000000000000000a,foo=1", // tracestate @@ -1301,7 +1304,8 @@ TEST_TRACER("span extraction") { }, { - __LINE__, "non-matching span, missing p value", + __LINE__, + "non-matching span, missing p value", "00-00000000000000000000000000000004-000000003ade68b1-" "01", // traceparent "dd=s:2,foo=1", // tracestate @@ -1313,7 +1317,8 @@ TEST_TRACER("span extraction") { }, { - __LINE__, "non-matching span, non-matching p value", + __LINE__, + "non-matching span, non-matching p value", "00-00000000000000000000000000000005-000000003ade68b1-" "01", // traceparent "dd=s:2;p:8fffffffffffffff,foo=1", // tracestate @@ -1851,7 +1856,9 @@ TEST_TRACER("APM tracing disabled") { auto finalized_config = finalize_config(config, clock); REQUIRE(finalized_config); Tracer tracer{*finalized_config}; - { auto root1 = tracer.create_span(); } + { + auto root1 = tracer.create_span(); + } REQUIRE(collector->chunks.size() == 1); REQUIRE(collector->chunks.front().size() == 1); @@ -1930,7 +1937,9 @@ TEST_TRACER("APM tracing disabled") { // When APM Tracing is disabled, we allow one trace per second for service // liveness. To ensure consistency, consume the limiter slot. - { tracer.create_span(); } + { + tracer.create_span(); + } collector->chunks.clear(); // Case 1: extracted context with priority, but no `_dd.p.ts` → depends if