CodexBloom - Programming Q&A Platform

How to ensure real-time telemetry updates with SignalR in an ASP.NET Core application?

πŸ‘€ Views: 55 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-01
ASP.NET Core SignalR Application Insights C#

I've hit a wall trying to I'm upgrading from an older version and I've searched everywhere and can't find a clear answer. I'm working on an ASP.NET Core application that uses SignalR for real-time updates, and I'm trying to send telemetry data to Azure Application Insights during specific events. I've set up the Application Insights SDK (version 2.13.0) and integrated it with my SignalR hub. However, I'm encountering an issue where the telemetry isn't being sent in real-time as expected. Instead, it seems to be batching the events, leading to delays in the data appearing in Application Insights. Here’s a snippet of how I’m currently capturing the telemetry inside my hub method: ```csharp public class MyHub : Hub { private readonly TelemetryClient _telemetryClient; public MyHub(TelemetryClient telemetryClient) { _telemetryClient = telemetryClient; } public async Task SendMessage(string user, string message) { // Capture telemetry when a message is sent _telemetryClient.TrackEvent("MessageSent", new Dictionary<string, string> { { "User", user }, { "Message", message } }); await Clients.All.SendAsync("ReceiveMessage", user, message); } } ``` I've confirmed that my `TelemetryClient` is properly configured in `Startup.cs`. The issue seems to arise when multiple messages are sent in rapid succession. Instead of each event being logged immediately, they appear to be queued and sent collectively after a short delay. I attempted to adjust the telemetry configuration by setting `TelemetryConfiguration.Active.EnableAdaptiveSampling = false;` in the `ConfigureServices` method, but this did not resolve the issue. Is there a best practice for ensuring real-time telemetry updates in this scenario? Are there other configuration options I might be missing, or is there a better way to handle telemetry in a SignalR context? My development environment is Windows. Has anyone else encountered this? I'm coming from a different tech stack and learning C#. My team is using C# for this desktop app.