Skip to content

opentelemetry-docker-tests: Refactor Docker tests to properly validate contents of exported telemetry#5220

Open
herin049 wants to merge 28 commits into
open-telemetry:mainfrom
herin049:misc/refactor-docker-tests
Open

opentelemetry-docker-tests: Refactor Docker tests to properly validate contents of exported telemetry#5220
herin049 wants to merge 28 commits into
open-telemetry:mainfrom
herin049:misc/refactor-docker-tests

Conversation

@herin049

Copy link
Copy Markdown
Contributor

Description

Prior to this refactor, the existing Docker exporter tests only verify that telemetry is correctly received by the OpenTelemetry collector. However, it does not validate that the contents of the telemetry received by the collector is semantically correct.

This refactor updates the Docker tests to properly validate the correctness of the contents of the telemetry received by the collector by updating the collector to forward all received telemetry to an additional OTLP HTTP server listening in the test runner process. The pytest tests are then able to examine the forwarded telemetry and verify the correctness of the contents of the telemetry, and that nothing was lost or mangled during exporting.

This PR also switches to using the system docker executable and likewise switches from using docker-compose to docker compose. Furthermore, it also adds functional tests for logging, which were previously not present.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

uv run tox -e docker-tests-otlpexporter

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@herin049 herin049 requested a review from a team as a code owner May 18, 2026 03:15

@xrmx xrmx 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.

As a reminder for some reason the stuff we add to test-utils may also be used by downstream users

Comment thread tox.ini Outdated
Comment thread tox.ini Outdated
Comment thread tox.ini
Comment thread tox.ini
@herin049

Copy link
Copy Markdown
Contributor Author

As a reminder for some reason the stuff we add to test-utils may also be used by downstream users

@xrmx I figured we can maybe keep the server class public since some users might find it useful. Alternatively, I can make it private for now. Let me know what you think.

herin049 added 2 commits May 18, 2026 12:26
Removed PyYAML and requests dependencies from docker-tests environment.
@herin049 herin049 requested a review from xrmx May 19, 2026 01:25
@lzchen lzchen moved this to Ready for review in Python PR digest May 28, 2026

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

Refactors opentelemetry-docker-tests OTLP exporter Docker-based functional tests so they validate the semantic contents of exported telemetry (traces/metrics/logs), by forwarding collector-received OTLP data to an in-process OTLP/HTTP test server for assertions.

Changes:

  • Introduces an OTLP protobuf-over-HTTP test server (OtlpProtoTestServer) plus unit tests for it in opentelemetry-test-utils.
  • Reworks Docker OTLP exporter functional tests to assert on exported span/metric/log record contents (including adding logs functional coverage).
  • Updates docker test orchestration to use the system docker CLI with docker compose, and adds a collector config that forwards telemetry to the in-process test server.

Reviewed changes

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

Show a summary per file
File Description
tox.ini Updates docker-tests env dependencies and switches orchestration to docker compose; reintroduces explicit lint env for test-utils.
tests/opentelemetry-test-utils/tests/test_otlp_test_server.py Adds tests covering the OTLP test server behavior across traces/metrics/logs and compression.
tests/opentelemetry-test-utils/test-requirements.txt Adds OTLP proto HTTP exporter dependency for test-utils test runs.
tests/opentelemetry-test-utils/src/opentelemetry/test/otlp_test_server.py Adds an in-process OTLP protobuf-over-HTTP server that records received telemetry into queues for assertions.
tests/opentelemetry-docker-tests/tests/otlpexporter/test_otlp_traces_functional.py Adds trace functional tests for both OTLP/HTTP and OTLP/gRPC exporters (via shared base).
tests/opentelemetry-docker-tests/tests/otlpexporter/test_otlp_metrics_functional.py Adds metrics functional tests for both OTLP/HTTP and OTLP/gRPC exporters (via shared base).
tests/opentelemetry-docker-tests/tests/otlpexporter/test_otlp_logs_functional.py Adds logs functional tests for both OTLP/HTTP and OTLP/gRPC exporters (via shared base).
tests/opentelemetry-docker-tests/tests/otlpexporter/test_otlp_http_exporter_functional.py Removes prior HTTP exporter tests that only validated receipt rather than semantic correctness.
tests/opentelemetry-docker-tests/tests/otlpexporter/test_otlp_grpc_exporter_functional.py Removes prior gRPC exporter tests that only validated receipt rather than semantic correctness.
tests/opentelemetry-docker-tests/tests/otlpexporter/init.py Replaces prior “received successfully” checks with semantic validation base classes for traces/metrics/logs using the in-process server.
tests/opentelemetry-docker-tests/tests/docker-compose.yml Updates collector service to use an explicit config file and adds host gateway mapping for forwarding.
tests/opentelemetry-docker-tests/tests/collector-config.yaml Adds collector pipelines that forward traces/metrics/logs to the host OTLP/HTTP test server.
.changelog/5220.added Adds changelog entry for the docker-tests refactor.

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

Comment thread tox.ini Outdated
Comment thread tests/opentelemetry-docker-tests/tests/otlpexporter/__init__.py Outdated

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

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Comment thread tox.ini Outdated
Comment on lines +412 to +417
recorded = self._server.get_log_record(timeout=5.0)
attrs = _attrs_to_dict(recorded.log_record.attributes)
self.assertEqual(attrs["str_key"], "hello")
self.assertEqual(attrs["int_key"], 42)
self.assertAlmostEqual(attrs["float_key"], 3.14, places=5)
self.assertEqual(attrs["bool_key"], True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

WDYT of using inline-snapshot for these assertions? IMO it makes adding new tests or updating existing ones if needed very easy.

OTOH the timestamps will need special handling and it might be clunky to deal with. We don't have to do it, just looking for your thoughts to start.

@xrmx for thoughts too

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.

Sounds good to me, up to @herin049 if we want to give it a run in this PR.

@herin049 herin049 Jul 3, 2026

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.

I've updated the PR to include some limited use of inline-snapshot to give it a try. I think it's useful in situations like these were we are validating the shape/structure of something that is well defined/deterministic. I think we would benefit the most from utilizing this package for some of the tests inside the contrib repo.

That being said, in my opinion we should be careful not to go overboard with this package by creating large snapshots that could result in validating behavior that isn't relevant to the individual test. There is a possibility that overuse can result in our tests becoming more brittle, and as a result we end up running --inline-snapshot=fix frequently, eliminating the value of the test in the first place.

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.

Thanks could you please add a note in CONTRIBUTING.md saying that docker tests are using inline-snapshots with a link to the repo or doc please?

herin049 and others added 2 commits July 2, 2026 16:35
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@herin049

herin049 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

As a reminder for some reason the stuff we add to test-utils may also be used by downstream users

I've decided to keep the test server private for now.

@xrmx xrmx enabled auto-merge July 3, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

5 participants