open-telemetry / open-telemetry/opentelemetry-python

Unit tests break in case service (e.g Jaeger) listens on ::1:4137

Open
#4,062 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
2.6k
Forks
1k
Avg merge
4d 15h
Merged PRs (30d)
19

Description

Describe your environment

OS: Ubuntu 24.04
Python version: 3.12
SDK version: main
API version: main

What happened?

Running unit tests suddenly failed for me, e.g. like this for some initially unclear reason:

========================================================== test session starts ===========================================================
platform linux -- Python 3.12.4, pytest-7.4.4, pluggy-1.5.0 -- /home/lm/git/opentelemetry-python/.tox/py312-test-opentelemetry-exporter-otlp-proto-grpc-0/bin/python
cachedir: .pytest_cache
rootdir: /home/lm/git/opentelemetry-python
configfile: pyproject.toml
collected 24 items / 22 deselected / 2 selected                                                                                          

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py::TestOTLPMetricExporter::test_shutdown 4317
None

------------------------------------------------------------- live log call --------------------------------------------------------------
ERROR    opentelemetry.exporter.otlp.proto.grpc.exporter:exporter.py:268 Failed to export metrics to localhost:4317, error code: StatusCode.UNIMPLEMENTED
FAILED

================================================================ FAILURES ================================================================
__________________________________________________ TestOTLPMetricExporter.test_shutdown __________________________________________________

self = <tests.test_otlp_metrics_exporter.TestOTLPMetricExporter testMethod=test_shutdown>

    def test_shutdown(self):
        add_MetricsServiceServicer_to_server(
            MetricsServiceServicerSUCCESS(), self.server
        )
>       self.assertEqual(
            self.exporter.export(self.metrics["sum_int"]),
            MetricExportResult.SUCCESS,
        )
E       AssertionError: <MetricExportResult.FAILURE: 1> != <MetricExportResult.SUCCESS: 0>

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py:776: AssertionError
----------------------------------------------------------- Captured log call ------------------------------------------------------------
ERROR    opentelemetry.exporter.otlp.proto.grpc.exporter:exporter.py:268 Failed to export metrics to localhost:4317, error code: StatusCode.UNIMPLEMENTED
============================================================ warnings summary ============================================================
Steps to Reproduce
  1. Open some network service (Jaeger in my case) on ::4317
  2. Start the otlp grpc unit tests
Expected Result

The tests should be independent of what else is running on the OS.
In case a network service is started and connected to, the exact same addresses for serving and connecting need to be used.
In case a listening socket can not be opened, the test shall fail.

Actual Result

This pointed me towards the solution:

ERROR    opentelemetry.exporter.otlp.proto.grpc.exporter:exporter.py:268 Failed to export metrics to localhost:4317, error code: StatusCode.UNIMPLEMENTED

I had some Jaeger instance running on IPv6 ::1:4317:

> netstat -alnp | grep 4317
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      0 ::1:4317                :::*                    LISTEN      -      

Turning it of unbreaks the unit tests again.

Why is that? It looks like the reason is that some unit tests open a server on 127.0.0.1:4317 and then connect to localhost:4317. In case something is running on IPv6 4317 the tests connect to that port. In case it is not running, the tests connect to IPv4 4317. This behavior is based on the OS level config, I guess.

Additional context

No response

Would you like to implement a fix?

No

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py, especially test_shutdown, and inspect exporter/opentelemetry-exporter-otlp-proto-grpc/opentelemetry/exporter/otlp/proto/grpc/exporter.py. Run the OTLP gRPC unit tests while a service listens on IPv6 ::1:4317. Done means the tests use consistent addresses, remain independent of other services, and fail when their listening socket cannot be opened.

Written by the indexing model from the issue text.

Assessment

Tech stack
grpc, python
Domain
networking, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.