MVC项目中Azure Application Insights实时指标显示应用离线或使用旧版SDK问题排查求助
Hey there, let's troubleshoot this frustrating real-time metrics issue you're hitting with your MVC 4.5.2 project in Visual Studio 2017. I've worked through similar scenarios before, so here are targeted checks to get your real-time data showing up:
1. Verify Compatibility of Your Application Insights SDK Versions
Real-time metrics (QuickPulse) has strict version requirements, especially for older .NET Framework versions like 4.5.2. Make sure these critical packages are on a compatible version (minimum 2.7.0 or later for most components):
Microsoft.ApplicationInsights.WebMicrosoft.ApplicationInsights.PerfCounterCollectorMicrosoft.ApplicationInsights.RuntimeTelemetry(if present)
To check versions:
- Right-click the assembly in your Bin folder → Properties → Look at the "File Version" field
- Or check your
packages.configfile for entries like:<package id="Microsoft.ApplicationInsights.Web" version="2.21.0" targetFramework="net452" />
If you're on an older version, update these packages via NuGet (make sure to update all dependent packages to avoid version conflicts).
2. Confirm Real-Time Metrics Configuration in ApplicationInsights.config
Double-check that your ApplicationInsights.config includes the required modules and processors for QuickPulse:
- Ensure this TelemetryModule is present under the
<TelemetryModules>section:<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector" /> - Ensure this TelemetryProcessor is present under the
<TelemetryProcessors>section:<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryProcessor, Microsoft.AI.PerfCounterCollector" />
Also verify your InstrumentationKey is correctly set in the <InstrumentationKey> element, and that no code in your project is overriding this key at runtime (check Global.asax or startup code for manual configuration).
3. Validate Access to Real-Time Metrics Endpoint
While Fiddler shows general data is flowing, real-time metrics uses a dedicated WebSocket endpoint. Confirm your local environment can reach this endpoint:
- Try accessing it in a browser, or use
ping rt.services.visualstudio.comin Command Prompt. - If you're behind a corporate firewall, ensure this endpoint is whitelisted. Note that Fiddler might not capture WebSocket traffic by default—enable WebSocket capturing in Fiddler's settings (Tools → Options → Connections → Check "Enable WebSocket") to verify the connection is being established.
4. Check IIS Express vs. Local IIS Permissions
If you're running the project via IIS Express, it might have restricted permissions that block WebSocket connections for real-time metrics. Try switching to Local IIS (Right-click project → Properties → Web → Select "Local IIS" under Servers) to see if the issue resolves. This ensures the app runs under a more permissive context.
5. Clean Cache and Restart
Sometimes stale build artifacts or VS cache can cause unexpected issues:
- Delete your project's
BinandObjfolders - Restart Visual Studio entirely
- Rebuild and redeploy your project
6. Rule Out Custom Telemetry Configuration Overrides
If you've added custom telemetry configuration code (e.g., in Global.asax.cs), ensure you haven't accidentally removed or disabled the QuickPulse module. For example, if you're manually initializing TelemetryConfiguration, make sure you're not clearing the default modules:
// Avoid this if you want to keep QuickPulse enabled TelemetryConfiguration.Active.TelemetryModules.Clear();
If none of these steps resolve the issue, sharing the exact version numbers of all Application Insights-related packages in your Bin directory would help narrow down further.
内容的提问来源于stack exchange,提问作者UliKunkelUSA

