Skip to content

src,test: preserve Latin1 strings in fastSpan APIs#450

Open
santigimeno wants to merge 1 commit intonode-v24.x-nsolid-v6.xfrom
santi/fix_latin_1_encoding
Open

src,test: preserve Latin1 strings in fastSpan APIs#450
santigimeno wants to merge 1 commit intonode-v24.x-nsolid-v6.xfrom
santi/fix_latin_1_encoding

Conversation

@santigimeno
Copy link
Copy Markdown
Member

@santigimeno santigimeno commented Apr 10, 2026

Convert FastOneByteString inputs to UTF-8 before storing span string data so non-ASCII Latin-1 values such as ñ are emitted correctly by the N|Solid fast tracing bindings.

Add tracing coverage for Latin-1 custom attributes and introduce a debug-only fast-path test that uses TRACK_V8_FAST_API_CALL to verify pushSpanDataString() and pushSpanDataString3() actually execute through the V8 fast API path.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of Latin-1 (non‑ASCII) strings in span data so trace names and URLs are correctly encoded as UTF‑8.
  • Tests

    • Added a new test validating native FastAPI string handling with Latin‑1 characters.
    • Updated existing tests and expected trace assertions to include Latin‑1 span attributes and URL parts.

@santigimeno santigimeno requested a review from RafaelGSS April 10, 2026 21:54
@santigimeno santigimeno self-assigned this Apr 10, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

Walkthrough

Adds Latin‑1 → UTF‑8 conversion for FastOneByteString in nsolid fast API calls, updates two fast API methods to use the converter and emit tracking macros, and adds/updates tests to validate Latin‑1 handling in spans and tracing flows.

Changes

Cohort / File(s) Summary
Fast API String Conversion
src/nsolid/nsolid_api.cc
Added node_debug.h and simdutf.h. Introduced OneByteToUtf8(const FastOneByteString&) to convert Latin‑1 to UTF‑8. Updated FastPushSpanDataString and FastPushSpanDataString3 to use the converter and emit TRACK_V8_FAST_API_CALL events.
New Test: Fast API Latin‑1
test/addons/nsolid-tracing/test-fast-api-string-latin1.js
New test exercising native nsolid_api fast API string paths with Latin‑1 sequences (e.g., Espa\u00f1a, /ma\u00f1ana), includes V8 optimization instrumentation and assertions on internal fast‑API tracking counters when debug instrumentation enabled.
Test Updates — Span Attributes
test/addons/nsolid-tracing/test-otel-basic.js, test/agents/test-grpc-tracing.mjs, test/common/nsolid-grpc-agent/client.js
Added a latin1: 'Espa\u00f1a' span attribute: test expectations and client span creation now include this attribute.

Sequence Diagram(s)

sequenceDiagram
    participant JS as App JS (tracer)
    participant Binding as nsolid native binding
    participant Converter as OneByteToUtf8 (simdutf)
    participant Tracer as nsolid tracer internals

    JS->>Binding: pushSpanDataString(FastOneByteString)
    Binding->>Converter: convert_latin1_to_utf8(data)
    Converter-->>Binding: utf8 bytes
    Binding->>Tracer: record span attribute / name (UTF-8)
    Tracer-->>JS: span updated / callbacks
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • RafaelGSS
  • EHortua

Poem

