Skip to content

Commit d6dc0b1

Browse files
committed
Squashed commit of the following:
commit 081b899edb2a3a47f1c59a8e982b553f7c28c2ac Merge: 350b7830 82ec2a5 Author: owent <[email protected]> Date: Tue May 20 11:29:36 2025 +0800 Merge remote-tracking branch 'github/main' into fix_lifetime_in_log_record commit 350b783012192c1d50f28ba2ec22bf0bb9a3f5fe Author: owent <[email protected]> Date: Tue May 20 11:29:25 2025 +0800 Use a standalone flag to switch deprecated LogRecord APIs commit ab7b413 Author: owent <[email protected]> Date: Mon May 19 15:43:24 2025 +0800 Restore prometheus-cpp commit 3709305 Merge: 4333fcf ba04dbb Author: WenTao Ou <[email protected]> Date: Mon May 19 15:37:28 2025 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit 4333fcf Merge: 865ee87 20c8ded Author: WenTao Ou <[email protected]> Date: Thu May 15 22:16:06 2025 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit 865ee87 Merge: 7bc61db 92dd28c Author: owent <[email protected]> Date: Fri May 9 21:06:52 2025 +0800 Merge remote-tracking branch 'github/main' into fix_lifetime_in_log_record # Conflicts: # CHANGELOG.md commit 7bc61db Merge: bada7dc 4e4d8de Author: WenTao Ou <[email protected]> Date: Fri May 9 11:11:01 2025 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit bada7dc Merge: faeee46 9fd8511 Author: Tom Tan <[email protected]> Date: Fri May 2 22:03:40 2025 -0700 Merge branch 'main' into fix_lifetime_in_log_record commit faeee46 Merge: 13f90d6 f5d6bc1 Author: owent <[email protected]> Date: Sun Apr 27 17:40:15 2025 +0800 Merge remote-tracking branch 'origin/fix_lifetime_in_log_record' into fix_lifetime_in_log_record # Conflicts: # CHANGELOG.md commit 13f90d6 Merge: afde1dd 7801cd9 Author: owent <[email protected]> Date: Sun Apr 27 17:37:08 2025 +0800 Merge remote-tracking branch 'github/main' into fix_lifetime_in_log_record # Conflicts: # CHANGELOG.md commit f5d6bc1 Merge: 3ea0774 4d52ab2 Author: WenTao Ou <[email protected]> Date: Wed Apr 9 20:06:31 2025 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit 3ea0774 Merge: 61a0902 a6779d8 Author: WenTao Ou <[email protected]> Date: Thu Mar 27 17:17:44 2025 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit 61a0902 Merge: 2759d15 6e214c8 Author: Tom Tan <[email protected]> Date: Wed Mar 26 22:27:23 2025 -0700 Merge branch 'main' into fix_lifetime_in_log_record commit 2759d15 Merge: 8af0220 a57063f Author: WenTao Ou <[email protected]> Date: Fri Mar 21 12:10:27 2025 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit 8af0220 Author: owent <[email protected]> Date: Sat Mar 15 12:56:05 2025 +0800 Fixes problems of cppcheck and markdown-lint commit 440dba3 Merge: afde1dd 148cfe9 Author: WenTao Ou <[email protected]> Date: Sat Mar 15 11:51:16 2025 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit afde1dd Merge: 7f06655 edfeabe Author: owent <[email protected]> Date: Fri Mar 7 16:57:48 2025 +0800 Merge remote-tracking branch 'github/main' into fix_lifetime_in_log_record commit 7f06655 Merge: dca08c8 021eb99 Author: owent <[email protected]> Date: Mon Feb 24 14:41:36 2025 +0800 Merge remote-tracking branch 'github/main' into fix_lifetime_in_log_record commit dca08c8 Author: owent <[email protected]> Date: Fri Feb 21 14:29:23 2025 +0800 Change the return types of ReadWriteLogRecord in API v2 commit 7e428af Merge: e0bb99e cd7103e Author: owent <[email protected]> Date: Fri Feb 21 10:23:08 2025 +0800 Merge remote-tracking branch 'github/main' into fix_lifetime_in_log_record commit e0bb99e Author: owent <[email protected]> Date: Thu Feb 13 18:51:34 2025 +0800 Fix iwyu commit aa821dc Merge: fabc4a0 3ca3c76 Author: owent <[email protected]> Date: Thu Feb 13 17:42:14 2025 +0800 Merge remote-tracking branch 'github/main' into fix_lifetime_in_log_record # Conflicts: # exporters/ostream/test/ostream_log_test.cc commit fabc4a0 Merge: 156c229 52a80b5 Author: WenTao Ou <[email protected]> Date: Fri Jan 31 11:36:28 2025 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit 156c229 Merge: b5198ae 6603c3a Author: owent <[email protected]> Date: Wed Jan 29 15:48:15 2025 +0800 Merge remote-tracking branch 'opentelemetry/main' into fix_lifetime_in_log_record commit b5198ae Author: owent <[email protected]> Date: Wed Jan 29 15:48:05 2025 +0800 Fixes iwyu commit b173dd7 Merge: b4bfe00 18e06f1 Author: owent <[email protected]> Date: Tue Jan 28 21:23:59 2025 +0800 Merge remote-tracking branch 'opentelemetry/main' into fix_lifetime_in_log_record commit b4bfe00 Merge: 1fc10b0 031307b Author: WenTao Ou <[email protected]> Date: Wed Jan 22 10:23:51 2025 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit 1fc10b0 Merge: a3cffa7 25f7a13 Author: WenTao Ou <[email protected]> Date: Tue Jan 21 19:20:33 2025 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit a3cffa7 Merge: 2f89435 3b89346 Author: WenTao Ou <[email protected]> Date: Wed Jan 8 10:12:22 2025 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit 2f89435 Merge: 4327f87 4998eb1 Author: owent <[email protected]> Date: Fri Dec 20 20:43:25 2024 +0800 Merge remote-tracking branch 'github/main' into fix_lifetime_in_log_record commit 4327f87 Merge: 68178bf 490f882 Author: WenTao Ou <[email protected]> Date: Thu Dec 12 11:32:22 2024 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit 68178bf Merge: 94cf407 2d80c18 Author: WenTao Ou <[email protected]> Date: Sat Dec 7 18:34:10 2024 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit 94cf407 Merge: da602f3 23562e6 Author: Lalit Kumar Bhasin <[email protected]> Date: Fri Dec 6 10:38:42 2024 -0800 Merge branch 'main' into fix_lifetime_in_log_record commit da602f3 Merge: cf758d1 150256c Author: WenTao Ou <[email protected]> Date: Thu Dec 5 12:21:05 2024 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit cf758d1 Merge: 3da4bed 8d45dec Author: WenTao Ou <[email protected]> Date: Wed Nov 27 14:20:29 2024 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit 3da4bed Merge: 282efec 955a807 Author: WenTao Ou <[email protected]> Date: Tue Nov 26 13:22:12 2024 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit 282efec Author: owent <[email protected]> Date: Mon Nov 25 11:28:58 2024 +0800 Implement a new LogRecordData to store both Owned attributes and attributes commit 40c4632 Merge: 5595d31 31956f8 Author: owent <[email protected]> Date: Mon Nov 25 10:43:01 2024 +0800 Merge remote-tracking branch 'github/main' into fix_lifetime_in_log_record commit 5595d31 Merge: 4b8012d f1b5fbd Author: Lalit Kumar Bhasin <[email protected]> Date: Fri Nov 22 15:00:41 2024 -0800 Merge branch 'main' into fix_lifetime_in_log_record commit 4b8012d Merge: 67f66c7 fe68d51 Author: WenTao Ou <[email protected]> Date: Thu Nov 21 16:44:09 2024 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit 67f66c7 Merge: cfd5db3 4d9cc28 Author: WenTao Ou <[email protected]> Date: Wed Nov 20 10:42:40 2024 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit cfd5db3 Author: owent <[email protected]> Date: Sat Nov 16 23:40:34 2024 +0800 Fix a typo commit b933ee8 Merge: cae98c6 a388e87 Author: WenTao Ou <[email protected]> Date: Sat Nov 16 00:33:43 2024 +0800 Merge branch 'main' into fix_lifetime_in_log_record commit cae98c6 Author: owent <[email protected]> Date: Fri Nov 15 22:26:49 2024 +0800 Fix unit test commit 8c86bbd Author: owent <[email protected]> Date: Fri Nov 15 20:21:26 2024 +0800 Fix unit test commit aa4471d Author: owent <[email protected]> Date: Fri Nov 15 19:33:53 2024 +0800 Fix lifetime for sdk::ReadWriteLogRecord
1 parent 82ec2a5 commit d6dc0b1

16 files changed

+1415
-71
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ Increment the:
5555
* [CMAKE] Add generated protobuf headers to the opentelemetry_proto target
5656
[#3400](https://github.com/open-telemetry/opentelemetry-cpp/pull/3400)
5757

58+
* [SDK] Fix lifetime for sdk::ReadWriteLogRecord
59+
[#3147](https://github.com/open-telemetry/opentelemetry-cpp/pull/3245)
60+
61+
Important changes:
62+
63+
* [SDK] Fix lifetime for sdk::ReadWriteLogRecord
64+
[#3147](https://github.com/open-telemetry/opentelemetry-cpp/pull/3245)
65+
66+
* `opentelemetry::sdk::logs::ReadableLogRecord::GetAttributes()`
67+
will returns a `std::unordered_map<std::string, opentelemetry::sdk::common::OwnedAttributeValue>`
68+
instead of a `std::unordered_map<std::string, opentelemetry::common::AttributeValue>`
69+
to keep the same type as the `opentelemetry::sdk::trace::SpanData`. And
70+
`opentelemetry::sdk::logs::ReadableLogRecord::GetBody()` will returns a
71+
`const opentelemetry::sdk::common::OwnedAttributeValue &` instead of a
72+
`const opentelemetry::common::AttributeValue &` now, we switch to the old
73+
APIs by add `-DWITH_DEPRECATED_SDK_LOG_RECORD=ON` for cmake or add
74+
`--copt -DOPENTELEMETRY_DEPRECATED_SDK_LOG_RECORD` for bazel.
75+
5876
## [1.20 2025-04-01]
5977

6078
* [BUILD] Update opentelemetry-proto version
@@ -199,6 +217,9 @@ Important changes:
199217

200218
* All the example code has been updated to reflect the new usage.
201219

220+
* [SDK] Implement spec: MetricFilter
221+
[#3235](https://github.com/open-telemetry/opentelemetry-cpp/pull/3235)
222+
202223
## [1.19 2025-01-22]
203224

204225
* [PROMETHEUS_EXPORTER] Fix default for emitting otel_scope attributes

CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ if(VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
121121
include("${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}")
122122
endif()
123123

124-
option(WITH_ABI_VERSION_1 "ABI version 1" ON)
124+
include(CMakeDependentOption)
125125
option(WITH_ABI_VERSION_2 "EXPERIMENTAL: ABI version 2 preview" OFF)
126+
cmake_dependent_option(WITH_ABI_VERSION_1 "ABI version 1" ON
127+
"NOT WITH_ABI_VERSION_2" OFF)
126128

127129
file(READ "${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h"
128130
OPENTELEMETRY_CPP_HEADER_VERSION_H)
@@ -183,6 +185,13 @@ message(STATUS "OPENTELEMETRY_VERSION=${OPENTELEMETRY_VERSION}")
183185

184186
option(WITH_NO_DEPRECATED_CODE "Do not include deprecated code" OFF)
185187

188+
option(WITH_DEPRECATED_SDK_LOG_RECORD "Use deprecated SDK log record" OFF)
189+
190+
if(WITH_DEPRECATED_SDK_LOG_RECORD)
191+
message(
192+
WARNING "WITH_DEPRECATED_SDK_LOG_RECORD=ON is temporary and deprecated")
193+
endif()
194+
186195
set(WITH_STL
187196
"OFF"
188197
CACHE STRING "Which version of the Standard Library for C++ to use")
@@ -490,7 +499,6 @@ if(WITH_OTLP_GRPC
490499
# Some versions of FindProtobuf.cmake uses mixed case instead of uppercase
491500
set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
492501
endif()
493-
include(CMakeDependentOption)
494502

495503
message(STATUS "PROTOBUF_PROTOC_EXECUTABLE=${PROTOBUF_PROTOC_EXECUTABLE}")
496504
set(SAVED_CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY})

ci/do_ci.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ switch ($action) {
6767
cmake $SRC_DIR `
6868
-DVCPKG_TARGET_TRIPLET=x64-windows `
6969
-DOPENTELEMETRY_BUILD_DLL=1 `
70+
-DWITH_DEPRECATED_SDK_LOG_RECORD=ON `
7071
"-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake"
7172
$exit = $LASTEXITCODE
7273
if ($exit -ne 0) {
@@ -221,6 +222,7 @@ switch ($action) {
221222
cmake $SRC_DIR `
222223
-DVCPKG_TARGET_TRIPLET=x64-windows `
223224
-DWITH_ASYNC_EXPORT_PREVIEW=ON `
225+
-DWITH_DEPRECATED_SDK_LOG_RECORD=ON `
224226
"-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake"
225227
$exit = $LASTEXITCODE
226228
if ($exit -ne 0) {

ci/do_ci.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ elif [[ "$1" == "cmake.with_async_export.test" ]]; then
228228
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
229229
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
230230
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
231+
-DWITH_DEPRECATED_SDK_LOG_RECORD=ON \
231232
"${SRC_DIR}"
232233
make -j $(nproc)
233234
make test
@@ -281,6 +282,7 @@ elif [[ "$1" == "cmake.c++20.test" ]]; then
281282
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
282283
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
283284
-DWITH_STL=CXX20 \
285+
-DWITH_DEPRECATED_SDK_LOG_RECORD=ON \
284286
"${SRC_DIR}"
285287
eval "$MAKE_COMMAND"
286288
make test
@@ -292,6 +294,7 @@ elif [[ "$1" == "cmake.c++23.test" ]]; then
292294
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
293295
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
294296
-DWITH_STL=CXX23 \
297+
-DWITH_DEPRECATED_SDK_LOG_RECORD=ON \
295298
"${SRC_DIR}"
296299
eval "$MAKE_COMMAND"
297300
make test
@@ -304,6 +307,7 @@ elif [[ "$1" == "cmake.c++14.stl.test" ]]; then
304307
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
305308
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
306309
-DWITH_STL=CXX14 \
310+
-DWITH_DEPRECATED_SDK_LOG_RECORD=ON \
307311
"${SRC_DIR}"
308312
eval "$MAKE_COMMAND"
309313
make test
@@ -316,6 +320,7 @@ elif [[ "$1" == "cmake.c++17.stl.test" ]]; then
316320
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
317321
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
318322
-DWITH_STL=CXX17 \
323+
-DWITH_DEPRECATED_SDK_LOG_RECORD=ON \
319324
"${SRC_DIR}"
320325
eval "$MAKE_COMMAND"
321326
make test

exporters/ostream/src/log_record_exporter.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "opentelemetry/sdk/common/exporter_utils.h"
2323
#include "opentelemetry/sdk/common/global_log_handler.h"
2424
#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
25-
#include "opentelemetry/sdk/logs/read_write_log_record.h"
25+
#include "opentelemetry/sdk/logs/log_record_data.h"
2626
#include "opentelemetry/sdk/logs/recordable.h"
2727
#include "opentelemetry/sdk/resource/resource.h"
2828
#include "opentelemetry/trace/span_id.h"
@@ -47,7 +47,7 @@ OStreamLogRecordExporter::OStreamLogRecordExporter(std::ostream &sout) noexcept
4747

4848
std::unique_ptr<sdklogs::Recordable> OStreamLogRecordExporter::MakeRecordable() noexcept
4949
{
50-
return std::unique_ptr<sdklogs::Recordable>(new sdklogs::ReadWriteLogRecord());
50+
return std::unique_ptr<sdklogs::Recordable>(new sdklogs::LogRecordData());
5151
}
5252

5353
sdk::common::ExportResult OStreamLogRecordExporter::Export(
@@ -62,8 +62,8 @@ sdk::common::ExportResult OStreamLogRecordExporter::Export(
6262

6363
for (auto &record : records)
6464
{
65-
auto log_record = std::unique_ptr<sdklogs::ReadWriteLogRecord>(
66-
static_cast<sdklogs::ReadWriteLogRecord *>(record.release()));
65+
auto log_record = std::unique_ptr<sdklogs::LogRecordData>(
66+
static_cast<sdklogs::LogRecordData *>(record.release()));
6767

6868
if (log_record == nullptr)
6969
{

exporters/ostream/test/ostream_log_test.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
#include "opentelemetry/nostd/utility.h"
2828
#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
2929
#include "opentelemetry/sdk/logs/exporter.h"
30+
#include "opentelemetry/sdk/logs/log_record_data.h"
3031
#include "opentelemetry/sdk/logs/logger_provider.h"
3132
#include "opentelemetry/sdk/logs/processor.h"
3233
#include "opentelemetry/sdk/logs/provider.h"
33-
#include "opentelemetry/sdk/logs/read_write_log_record.h"
3434
#include "opentelemetry/sdk/logs/readable_log_record.h"
3535
#include "opentelemetry/sdk/logs/recordable.h"
3636
#include "opentelemetry/sdk/logs/simple_log_record_processor.h"
@@ -82,7 +82,7 @@ TEST(OStreamLogRecordExporter, Shutdown)
8282

8383
// After processor/exporter is shutdown, no logs should be sent to stream
8484
auto record = exporter->MakeRecordable();
85-
static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetBody("Log record not empty");
85+
static_cast<sdklogs::LogRecordData *>(record.get())->SetBody("Log record not empty");
8686
exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&record, 1));
8787

8888
// Restore original stringstream buffer
@@ -171,12 +171,12 @@ TEST(OStreamLogRecordExporter, SimpleLogToCout)
171171
// Create a log record and manually timestamp, severity, name, message
172172
common::SystemTimestamp now(std::chrono::system_clock::now());
173173

174-
auto record = std::unique_ptr<sdklogs::Recordable>(new sdklogs::ReadWriteLogRecord());
175-
static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetTimestamp(now);
176-
static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetObservedTimestamp(now);
177-
static_cast<sdklogs::ReadWriteLogRecord *>(record.get())
174+
auto record = std::unique_ptr<sdklogs::Recordable>(new sdklogs::LogRecordData());
175+
static_cast<sdklogs::LogRecordData *>(record.get())->SetTimestamp(now);
176+
static_cast<sdklogs::LogRecordData *>(record.get())->SetObservedTimestamp(now);
177+
static_cast<sdklogs::LogRecordData *>(record.get())
178178
->SetSeverity(logs_api::Severity::kTrace); // kTrace has enum value of 1
179-
static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetBody("Message");
179+
static_cast<sdklogs::LogRecordData *>(record.get())->SetBody("Message");
180180

181181
opentelemetry::sdk::instrumentationscope::InstrumentationScope instrumentation_scope =
182182
GetTestInstrumentationScope();
@@ -248,10 +248,10 @@ TEST(OStreamLogRecordExporter, LogWithStringAttributesToCerr)
248248

249249
// Set resources for this log record only of type <string, string>
250250
auto resource = opentelemetry::sdk::resource::Resource::Create({{"key1", "val1"}});
251-
static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetResource(resource);
251+
static_cast<sdklogs::LogRecordData *>(record.get())->SetResource(resource);
252252

253253
// Set attributes to this log record of type <string, AttributeValue>
254-
static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetAttribute("a", true);
254+
static_cast<sdklogs::LogRecordData *>(record.get())->SetAttribute("a", true);
255255

256256
opentelemetry::sdk::instrumentationscope::InstrumentationScope instrumentation_scope =
257257
GetTestInstrumentationScope();
@@ -326,12 +326,12 @@ TEST(OStreamLogRecordExporter, LogWithVariantTypesToClog)
326326
nostd::span<int> data1{array1.data(), array1.size()};
327327

328328
auto resource = opentelemetry::sdk::resource::Resource::Create({{"res1", data1}});
329-
static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetResource(resource);
329+
static_cast<sdklogs::LogRecordData *>(record.get())->SetResource(resource);
330330

331331
// Set resources for this log record of bool types as the value
332332
// e.g. key/value is a par of type <string, array of bools>
333333
std::array<bool, 3> array = {false, true, false};
334-
static_cast<sdklogs::ReadWriteLogRecord *>(record.get())
334+
static_cast<sdklogs::LogRecordData *>(record.get())
335335
->SetAttribute("attr1", nostd::span<bool>{array.data(), array.size()});
336336

337337
opentelemetry::sdk::instrumentationscope::InstrumentationScope instrumentation_scope =

0 commit comments

Comments
 (0)