-
Notifications
You must be signed in to change notification settings - Fork 476
Fix lifetime for sdk::ReadWriteLogRecord #3147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Deploy Preview for opentelemetry-cpp-api-docs canceled.
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3147 +/- ##
==========================================
- Coverage 90.06% 89.71% -0.35%
==========================================
Files 212 213 +1
Lines 6939 7127 +188
==========================================
+ Hits 6249 6393 +144
- Misses 690 734 +44
🚀 New features to boost your workflow:
|
I don't know if this is critical, but this change breaks the ABI:
To reproduce: cmake -B build -DBUILD_SHARED_LIBS=ON -DCMAKE_CXX_FLAGS="-Og -g3" --fresh
cmake --build build -j$(nproc) --clean-first
cmake --install build --prefix ORIG
wget https://patch-diff.githubusercontent.com/raw/open-telemetry/opentelemetry-cpp/pull/3147.diff
patch -p1 < 3147.diff
cmake --build build -j$(nproc)
cmake --install build --prefix NEW
mkdir dumps
for i in ORIG/lib/*.so; do abi-dumper "$i" -o "dumps/orig-$(basename "$i").dump" -lver orig; done
for i in NEW/lib/*.so; do abi-dumper "$i" -o "dumps/new-$(basename "$i").dump" -lver new; done
for i in NEW/lib/*.so; do abi-compliance-checker -l "$(basename "$i")" -old "dumps/orig-$(basename "$i").dump" -new "dumps/new-$(basename "$i").dump; done It will show smth like
|
If I didn't miss anything, I think we only need to keep ABI compatibility for api. These changes keep API compatibility for sdk and exporters. |
I noticed that the library does not have a SOVERSION and thought that the changes could break the existing consumers (I know that Alpine Linux ships OpenTelemetry C++ libraries). That's why I asked :-) |
If we build otel-cpp with cmake, we can use
Thanks. I noticed #3110 and agree with the SOVERSION idea. Let's continue discussing it there. |
@owent Thanks for the PR. With the use of the How about having two separate recordables:
|
Good point. |
/** | ||
* Set an owned copy (OwnedAttributeValue) and attribute view of a non-owning AttributeValue. | ||
*/ | ||
class MixedAttributeViewSetter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@owent - Do we still need this class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still used by MixedAttributeMap
, which is used by LogRecordData
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are some differents between LogRecordData
and SpanData
.
SpanData::GetAttributes
returns std::unordered_map<std::string, opentelemetry::sdk::common::OwnedAttributeValue>
but LogRecordData::GetAttributes
returns std::unordered_map<std::string, opentelemetry::common::AttributeValue>
.
We need storage to store span<T>
in opentelemetry::common::AttributeValue
, or do you think we can break the API of
ReadableLogRecord::GetAttributes
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea about keep the mixed types or change the API of ReadableLogRecord::GetAttributes
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another note to myself that I really really need to review this. @owent Could you refresh the patch and merge with a recent main ? Also, make sure there are no changes under third_party. Thanks. |
Thanks, conflicts are resolved. |
Is the update to the prometheus-cpp submodule expected? |
I don't understand all the reasoning that lead to this current patch, it looks way too complicated to me. Either I totally missed something, or it can be done in a simpler way. Please see a different attempt to resolve the same issues, and comment: |
c126e12
to
ab7b413
Compare
Sorry, it's a mistake and it's removed now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments, do not use the ABI version here.
#if OPENTELEMETRY_ABI_VERSION_NO >= 2 | ||
virtual const common::OwnedAttributeValue & | ||
#else | ||
virtual const opentelemetry::common::AttributeValue & | ||
#endif | ||
GetBody() const noexcept = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree with using OPENTELEMETRY_ABI_VERSION_NO
here:
-
The content of api/include has not changed in this PR, the
ABI
for the instrumentation interface is strictly the same before and after the fix, so there is noABI
change. The symbolOPENTELEMETRY_ABI_VERSION_NO
is dedicated to the API part, it is not meant to keep track of SDK ABI changes, that can happen independently. -
Using a flag to provide a migration path is fine. If we want to do it, the flag should be similar to
WITH_DEPRECATED_SDK_FACTORY
/OPENTELEMETRY_DEPRECATED_SDK_FACTORY
introduced by PR [API/SDK] Provider cleanup #2664 for example. Do not useOPENTELEMETRY_ABI_VERSION_NO
for this.
Now, there is more to this:
-
This change does not affect the instrumentation interface, so no instrumented code will be broken by this.
-
This change does not affect the SDK configuration interface (defining an exporter, etc), so no application simply using the SDK to configure opentelemetry-cpp will be affected.
-
The only way some user code can be affected is if the user code implements its own log record exporter, and reuses the
ReadableLogRecord
class from the SDK instead of defining its own recordable for its own implementation. -
Even if this happen to be the case, the user log record exporter is then by definition broken and crashing, the same way the ostream exporter is crashing today, precisely because this class implementation uses stale pointers.
In conclusion, I don't think using a feature flag to provide the fix (or not) resolves anything. To the contrary, it complicates the implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree about the flag. However, regarding compatibility, the issue isn't a crash. The return type has changed, so if users implement their own exporters using ReadableLogRecord
, their code won't compile. I think we can allow users time to migrate from the old SDK to the new version, rather than introducing an immediate breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type has changed, so if users implement their own exporters using
ReadableLogRecord
, their code won't compile.
Correct.
But also note that if a user has such code in a custom exporter, that exporter should be currently crashing, when using stale pointers in body or attributes.
Forcing users to fix a broken custom exporter implementation might not be that bad after all, even if the visible effect is a build break.
I think we can allow users time to migrate from the old SDK to the new version, rather than introducing an immediate breaking change.
Assuming we want to take this path, it requires:
- to introduce a build flag, to expose the new return type versus the old one.
- to announce building with the old return type is deprecated, and will be removed in the future
- to raise a build deprecation warning, to force users to notice
- to document the migration path, and explain using the build flag is preferable
- in the next release, to remove the build flag, and only keep the new implementation
- in the next release notes, document that users have to adjust their code (they had 1 full release to do so)
This is technically possible, and has been done in the past.
But this has been done in cases where:
- the SDK configuration api got changed
- every application configuring the SDK was known to be affected
so in short when the amount of code / users affected was significant.
Here, the SDK configuration has not changed, and most if not all applications will require no changes at all.
Again, the only impact is for applications that:
- defines their own log record exporter
- reuse an SDK class in their implementation (instead of implementing their own recordable)
Taking dependencies on the SDK implementation implies some risks, applications doing this should be aware of possible consequences.
I understand this particular point is a matter of assessment and opinions, but in this case I think having the full build flag and migration path for a use case that is expected to be very narrow (custom exporter), is overkill.
ab7b413
to
d6dc0b1
Compare
There are a lot of commits before, I also rebase and squash it from mian again. |
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
Fixes GetBody::ReadWriteLogRecord
872f40c
to
8459290
Compare
Close as #3417 is more simple when breaking the ABI and APIs is acceptable. |
Fixes #3135
Fixes #2651
Changes
MixedAttributeMap
to store bothstd::unordered_map<std::string, opentelemetry::common::AttributeValue>
andAttributeMap
OwnedAttributeValue
,std::vector<nostd::string_view>
andbool
array forReadWriteLogRecord
.For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes