Skip to content

Replace legacy EventSource providers with source-generated logging#4058

Open
marcschier wants to merge 2 commits into
masterfrom
remove-legacy-eventsource
Open

Replace legacy EventSource providers with source-generated logging#4058
marcschier wants to merge 2 commits into
masterfrom
remove-legacy-eventsource

Conversation

@marcschier

Copy link
Copy Markdown
Collaborator

Description

Replace the four stack-owned System.Diagnostics.Tracing.EventSource providers with source-generated ILogger logging.

  • Preserve the legacy provider category names, numeric event IDs, event names, levels, message structure, and semantic structured fields.
  • Remove ClientTraceFlags.EventLog and route ClientTraceFlags.Log through the canonical OPC-UA-Core compatibility events.
  • Keep ChannelManager activities and metrics while moving its diagnostic events to the Opc.Ua.ChannelManager logger category.
  • Replace EventListener-based unit and stress-test collection with structured logger providers.
  • Document the ETW removal, retained compatibility identities, and migration path for existing consumers.

Validation

  • dotnet build UA.slnx -c Release -p:CustomTestTarget=net10.0 -p:NuGetAudit=false
  • Focused Core, Client, and Server logging tests on net10.0 and net48
  • Stress harness Release build and SessionRecoversFromAcceptButStallAsync
  • Direct AOT test application: 115 tests passed
  • dotnet test UA.slnx -c Release -p:CustomTestTarget=net48 -p:NuGetAudit=false

The full net10.0 dotnet test UA.slnx invocation is currently blocked by the repository's existing mixed VSTest/Microsoft.Testing.Platform configuration in Opc.Ua.Aot.Tests; the AOT project builds and its test executable passes directly.

Related Issues

Checklist

  • I have signed the CLA and read the CONTRIBUTING doc.
  • I have added tests that prove my fix is effective or that my feature works and increased code coverage.
  • I have added all necessary documentation.
  • I have verified that my changes do not introduce (new) build or analyzer warnings.
  • I ran all tests locally using the UA.slnx solution against at least .net framework and .net 10, and all passed.
  • I fixed all failing and flaky tests in the CI pipelines and all CodeQL warnings.
  • I have addressed all PR feedback received.

Comment thread src/Opc.Ua.Client/OpcUaClientCompatibilityLog.cs Outdated
@marcschier
marcschier marked this pull request as ready for review July 20, 2026 06:02
Copilot AI review requested due to automatic review settings July 20, 2026 06:02

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

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

This PR replaces stack-owned EventSource diagnostics with source-generated ILogger compatibility logging, updates stress-test telemetry collection accordingly, and documents the ETW removal/migration path.

Changes:

  • Introduces compatibility ILogger categories + retained EventId/EventName contracts for former EventSource providers (OPC-UA-Core, OPC-UA-Client, OPC-UA-Server, Opc.Ua.ChannelManager).
  • Updates core/client/server codepaths to emit compatibility logs and removes EventSource usage + related tests.
  • Reworks stress-test diagnostics collection from EventListener to structured ILogger recording and updates docs.

Reviewed changes

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

Show a summary per file
File Description
tests/Opc.Ua.Test.Common/RecordingLoggerProvider.cs Adds a recording ILoggerProvider to capture structured logs for unit/stress assertions.
tests/Opc.Ua.Stress.Tests/README.md Updates failure-inspection guidance to refer to structured logs instead of EventSource.
tests/Opc.Ua.Stress.Tests/Channels/Soak/LongSoakTests.cs Wires stress telemetry explicitly into the channel manager under test.
tests/Opc.Ua.Stress.Tests/Channels/Soak/CombinatorialMatrixTests.cs Wires stress telemetry explicitly into the channel manager under test.
tests/Opc.Ua.Stress.Tests/Channels/Integration/ServerOutageRecoveryTests.cs Ensures metrics/log collector is used for channel-manager diagnostics during integration stress.
tests/Opc.Ua.Stress.Tests/Channels/Integration/IntegrationTestBase.cs Extends CreateChannelManager helper to accept an override telemetry context.
tests/Opc.Ua.Stress.Tests/Channels/Integration/FailoverLeaseSwapTests.cs Passes collector telemetry to channel manager so structured logs are captured.
tests/Opc.Ua.Stress.Tests/Channels/Integration/CertRotationLiveTests.cs Passes collector telemetry to channel manager for structured log capture.
tests/Opc.Ua.Stress.Tests/Channels/Helpers/MetricsCollector.cs Replaces EventListener-based event capture with RecordingLoggerProvider-based structured capture.
tests/Opc.Ua.Stress.Tests/Channels/Chaos/TransparentReconnectChaosTests.cs Wires collector telemetry into channel manager creation.
tests/Opc.Ua.Stress.Tests/Channels/Chaos/BlockAcceptChaosTests.cs Moves collector lifetime outward and routes telemetry into channel manager.
tests/Opc.Ua.Stress.Tests/Channels/Chaos/AcceptButStallChaosTests.cs Makes collector/telemetry wiring explicit and simplifies disposal flow.
tests/Opc.Ua.Server.Tests/OpcUaServerEventSourceTests.cs Removes EventSource-based unit tests for retired provider.
tests/Opc.Ua.Server.Tests/OpcUaServerCompatibilityLoggingTests.cs Adds contract tests validating retained server compatibility events via ILogger.
tests/Opc.Ua.Core.Tests/Types/Utils/OpcUaCompatibilityLoggingTests.cs Adds contract tests validating retained core + channel-manager compatibility events via ILogger.
tests/Opc.Ua.Core.Tests/Stack/Client/ClientChannelManagerManagedTests.cs Updates channel-manager diagnostics tests to assert structured logs instead of EventSource.
tests/Opc.Ua.Core.Tests/Stack/Client/ClientBaseTests.cs Updates tests to validate compatibility log events and removes EventLog flag coverage.
tests/Opc.Ua.Client.Tests/Stack/Client/ClientChannelManagerManagedTests.cs Updates channel-manager diagnostics tests to assert structured logs instead of EventSource.
tests/Opc.Ua.Client.Tests/OpcUaClientCompatibilityLoggingTests.cs Adds contract tests validating retained client compatibility events via ILogger.
src/Opc.Ua.Server/Subscription/MonitoredItem/MonitoredItem.cs Removes commented legacy EventSource calls in monitored-item publish readiness checks.
src/Opc.Ua.Server/Session/Session.cs Routes session compatibility events through compatibility ILogger category.
src/Opc.Ua.Server/Server/StandardServer.cs Routes request compatibility events through compatibility ILogger category.
src/Opc.Ua.Server/Server/OpcUaServerEventSource.cs Removes the retired server EventSource implementation.
src/Opc.Ua.Server/Server/OpcUaServerCompatibilityLog.cs Adds server compatibility [LoggerMessage] definitions preserving legacy identities.
src/Opc.Ua.Server/EventIds.cs Adds retained server compatibility event id constants.
src/Opc.Ua.Core/Types/Utils/OpcUaCoreEventSource.cs Removes the retired core EventSource implementation.
src/Opc.Ua.Core/Types/Utils/OpcUaCoreCompatibilityLog.cs Adds core compatibility [LoggerMessage] definitions preserving legacy identities.
src/Opc.Ua.Core/Types/Utils/LoggerUtils.cs Removes the core EventSource singleton from Utils.
src/Opc.Ua.Core/Stack/Tcp/TcpServerChannel.cs Emits SendResponse via compatibility ILogger category instead of EventSource.
src/Opc.Ua.Core/Stack/Client/ClientBase.cs Removes EventLog flag and emits core compatibility events via ILogger.
src/Opc.Ua.Core/Stack/Client/Channels/Internal/ClientChannelManagerMetrics.cs Updates docs/comments to reflect structured logs replacing EventSource.
src/Opc.Ua.Core/Stack/Client/Channels/Internal/ClientChannelManagerDiagnostics.cs Replaces channel-manager EventSource emissions with source-generated structured logs + Activities.
src/Opc.Ua.Core/Stack/Client/Channels/ClientChannelManager.cs Refactors constructors and injects diagnostics logger category wiring.
src/Opc.Ua.Core/EventIds.cs Adds retained core + channel-manager compatibility categories and event ids.
src/Opc.Ua.Client/Subscription/Classic/Subscription.cs Emits client compatibility subscription-state via compatibility ILogger category.
src/Opc.Ua.Client/Subscription/Classic/MonitoredItem.cs Emits notification compatibility events via compatibility ILogger category and removes per-class debug log.
src/Opc.Ua.Client/Session/Subscription/ClassicSubscriptionEngine.cs Emits publish/notification compatibility events via compatibility ILogger category.
src/Opc.Ua.Client/Session/Session.ChannelManager.cs Updates docs/comments to reflect structured logs replacing EventSource.
src/Opc.Ua.Client/OpcUaClientEventSource.cs Removes the retired client EventSource implementation.
src/Opc.Ua.Client/OpcUaClientCompatibilityLog.cs Adds client compatibility [LoggerMessage] definitions preserving legacy identities.
src/Opc.Ua.Client/EventIds.cs Adds retained client compatibility category and event ids.
docs/migrate/2.0.x/telemetry.md Documents ETW provider removals, compatibility identities, and migration steps from EventListener/ETW.
docs/Sessions.md Updates channel-manager diagnostics contract to structured logs and lists retained compatibility event table.
docs/Diagnostics.md Updates diagnostic docs to reference structured logs instead of EventSource for correlation.
docs/DeveloperGuide.md Documents the “narrow exception” for retained EventSource-compatibility ids in [LoggerMessage].
Comments suppressed due to low confidence (2)

tests/Opc.Ua.Stress.Tests/Channels/Helpers/MetricsCollector.cs:1

  • m_loggerProvider.Records builds a full snapshot array (ConcurrentQueue.ToArray()) each time CaptureNewLogRecords() runs. Because this method is called from Events and CountEvents, repeated calls can become allocation-heavy and trend toward O(n²) behavior as the log grows during long stress runs. Consider adding an incremental retrieval API to RecordingLoggerProvider (e.g., a thread-safe TryDequeue/drain method for test capture, or an internal locked list with an index cursor) so MetricsCollector can fetch only newly appended records without re-snapshotting the entire history.
    tests/Opc.Ua.Test.Common/RecordingLoggerProvider.cs:1
  • RecordedLogRecord.Properties is exposed as IReadOnlyDictionary<,> but you’re passing a mutable Dictionary<,> instance through, which allows downstream test code to mutate captured records if it casts (or if future refactors expose the concrete type). Wrapping properties in a read-only view (or copying into an immutable/read-only dictionary type) would make captured records stable and reduce the chance of accidental mutation affecting later assertions.

Comment thread src/Opc.Ua.Server/Server/OpcUaServerCompatibilityLog.cs Outdated
Comment thread src/Opc.Ua.Core/Stack/Client/Channels/ClientChannelManager.cs
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.77528% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.56%. Comparing base (12f770b) to head (4791bd1).
⚠️ Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
...annels/Internal/ClientChannelManagerDiagnostics.cs 64.28% 3 Missing and 7 partials ⚠️
...Core/Stack/Client/Channels/ClientChannelManager.cs 88.23% 0 Missing and 4 partials ⚠️
...pc.Ua.Client/Subscription/Classic/MonitoredItem.cs 33.33% 1 Missing and 1 partial ⚠️
...Opc.Ua.Client/Subscription/Classic/Subscription.cs 75.00% 0 Missing and 1 partial ⚠️
src/Opc.Ua.Server/Session/Session.cs 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4058      +/-   ##
==========================================
- Coverage   73.86%   73.56%   -0.31%     
==========================================
  Files        1345     1342       -3     
  Lines      180038   180007      -31     
  Branches    31678    31677       -1     
==========================================
- Hits       132993   132424     -569     
- Misses      36290    36876     +586     
+ Partials    10755    10707      -48     
Files with missing lines Coverage Δ
...rc/Opc.Ua.Client/Session/Session.ChannelManager.cs 77.39% <ø> (ø)
.../Session/Subscription/ClassicSubscriptionEngine.cs 70.23% <100.00%> (-0.36%) ⬇️
...t/Channels/Internal/ClientChannelManagerMetrics.cs 94.44% <ø> (ø)
src/Opc.Ua.Core/Stack/Client/ClientBase.cs 78.68% <100.00%> (+1.29%) ⬆️
src/Opc.Ua.Core/Stack/Tcp/TcpServerChannel.cs 60.11% <100.00%> (+0.05%) ⬆️
src/Opc.Ua.Core/Types/Utils/LoggerUtils.cs 77.77% <ø> (-2.23%) ⬇️
src/Opc.Ua.Server/Server/StandardServer.cs 73.77% <100.00%> (+0.34%) ⬆️
...Server/Subscription/MonitoredItem/MonitoredItem.cs 79.31% <ø> (ø)
...Opc.Ua.Client/Subscription/Classic/Subscription.cs 66.23% <75.00%> (-0.08%) ⬇️
src/Opc.Ua.Server/Session/Session.cs 75.58% <66.66%> (+<0.01%) ⬆️
... and 3 more

... and 55 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants