Skip to content

Conversation

@victornguen
Copy link
Contributor

Which problem is this PR solving?

Description of the changes

Implement copy-on-write approach for all sanitizers:

  • Check if modifications are needed before attempting changes
  • Return original traces if no sanitization required
  • Test mutability and create a copy if data is read-only
  • Apply modifications to the working copy instead of original data

How was this change tested?

  • Tests each sanitizer with read-only traces that need modification
  • Tests each sanitizer with read-only traces that don't need modification
  • Added test in storage exporter that reproduces the original panic scenario

Checklist

@victornguen victornguen requested a review from a team as a code owner June 22, 2025 19:30
@victornguen victornguen requested a review from pavolloffay June 22, 2025 19:30
@victornguen victornguen force-pushed the fix/7221 branch 2 times, most recently from e00cbae to c771901 Compare June 22, 2025 19:42

var workingTraces ptrace.Traces

canModify := true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is IsReadOnly function, why do we need to test via panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad, I've refactored it

span := spans.At(k)
if spanNeedsDurationSanitization(span) {
needsModification = true
break
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this only breaks out of the inner loop, you need to use a label at the outer loop and break outerloop. Or move the check to a function and return true

Comment on lines 58 to 60
workingResourceSpans := workingTraces.ResourceSpans()
for i := 0; i < workingResourceSpans.Len(); i++ {
resourceSpan := workingResourceSpans.At(i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can simplify using iterators

Suggested change
workingResourceSpans := workingTraces.ResourceSpans()
for i := 0; i < workingResourceSpans.Len(); i++ {
resourceSpan := workingResourceSpans.At(i)
for resourceSpan := range workingTraces.ResourceSpans().All() {


func attributesNeedUTF8Sanitization(attributes pcommon.Map) bool {
needsSanitization := false
attributes.Range(func(k string, v pcommon.Value) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you use iterator here?

for k, v := attributes.All()

@codecov
Copy link

codecov bot commented Jun 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.17%. Comparing base (a5ba290) to head (499e999).
Report is 21 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7245      +/-   ##
==========================================
- Coverage   96.20%   96.17%   -0.04%     
==========================================
  Files         369      370       +1     
  Lines       22098    22290     +192     
==========================================
+ Hits        21260    21437     +177     
- Misses        626      638      +12     
- Partials      212      215       +3     
Flag Coverage Δ
badger_v1 9.85% <ø> (+<0.01%) ⬆️
badger_v2 1.83% <ø> (-0.06%) ⬇️
cassandra-4.x-v1-manual 14.81% <ø> (+<0.01%) ⬆️
cassandra-4.x-v2-auto 1.82% <ø> (-0.06%) ⬇️
cassandra-4.x-v2-manual 1.82% <ø> (-0.06%) ⬇️
cassandra-5.x-v1-manual 14.81% <ø> (+<0.01%) ⬆️
cassandra-5.x-v2-auto 1.82% <ø> (-0.06%) ⬇️
cassandra-5.x-v2-manual 1.82% <ø> (-0.06%) ⬇️
elasticsearch-6.x-v1 20.78% <ø> (+<0.01%) ⬆️
elasticsearch-7.x-v1 20.83% <ø> (-0.03%) ⬇️
elasticsearch-8.x-v1 21.01% <ø> (-0.03%) ⬇️
elasticsearch-8.x-v2 1.83% <ø> (-0.06%) ⬇️
grpc_v1 11.39% <ø> (+<0.01%) ⬆️
grpc_v2 1.83% <ø> (-0.06%) ⬇️
kafka-3.x-v1 10.21% <ø> (+<0.01%) ⬆️
kafka-3.x-v2 1.83% <ø> (-0.06%) ⬇️
memory_v2 1.83% <ø> (-0.06%) ⬇️
opensearch-1.x-v1 20.88% <ø> (-0.03%) ⬇️
opensearch-2.x-v1 20.88% <ø> (-0.03%) ⬇️
opensearch-2.x-v2 1.83% <ø> (-0.06%) ⬇️
query 1.83% <ø> (-0.06%) ⬇️
tailsampling-processor 0.51% <ø> (-0.02%) ⬇️
unittests 95.02% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yurishkuro
Copy link
Member

Both DCO checks are failing. My recommendation is to squash all commits into one and make sure it is signed correctly. See CONTRIBUTING for help.

…porters

Implement copy-on-write approach for all sanitizers:

- Check if modifications are needed before attempting changes
- Return original traces if no sanitization required
- Test mutability and create a copy if data is read-only
- Apply modifications to the working copy instead of original data

---------

Signed-off-by: Victor Nguen <nguen-victor@yandex.ru>
@victornguen
Copy link
Contributor Author

victornguen commented Jun 29, 2025

Thanks, I squashed the commits. DCO passed.

@yurishkuro yurishkuro enabled auto-merge June 29, 2025 21:04
@yurishkuro yurishkuro added this pull request to the merge queue Jun 29, 2025
Merged via the queue into jaegertracing:main with commit f31a1d9 Jun 29, 2025
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Jaeger v2 panics when exporting a span without "service.name" to multiple exporters

2 participants