Replace legacy EventSource providers with source-generated logging#4058
Replace legacy EventSource providers with source-generated logging#4058marcschier wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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
ILoggercategories + retainedEventId/EventNamecontracts for formerEventSourceproviders (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
EventListenerto structuredILoggerrecording 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.Recordsbuilds a full snapshot array (ConcurrentQueue.ToArray()) each timeCaptureNewLogRecords()runs. Because this method is called fromEventsandCountEvents, 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 toRecordingLoggerProvider(e.g., a thread-safeTryDequeue/drain method for test capture, or an internal locked list with an index cursor) soMetricsCollectorcan fetch only newly appended records without re-snapshotting the entire history.
tests/Opc.Ua.Test.Common/RecordingLoggerProvider.cs:1RecordedLogRecord.Propertiesis exposed asIReadOnlyDictionary<,>but you’re passing a mutableDictionary<,>instance through, which allows downstream test code to mutate captured records if it casts (or if future refactors expose the concrete type). Wrappingpropertiesin 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.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ 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
🚀 New features to boost your workflow:
|
Description
Replace the four stack-owned
System.Diagnostics.Tracing.EventSourceproviders with source-generatedILoggerlogging.ClientTraceFlags.EventLogand routeClientTraceFlags.Logthrough the canonicalOPC-UA-Corecompatibility events.Opc.Ua.ChannelManagerlogger category.Validation
dotnet build UA.slnx -c Release -p:CustomTestTarget=net10.0 -p:NuGetAudit=falsenet10.0andnet48SessionRecoversFromAcceptButStallAsyncdotnet test UA.slnx -c Release -p:CustomTestTarget=net48 -p:NuGetAudit=falseThe full
net10.0dotnet test UA.slnxinvocation is currently blocked by the repository's existing mixed VSTest/Microsoft.Testing.Platform configuration inOpc.Ua.Aot.Tests; the AOT project builds and its test executable passes directly.Related Issues
Checklist