You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
System.Transactions.TransactionsEventSource cannot be enabled due to Event ID failure #50848
When one tries to enable System.Transactions.TransactionsEventSource an error happens:
ERROR: Exception in Command Processing for EventSource System.Transactions.TransactionsEventSource: Event SetActivityId has ID 40 which is already in use.
Configuration
Which version of .NET is the code running on? .NET5.0
What OS and version, and what distro if applicable? Windows 10
What is the architecture (x64, x86, ARM, ARM64)? x64
Reproduction
public class MyEventListener : EventListener
{
protected override void OnEventSourceCreated(EventSource eventSource)
{
if (eventSource.Name.StartsWith("System.Transaction"))
{
EnableEvents(eventSource, EventLevel.LogAlways, EventKeywords.All);
}
}
protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
//message will contain the error here
}
}
Other information
My guess is that the private void SetActivityId(string str) method in TransactionsWtwProvider.cs misses the NonEvent attribute.
TransactionsEtwProvider.SetActivityId does not appear to access the TransactionsEtwProvider instance. If you made it static, then that would also prevent EventSource from treating it as an event method, like NonEventAttribute.
AsyncTransactionScopeTests.AsyncTSTest enables the event source, but I think it does not detect the error because it just collects the logged events and then ignores them unless the test fails for some other reason.
@HongGit This appears to be an issue in System.Transactions and its uses of Activities. Please let us know if we can help with the investigation of the issue.
This use of SetActivityId(transactionIdentifier) looks wrong anyway; the activity ID that it sets will also affect subsequent non-transaction events from the same thread. Preferably, TransactionsEtwProvider should use a method like EventSource.Write<T> (string? eventName, ref System.Diagnostics.Tracing.EventSourceOptions options, ref Guid activityId, ref Guid relatedActivityId, ref T data) and pass the activity ID as a parameter, instead of touching the per-thread activity ID. Alas, that method looks suitable for TraceLogging events only; the EventSource class doesn't seem to have a similar public or protected method for manifest-based events. The alternative is to save the original activity ID of the thread and restore it at the end.
Activity
KalleOlaviNiemitalo commentedon Apr 7, 2021
runtime/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs
Line 1158 in cf258a1
TransactionsEtwProvider.SetActivityId does not appear to access the TransactionsEtwProvider instance. If you made it
static, then that would also prevent EventSource from treating it as an event method, like NonEventAttribute.runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
Line 3062 in cf258a1
KalleOlaviNiemitalo commentedon Apr 7, 2021
AsyncTransactionScopeTests.AsyncTSTest enables the event source, but I think it does not detect the error because it just collects the logged events and then ignores them unless the test fails for some other reason.
runtime/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs
Lines 62 to 66 in cf258a1
runtime/src/libraries/System.Transactions.Local/tests/AsyncTransactionScopeTests.cs
Line 102 in cf258a1
runtime/src/libraries/System.Transactions.Local/tests/TransactionTracingEventListener.cs
Lines 97 to 100 in cf258a1
tommcdon commentedon Apr 12, 2021
@HongGit This appears to be an issue in System.Transactions and its uses of Activities. Please let us know if we can help with the investigation of the issue.
KalleOlaviNiemitalo commentedon Nov 30, 2023
This use of
SetActivityId(transactionIdentifier)looks wrong anyway; the activity ID that it sets will also affect subsequent non-transaction events from the same thread. Preferably, TransactionsEtwProvider should use a method like EventSource.Write<T> (string? eventName, ref System.Diagnostics.Tracing.EventSourceOptions options, ref Guid activityId, ref Guid relatedActivityId, ref T data) and pass the activity ID as a parameter, instead of touching the per-thread activity ID. Alas, that method looks suitable for TraceLogging events only; the EventSource class doesn't seem to have a similar public or protected method for manifest-based events. The alternative is to save the original activity ID of the thread and restore it at the end.