Skip to content

Fix: Address-family mismatch confirmed: the shared mock server in test_otlp_e - #5530

Open
M001N wants to merge 1 commit into
open-telemetry:mainfrom
M001N:oss-engine/08e6d55a-121a595b
Open

Fix: Address-family mismatch confirmed: the shared mock server in test_otlp_e#5530
M001N wants to merge 1 commit into
open-telemetry:mainfrom
M001N:oss-engine/08e6d55a-121a595b

Conversation

@M001N

@M001N M001N commented Aug 9, 2026

Copy link
Copy Markdown

Summary

Gave the test-only OTLPSpanExporterForTesting helper class (in test_otlp_exporter_mixin.py) a default endpoint of "http://127.0.0.1:4317" via kwargs.setdefault, applied only when a test doesn't already pass its own endpoint (so test_otlp_exporter_endpoint, which explicitly parametrizes endpoint/insecure combinations, is unaffected). This makes every real-connection test target the same IPv4 address the mock server binds to, eliminating the address-family mismatch. Updated the handful of assertions that hard-coded the old 'localhost:4317' string (two warning-log message checks, two mocked insecure_channel call assertions, and the server.address metric attribute check) to expect 127.0.0.1:4317 / 127.0.0.1, since those exporters now genuinely resolve to that address. Production default endpoint values in exporter.py were not touched. test_otlp_trace_exporter.py and test_otlp_metrics_exporter.py only assert against mocked gRPC channels (never make a real socket connection) and are verifying the production default endpoint value, so they were left unchanged as instructed.

Problem

open-telemetry/opentelemetry-python issue reference: #4062

Root Cause

Address-family mismatch confirmed: the shared mock server in test_otlp_exporter_mixin.py binds explicitly to the IPv4 loopback (127.0.0.1:4317), but tests exercising real exports rely on the exporter's default endpoint resolution of the ambiguous hostname 'localhost', which can resolve to the IPv6 loopback (::1) first depending on OS/DNS/hosts configuration. This is purely a test-fixture issue, not a production defect.

Testing

PASS - all 51 tests passed, 5 skipped (Windows-only timing skips, pre-existing and unrelated to this fix)

Related Issue

#4062

…tname

The mock gRPC server used by test_otlp_exporter_mixin.py binds only to
the IPv4 loopback address (127.0.0.1), but the tests that actually
exercise real connections to that server relied on the exporter's
default endpoint, which resolves the ambiguous hostname 'localhost'.
On environments where 'localhost' resolves to the IPv6 loopback
address (::1) first, the exporter would try to connect to whatever
(if anything) is listening on ::1:4317 instead of the mock server,
causing confusing, environment-dependent test failures/hangs.

Give OTLPSpanExporterForTesting an explicit default endpoint of
http://127.0.0.1:4317 (only applied when the test doesn't already
pass its own endpoint, e.g. test_otlp_exporter_endpoint), matching
the address the mock server actually binds to. Update the couple of
assertions that hard-coded the old 'localhost:4317' string for
exporters that now connect via 127.0.0.1.

Tests in test_otlp_trace_exporter.py and test_otlp_metrics_exporter.py
only assert against mocked channels (never make a real connection) and
still validate the production default endpoint value, so they are left
untouched.

Assisted-by: Claude Sonnet 5
@M001N
M001N requested a review from a team as a code owner August 9, 2026 16:02
@linux-foundation-easycla

Copy link
Copy Markdown

CLA Not Signed

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant