Skip to content

System.Transactions.TransactionsEventSource cannot be enabled due to Event ID failure #50848

Open

Description

@csnemes

Description

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.

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Apr 7, 2021
  2. KalleOlaviNiemitalo commented on Apr 7, 2021

    @KalleOlaviNiemitalo

    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.

    MethodInfo[] methods = eventSourceType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

  3. KalleOlaviNiemitalo commented on Apr 7, 2021

    @KalleOlaviNiemitalo

    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.

    [EventSource(
    Name = "System.Transactions.TransactionsEventSource",
    Guid = "8ac2d80a-1f1a-431b-ace4-bff8824aef0b",
    LocalizationResources = "FxResources.System.Transactions.Local.SR")]
    internal sealed class TransactionsEtwProvider : EventSource

    using (var listener = new TestEventListener(new Guid("8ac2d80a-1f1a-431b-ace4-bff8824aef0b"), System.Diagnostics.Tracing.EventLevel.Verbose))

    if (source.Name.Equals(_targetSourceName) ||
    source.Guid.Equals(_targetSourceGuid))
    {
    EnableEvents(source, _level);

  4. tommcdon commented on Apr 12, 2021

    @tommcdon
    Member

    @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.

  5. removed
    untriagedNew issue has not been triaged by the area owner
    on Jul 22, 2021
  6. added this to the Future milestone on Jul 22, 2021
  7. KalleOlaviNiemitalo commented on Nov 30, 2023

    @KalleOlaviNiemitalo

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions