Skip to content

Conversation

martincostello
Copy link
Member

@martincostello martincostello commented Oct 3, 2025

Verified the test improvements by changing this line of code to use v0.133.0 of the collector (see #6565):

image: otel/opentelemetry-collector:0.136.0@sha256:98fd3b410ae8a939be9588f1580c4b7c3da6ebba49f5363df4259a827aabb779

With that change, the metrics tests in this PR fail due to the error event being detected, with a message like the below printed in the test output:

tests-1           | [xUnit.net 00:00:20.79]         [Error] HTTP request to http://otel-collector:4318/v1/metrics failed. Response: \x08\x03\x120proto: wrong wireType = 1 for field BucketCounts. Exception: System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).
tests-1           | [xUnit.net 00:00:20.79]            at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
tests-1           | [xUnit.net 00:00:20.79]            at OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient.OtlpHttpExportClient.SendExportRequest(Byte[] buffer, Int32 contentLength, DateTime deadlineUtc, CancellationToken cancellationToken) in /repo/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpHttpExportClient.cs:line 34
tests-1           | [xUnit.net 00:00:20.79]         [Verbose] MetricReader event: 'OpenTelemetry.Tests.DelegatingExporter`1[OpenTelemetry.Metrics.Metric].Export failed.'
... <snip>
tests-1           | Total tests: 26
tests-1           |      Passed: 21
tests-1           |      Failed: 5

Making the same change to use v0.133.0 in main, the tests do not fail.

Changes

  • Refactor the OTLP OpenCollector integration tests by:
    • Verify that there are no warnings or errors during the integration tests.
    • Log event levels to aid debugging.
    • Refactor tests to avoid duplication and fix Visual Studio refactoring suggestions.
    • Add a gauge and a histogram to the metrics test for additional coverage.
  • Log the HTTP response content, if available, if exporting metrics fails.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

- Refactor tests to use `[MemberData]` to avoid duplication.
- Fix code analysis suggestions.
- Log event level.
Verify that there are no warnings or errors during the integration tests.
Refactor tests to de-duplicate assertion code.
- Add a gauge and a histogram to the metrics test.
- Rename variable.
- Refactor use of `Assert.Single()`.
Log the HTTP response body, if available.

Resolves open-telemetry#6454.
@github-actions github-actions bot added the pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package label Oct 3, 2025
Copy link

codecov bot commented Oct 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.64%. Comparing base (0ea6c23) to head (0add777).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6564      +/-   ##
==========================================
- Coverage   86.67%   86.64%   -0.03%     
==========================================
  Files         258      258              
  Lines       11895    11909      +14     
==========================================
+ Hits        10310    10319       +9     
- Misses       1585     1590       +5     
Flag Coverage Δ
unittests-Project-Experimental 86.56% <100.00%> (-0.03%) ⬇️
unittests-Project-Stable 86.33% <100.00%> (-0.23%) ⬇️

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

Files with missing lines Coverage Δ
...ol/Implementation/ExportClient/OtlpExportClient.cs 100.00% <100.00%> (ø)
...mplementation/ExportClient/OtlpGrpcExportClient.cs 76.34% <100.00%> (+1.06%) ⬆️
...mplementation/ExportClient/OtlpHttpExportClient.cs 100.00% <100.00%> (ø)
...tation/OpenTelemetryProtocolExporterEventSource.cs 84.52% <100.00%> (+1.19%) ⬆️

... and 4 files with indirect coverage changes

@martincostello martincostello marked this pull request as ready for review October 3, 2025 10:52
@martincostello martincostello requested a review from a team as a code owner October 3, 2025 10:52
@Copilot Copilot AI review requested due to automatic review settings October 3, 2025 10:52
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the OpenTelemetry Collector integration tests to improve error detection and debugging while adding response body logging when HTTP exports fail. The changes enhance test reliability by verifying no warnings or errors occur during tests and provide better debugging information when issues arise.

  • Refactored integration tests to use MemberData instead of InlineData for better maintainability
  • Added verification that no warnings or errors occur during integration tests
  • Enhanced HTTP export error logging to include response body content for better debugging

Reviewed Changes

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

Show a summary per file
File Description
IntegrationTests.cs Refactored test cases to use MemberData, added error/warning validation, and improved test structure
OpenTelemetryProtocolExporterEventSource.cs Updated HttpRequestFailed method to include response body parameter
OtlpHttpExportClient.cs Added response body retrieval when HTTP export fails
OtlpGrpcExportClient.cs Added response body retrieval and proper resource disposal for gRPC exports
OtlpExportClient.cs Added helper method to safely extract response body content

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Kielek
Copy link
Member

Kielek commented Oct 7, 2025

@alanwest, @rajkumar-rangaraj - there should be no performance impact in the standard cases. It is reading body response only when exception occured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package
Projects
None yet
2 participants