Skip to content

Comments

[Infra] Refactor EventSource tests#6896

Merged
rajkumar-rangaraj merged 5 commits intoopen-telemetry:mainfrom
martincostello:validate-event-sources
Feb 16, 2026
Merged

[Infra] Refactor EventSource tests#6896
rajkumar-rangaraj merged 5 commits intoopen-telemetry:mainfrom
martincostello:validate-event-sources

Conversation

@martincostello
Copy link
Member

Complements open-telemetry/opentelemetry-dotnet-contrib#3864.

Changes

Refactor EventSource validation to improve assertions.

Example assertion failure before:

    System.Exception : Method 'AspNetInstrumentationEventSource.RequestIsFilteredOut' is implemented incorrectly.
    ---- System.InvalidOperationException : Sequence contains no matching element

Example assertion failure after:

    EventSource 'OpenTelemetry.Instrumentation.AspNet.Implementation.AspNetInstrumentationEventSource' has event ID validation error(s):
    Duplicate EventId 4: methods 'InvalidConfigurationValue' and 'NullActivity' share the same ID.
    Event NullActivity is givien event ID 4 but 5 was passed to WriteEvent.
    Event NullActivity has ID 4 which is already in use.
    Event NullActivity (with ID 4) has the same task/opcode pair as event InvalidConfigurationValue (with ID 4).

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 `EventSource` validation to improve assertions.

Complements open-telemetry/opentelemetry-dotnet-contrib#3864.
@github-actions github-actions bot added pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package pkg:OpenTelemetry.Exporter.Zipkin Issues related to OpenTelemetry.Exporter.Zipkin NuGet package pkg:OpenTelemetry.Extensions.Hosting Issues related to OpenTelemetry.Extensions.Hosting NuGet package pkg:OpenTelemetry.Extensions.Propagators Issues related to OpenTelemetry.Extensions.Propagators NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package labels Feb 13, 2026
Fix code analysis warnings.
martincostello added a commit to martincostello/opentelemetry-dotnet-contrib that referenced this pull request Feb 13, 2026
@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.23%. Comparing base (28dc317) to head (9c6c9d4).
⚠️ 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    #6896      +/-   ##
==========================================
- Coverage   87.30%   87.23%   -0.08%     
==========================================
  Files         263      263              
  Lines       12387    12387              
==========================================
- Hits        10815    10806       -9     
- Misses       1572     1581       +9     
Flag Coverage Δ
unittests-Project-Experimental 86.20% <ø> (-1.06%) ⬇️
unittests-Project-Stable 86.16% <ø> (-0.98%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 5 files with indirect coverage changes

@martincostello martincostello marked this pull request as ready for review February 13, 2026 14:05
@martincostello martincostello requested a review from a team as a code owner February 13, 2026 14:05
Copilot AI review requested due to automatic review settings February 13, 2026 14:05
Copy link

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 EventSource test infrastructure to improve error reporting and validation. It replaces the old event listener-based testing approach with a more robust validation method using EventSource.GenerateManifest with strict mode, which performs IL-level inspection to verify that WriteEvent calls match their [Event] attributes. The refactoring also adds explicit duplicate event ID detection.

Changes:

  • Replaced the old MethodsAreImplementedConsistentlyWithTheirAttributes method with a new ValidateEventSourceIds method that provides clearer error messages
  • Added comprehensive tests for the helper class itself to validate various error scenarios
  • Updated all EventSource test files across multiple projects to use the new validation approach and corrected test method naming (EventSourceTest → EventSourceTests)

Reviewed changes

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

Show a summary per file
File Description
test/OpenTelemetry.Tests/Shared/TestEventListener.cs Added CA1812 warning suppression for unused internal class
test/OpenTelemetry.Tests/Shared/EventSourceTestHelper.cs Complete refactor: replaced old validation logic with GenerateManifest-based approach and duplicate ID detection
test/OpenTelemetry.Tests/EventSourceTests.cs Updated to use new ValidateEventSourceIds method and fixed test method name
test/OpenTelemetry.Tests/EventSourceTestHelperTests.cs New file: comprehensive tests for the EventSourceTestHelper validation logic
test/OpenTelemetry.Extensions.Propagators.Tests/EventSourceTests.cs Updated to use new ValidateEventSourceIds method and fixed test method name
test/OpenTelemetry.Extensions.Hosting.Tests/EventSourceTests.cs Updated to use new ValidateEventSourceIds method and fixed test method name
test/OpenTelemetry.Exporter.Zipkin.Tests/EventSourceTests.cs Updated to use new ValidateEventSourceIds method and fixed test method name
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/EventSourceTests.cs Updated to use new ValidateEventSourceIds method and fixed test method name
test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/EventSourceTests.cs Updated to use new ValidateEventSourceIds method and fixed test method names (3 tests)
test/OpenTelemetry.Api.Tests/EventSourceTests.cs Updated to use new ValidateEventSourceIds method and fixed test method name

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

- Remove unused code.
- Fix namespace.
- Fix spacing.
Remove unused `using`.
Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

nice!
At some point in future, we should be able to weaver-generate these code from a schema.

@rajkumar-rangaraj rajkumar-rangaraj added this pull request to the merge queue Feb 13, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 13, 2026
@rajkumar-rangaraj rajkumar-rangaraj added this pull request to the merge queue Feb 16, 2026
github-merge-queue bot pushed a commit that referenced this pull request Feb 16, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 16, 2026
@rajkumar-rangaraj rajkumar-rangaraj added this pull request to the merge queue Feb 16, 2026
Merged via the queue into open-telemetry:main with commit 4d91fa0 Feb 16, 2026
55 checks passed
@martincostello martincostello deleted the validate-event-sources branch February 16, 2026 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package pkg:OpenTelemetry.Exporter.Zipkin Issues related to OpenTelemetry.Exporter.Zipkin NuGet package pkg:OpenTelemetry.Extensions.Hosting Issues related to OpenTelemetry.Extensions.Hosting NuGet package pkg:OpenTelemetry.Extensions.Propagators Issues related to OpenTelemetry.Extensions.Propagators NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants