Skip to content

[SignalR] Blazor's Activity.Current is null when executing a HubMethod #63313

@Hamata6

Description

@Hamata6

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In PR #57049, a change was made to set Activity.Current to null prior to the execution of dispatcher.ExecuteHubMethod in SignalR. This modification has resulted in a breaking change for telemetry correlation in Application Insights.
Impact on Application Insights telemetry:

  • The operation_Id field in Application Insights is now null instead of containing the expected correlation ID
  • The operation_ParentId field in Application Insights is now null instead of containing the parent activity ID
  • This breaks telemetry correlation chains, making it difficult to trace requests across distributed systems

Root cause: The .NET SDK for Application Insights relies on Activity.Current to establish telemetry correlation. When Activity.Current is set to null before hub method execution, the Application Insights SDK cannot capture the proper correlation context, resulting in missing operation_Id and operation_ParentId values.

I have also tested .NET 10 preview 6 and the bug is still there.

Expected Behavior

  • operation_Id should contain the trace ID from the current activity
  • operation_ParentId should contain the span ID from the parent activity
  • Telemetry correlation should be maintained throughout the SignalR hub method execution

Steps To Reproduce

  • Clone this repo . It is a newly created Blazor Web app on .NET 9 with only sample code on the Home page.
  • Add Application Insights in Visual Studio via Project > Add Application Insights Telemetry > Azure Application Insights.
  • Run solution and click button on homepage to trigger a TrackException.
  • Check your Application Insights exception logs to see that there is no operation_Id and operation_ParentId:
    exceptions | where outerMessage == "Demo Exception for Activity.Current issue" | project timestamp, outerMessage, operation_Id, operation_ParentId

Exceptions (if any)

No response

.NET Version

Since 9.0.0 through 10.0.0 preview 6

Anything else?

Output on .NET 9:
Image

Output on .NET 8:
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-signalrIncludes: SignalR clients and servers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions