Skip to content

fix(zipkin): store remote endpoint IPs as text, not raw binary/int#1998

Merged
bobstrecansky merged 3 commits into
open-telemetry:mainfrom
jorgsowa:fix/zipkin-ipv6-json-encoding
Jul 14, 2026
Merged

fix(zipkin): store remote endpoint IPs as text, not raw binary/int#1998
bobstrecansky merged 3 commits into
open-telemetry:mainfrom
jorgsowa:fix/zipkin-ipv6-json-encoding

Conversation

@jorgsowa

@jorgsowa jorgsowa commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Zipkin's V2 JSON API expects ipv4/ipv6 on Endpoint as textual strings. Storing raw inet_pton() bytes for IPv6 produced invalid UTF-8, crashing json_encode(..., JSON_THROW_ON_ERROR) and dropping the whole span batch for any CLIENT/PRODUCER span with a net.peer.ip IPv6 address. ipv4 had the same class of bug, encoding as an integer instead of a dotted string.

Zipkin's V2 JSON API expects ipv4/ipv6 on Endpoint as textual strings.
Storing raw inet_pton() bytes for IPv6 produced invalid UTF-8, crashing
json_encode(..., JSON_THROW_ON_ERROR) and dropping the whole span batch
for any CLIENT/PRODUCER span with a net.peer.ip IPv6 address. ipv4 had
the same class of bug, encoding as an integer instead of a dotted string.
@jorgsowa
jorgsowa requested a review from a team as a code owner July 1, 2026 19:36
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.08%. Comparing base (6cb4156) to head (b4faedd).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1998      +/-   ##
============================================
+ Coverage     68.02%   68.08%   +0.05%     
- Complexity     3075     3082       +7     
============================================
  Files           459      459              
  Lines          9017     9026       +9     
============================================
+ Hits           6134     6145      +11     
+ Misses         2883     2881       -2     
Flag Coverage Δ
8.1 67.82% <100.00%> (+0.09%) ⬆️
8.2 67.97% <100.00%> (+0.06%) ⬆️
8.3 67.95% <100.00%> (+0.03%) ⬆️
8.4 67.95% <100.00%> (-0.03%) ⬇️
8.5 67.95% <100.00%> (+0.05%) ⬆️

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

Files with missing lines Coverage Δ
src/Contrib/Zipkin/SpanConverter.php 97.20% <100.00%> (+0.03%) ⬆️

... and 14 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6cb4156...b4faedd. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes Zipkin V2 JSON endpoint IP serialization by ensuring remoteEndpoint.ipv4/remoteEndpoint.ipv6 are stored as textual IP strings (preventing invalid UTF-8 / incorrect numeric encodings) and adds regression coverage to avoid span-batch drops during JSON encoding.

Changes:

  • Store remoteEndpoint.ipv4 as a dotted IPv4 string instead of ip2long() output.
  • Store remoteEndpoint.ipv6 as a textual IPv6 string (instead of raw inet_pton() bytes) with regression coverage for routable IPv6 + json_encode(..., JSON_THROW_ON_ERROR).
  • Refactor Zipkin remote endpoint tests into a data provider covering IPv4/IPv6 cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Contrib/Zipkin/SpanConverter.php Adjusts remote endpoint IP fields to be serialized as text for Zipkin V2 JSON.
tests/Unit/Contrib/Zipkin/ZipkinSpanConverterTest.php Adds/updates unit coverage for IPv4/IPv6 remote endpoint serialization and JSON encoding regression.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Contrib/Zipkin/SpanConverter.php Outdated
string $expectedKey,
string $expectedValue,
int $expectedPort,
): void {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not relevant. This code is correct according to the CI's style Check (PHP CS Fixer).

@bobstrecansky

Copy link
Copy Markdown
Contributor

@jorgsowa - ready to merge this after the comments are addressed. Thanks!

@jorgsowa
jorgsowa force-pushed the fix/zipkin-ipv6-json-encoding branch from ce211ec to cd7c5f6 Compare July 13, 2026 20:57
@jorgsowa

Copy link
Copy Markdown
Contributor Author

I applied the first comment, but not the second one. Style Check is passing, and PHP CS Fixer prevents the suggested form.

Both inet_pton() and inet_ntop() can return false. Check inet_pton()
result before passing to inet_ntop(), and check inet_ntop() result
before assigning to remoteEndpoint['ipv6']. Fall back to the original
IP string if either conversion fails.
@jorgsowa
jorgsowa force-pushed the fix/zipkin-ipv6-json-encoding branch from cd7c5f6 to b4faedd Compare July 13, 2026 21:06
@bobstrecansky
bobstrecansky merged commit 0d4bb2a into open-telemetry:main Jul 14, 2026
12 checks passed
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.

4 participants