🐰 In burrows of code I softly sing,
Latin‑1 blossoms into UTF‑8 spring,
España hops into each trace,
Fast calls hum with proper grace,
A carrot of bytes, a joyful ring! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: converting Latin-1 strings to UTF-8 in fast span APIs. It directly reflects the core objective of the pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch santi/fix_latin_1_encoding

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/nsolid/nsolid_api.cc`:
- Around line 98-105: The helper OneByteToUtf8 should accept empty
FastOneByteString inputs: remove or guard the DCHECK that assumes actual_length
!= 0 so empty input (input.length == 0) does not trigger a debug crash;
specifically, in OneByteToUtf8 replace the unconditional
DCHECK_NE(actual_length, 0) with a conditional guard (e.g., only DCHECK when
input.length > 0) or drop it entirely, then resize out to actual_length as
already done so empty results are handled the same way as the String::Utf8Value
slow path; reference symbols: OneByteToUtf8, FastOneByteString,
simdutf::convert_latin1_to_utf8, DCHECK_NE(actual_length, 0).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5dc324e0-d8b7-4bed-838d-0ca339d1ff44

📥 Commits

Reviewing files that changed from the base of the PR and between 1fec452 and 6b47372.

📒 Files selected for processing (5)
  • src/nsolid/nsolid_api.cc
  • test/addons/nsolid-tracing/test-fast-api-string-latin1.js
  • test/addons/nsolid-tracing/test-otel-basic.js
  • test/agents/test-grpc-tracing.mjs
  • test/common/nsolid-grpc-agent/client.js

Convert FastOneByteString inputs to UTF-8 before storing span string
data so non-ASCII Latin-1 values such as ñ are emitted correctly by the
N|Solid fast tracing bindings.

Add tracing coverage for Latin-1 custom attributes and introduce a
debug-only fast-path test that uses TRACK_V8_FAST_API_CALL to verify
pushSpanDataString() and pushSpanDataString3() actually execute through
the V8 fast API path.
@santigimeno santigimeno force-pushed the santi/fix_latin_1_encoding branch from 6b47372 to 6f3ef2c Compare April 10, 2026 22:13
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/nsolid/nsolid_api.cc (1)

2483-2490: Minor indentation inconsistency.

Lines 2487-2489 have different indentation than 2484-2486.

🧹 Suggested fix for consistent alignment
   TRACK_V8_FAST_API_CALL("nsolid.pushSpanDataString3");
   PushSpanDataStringImpl3(FromJSObject<BindingData>(receiver),
                           trace_id,
                           type,
-                         OneByteToUtf8(val1),
-                         OneByteToUtf8(val2),
-                         OneByteToUtf8(val3));
+                          OneByteToUtf8(val1),
+                          OneByteToUtf8(val2),
+                          OneByteToUtf8(val3));
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/nsolid/nsolid_api.cc` around lines 2483 - 2490, Align the argument
formatting for the PushSpanDataStringImpl3 call to match the surrounding calls:
make the lines passing FromJSObject<BindingData>(receiver), trace_id, type,
OneByteToUtf8(val1), OneByteToUtf8(val2), OneByteToUtf8(val3) use the same
indentation/column alignment as the earlier block (and as
TRACK_V8_FAST_API_CALL("nsolid.pushSpanDataString3") line), so arguments 2–6
line up consistently with the other multi-line call sites in this file and
restore consistent indentation around PushSpanDataStringImpl3 and its
parameters.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/nsolid/nsolid_api.cc`:
- Around line 2483-2490: Align the argument formatting for the
PushSpanDataStringImpl3 call to match the surrounding calls: make the lines
passing FromJSObject<BindingData>(receiver), trace_id, type,
OneByteToUtf8(val1), OneByteToUtf8(val2), OneByteToUtf8(val3) use the same
indentation/column alignment as the earlier block (and as
TRACK_V8_FAST_API_CALL("nsolid.pushSpanDataString3") line), so arguments 2–6
line up consistently with the other multi-line call sites in this file and
restore consistent indentation around PushSpanDataStringImpl3 and its
parameters.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 76417f12-6e6f-4e2b-b5ec-5a9e26fca40f

📥 Commits

Reviewing files that changed from the base of the PR and between 6b47372 and 6f3ef2c.

📒 Files selected for processing (5)
  • src/nsolid/nsolid_api.cc
  • test/addons/nsolid-tracing/test-fast-api-string-latin1.js
  • test/addons/nsolid-tracing/test-otel-basic.js
  • test/agents/test-grpc-tracing.mjs
  • test/common/nsolid-grpc-agent/client.js
✅ Files skipped from review due to trivial changes (2)
  • test/addons/nsolid-tracing/test-otel-basic.js
  • test/common/nsolid-grpc-agent/client.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/agents/test-grpc-tracing.mjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant