Skip to content

Commit 3242d82

Browse files
authored
Merge branch 'main' into upgrade_proto_1.5.0
2 parents 0281ca9 + 92bf8da commit 3242d82

File tree

22 files changed

+929
-105
lines changed

22 files changed

+929
-105
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ Increment the:
1515

1616
## [Unreleased]
1717

18+
* [SDK] Do not frequently create and destroy http client threads
19+
[#3198](https://github.com/open-telemetry/opentelemetry-cpp/pull/3198)
20+
21+
* [SDK] Fix instrumentation scope attributes evaluated in equal method
22+
[#3214](https://github.com/open-telemetry/opentelemetry-cpp/pull/3214)
23+
1824
## [1.18 2024-11-25]
1925

2026
* [EXPORTER] Fix crash in ElasticsearchLogRecordExporter

CMakeLists.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,37 @@ if(BUILD_TESTING)
645645
endif()
646646
message(STATUS "GTEST_INCLUDE_DIRS = ${GTEST_INCLUDE_DIRS}")
647647
message(STATUS "GTEST_BOTH_LIBRARIES = ${GTEST_BOTH_LIBRARIES}")
648+
649+
# Try to find gmock
650+
if(NOT GMOCK_LIB AND TARGET GTest::gmock)
651+
set(GMOCK_LIB GTest::gmock)
652+
elseif(MSVC)
653+
# Explicitly specify that we consume GTest from shared library. The rest of
654+
# code logic below determines whether we link Release or Debug flavor of the
655+
# library. These flavors have different prefix on Windows, gmock and gmockd
656+
# respectively.
657+
add_definitions(-DGTEST_LINKED_AS_SHARED_LIBRARY=1)
658+
if(GMOCK_LIB)
659+
# unset GMOCK_LIB to force find_library to redo the lookup, as the cached
660+
# entry could cause linking to incorrect flavor of gmock and leading to
661+
# runtime error.
662+
unset(GMOCK_LIB CACHE)
663+
endif()
664+
endif()
665+
if(NOT GMOCK_LIB)
666+
if(MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug")
667+
find_library(GMOCK_LIB gmockd PATH_SUFFIXES lib)
668+
else()
669+
find_library(GMOCK_LIB gmock PATH_SUFFIXES lib)
670+
endif()
671+
# Reset GMOCK_LIB if it was not found, or some target may link
672+
# GMOCK_LIB-NOTFOUND
673+
if(NOT GMOCK_LIB)
674+
unset(GMOCK_LIB)
675+
unset(GMOCK_LIB CACHE)
676+
endif()
677+
endif()
678+
648679
enable_testing()
649680
if(WITH_BENCHMARK)
650681
# Benchmark respects the CMAKE_PREFIX_PATH

api/include/opentelemetry/detail/preprocessor.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@
1111

1212
#define OPENTELEMETRY_CONCAT(A, B) OPENTELEMETRY_CONCAT_(A, B)
1313
#define OPENTELEMETRY_CONCAT_(A, B) A##B
14+
15+
// Import the C++20 feature-test macros
16+
#ifdef __has_include
17+
# if __has_include(<version>)
18+
# include <version>
19+
# endif
20+
#elif defined(_MSC_VER) && ((defined(__cplusplus) && __cplusplus >= 202002L) || \
21+
(defined(_MSVC_LANG) && _MSVC_LANG >= 202002L))
22+
# if _MSC_VER >= 1922
23+
# include <version>
24+
# endif
25+
#endif

exporters/elasticsearch/src/es_log_recordable.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#include <opentelemetry/version.h>
5+
46
#include <chrono>
57
#include <ctime>
68
#include <nlohmann/json.hpp>
79
#include <string>
810

11+
#if defined(__cpp_lib_format)
12+
# include <format>
13+
#endif
14+
915
#include "opentelemetry/exporters/elasticsearch/es_log_recordable.h"
1016
#include "opentelemetry/logs/severity.h"
1117
#include "opentelemetry/nostd/variant.h"
@@ -71,7 +77,8 @@ void ElasticSearchRecordable::SetTimestamp(
7177

7278
// If built with with at least cpp 20 then use std::format
7379
// Otherwise use the old style to format the timestamp in UTC
74-
#if __cplusplus >= 202002L
80+
// @see https://en.cppreference.com/w/cpp/feature_test#cpp_lib_format
81+
#if defined(__cpp_lib_format) && __cpp_lib_format >= 201907
7582
const std::string dateStr = std::format("{:%FT%T%Ez}", timePoint);
7683
#else
7784
std::time_t time = std::chrono::system_clock::to_time_t(timePoint);

exporters/otlp/CMakeLists.txt

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -313,29 +313,6 @@ if(BUILD_TESTING)
313313
TEST_PREFIX exporter.otlp.
314314
TEST_LIST otlp_metrics_serialization_test)
315315

316-
if(NOT GMOCK_LIB AND TARGET GTest::gmock)
317-
set(GMOCK_LIB GTest::gmock)
318-
elseif(MSVC)
319-
# Explicitly specify that we consume GTest from shared library. The rest of
320-
# code logic below determines whether we link Release or Debug flavor of the
321-
# library. These flavors have different prefix on Windows, gmock and gmockd
322-
# respectively.
323-
add_definitions(-DGTEST_LINKED_AS_SHARED_LIBRARY=1)
324-
if(GMOCK_LIB)
325-
# unset GMOCK_LIB to force find_library to redo the lookup, as the cached
326-
# entry could cause linking to incorrect flavor of gmock and leading to
327-
# runtime error.
328-
unset(GMOCK_LIB CACHE)
329-
endif()
330-
endif()
331-
if(NOT GMOCK_LIB)
332-
if(MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug")
333-
find_library(GMOCK_LIB gmockd PATH_SUFFIXES lib)
334-
else()
335-
find_library(GMOCK_LIB gmock PATH_SUFFIXES lib)
336-
endif()
337-
endif()
338-
339316
if(WITH_OTLP_GRPC)
340317
add_executable(otlp_grpc_exporter_test test/otlp_grpc_exporter_test.cc)
341318
target_link_libraries(

exporters/otlp/src/otlp_http_client.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ OtlpHttpClient::createSession(
890890
// Parse uri and store it to cache
891891
if (http_uri_.empty())
892892
{
893-
auto parse_url = opentelemetry::ext::http::common::UrlParser(std::string(options_.url));
893+
const auto parse_url = opentelemetry::ext::http::common::UrlParser(options_.url);
894894
if (!parse_url.success_)
895895
{
896896
std::string error_message = "[OTLP HTTP Client] Export failed, invalid url: " + options_.url;

exporters/zipkin/CMakeLists.txt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,6 @@ if(BUILD_TESTING)
4949
TEST_PREFIX exporter.
5050
TEST_LIST zipkin_recordable_test)
5151

52-
if(MSVC)
53-
if(GMOCK_LIB)
54-
unset(GMOCK_LIB CACHE)
55-
endif()
56-
endif()
57-
if(MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug")
58-
find_library(GMOCK_LIB gmockd PATH_SUFFIXES lib)
59-
else()
60-
find_library(GMOCK_LIB gmock PATH_SUFFIXES lib)
61-
endif()
62-
6352
add_executable(zipkin_exporter_test test/zipkin_exporter_test.cc)
6453

6554
target_link_libraries(

ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -322,25 +322,16 @@ class HttpClient : public opentelemetry::ext::http::client::HttpClient
322322

323323
inline CURLM *GetMultiHandle() noexcept { return multi_handle_; }
324324

325-
void MaybeSpawnBackgroundThread();
325+
// return true if create background thread, false is already exist background thread
326+
bool MaybeSpawnBackgroundThread();
326327

327328
void ScheduleAddSession(uint64_t session_id);
328329
void ScheduleAbortSession(uint64_t session_id);
329330
void ScheduleRemoveSession(uint64_t session_id, HttpCurlEasyResource &&resource);
330331

331-
void WaitBackgroundThreadExit()
332-
{
333-
std::unique_ptr<std::thread> background_thread;
334-
{
335-
std::lock_guard<std::mutex> lock_guard{background_thread_m_};
336-
background_thread.swap(background_thread_);
337-
}
332+
void SetBackgroundWaitFor(std::chrono::milliseconds ms);
338333

339-
if (background_thread && background_thread->joinable())
340-
{
341-
background_thread->join();
342-
}
343-
}
334+
void WaitBackgroundThreadExit();
344335

345336
private:
346337
void wakeupBackgroundThread();
@@ -366,6 +357,9 @@ class HttpClient : public opentelemetry::ext::http::client::HttpClient
366357
std::unique_ptr<std::thread> background_thread_;
367358
std::chrono::milliseconds scheduled_delay_milliseconds_;
368359

360+
std::chrono::milliseconds background_thread_wait_for_;
361+
std::atomic<bool> is_shutdown_{false};
362+
369363
nostd::shared_ptr<HttpCurlGlobalInitializer> curl_global_initializer_;
370364
};
371365

0 commit comments

Comments
 (0)