« Application Insights » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
Aucun résumé des modifications |
Aucun résumé des modifications |
||
Ligne 14 : | Ligne 14 : | ||
var telemetryClient = new TelemetryClient(configuration); | var telemetryClient = new TelemetryClient(configuration); | ||
</kode> | </kode> | ||
= Dependency injection in Prism WPF application = | |||
<filebox fn='App.xaml.cs'> | |||
// classe de type PrismApplication qui hérite de PrismApplicationBase (Prism.DryIoc) | |||
public partial class App | |||
{ | |||
protected override void RegisterTypes(IContainerRegistry containerRegistry) | |||
{ | |||
var config = TelemetryConfiguration.Active; // Reads ApplicationInsights.config file if present | |||
var telemetryClient = new TelemetryClient(config); | |||
containerRegistry.RegisterInstance(telemetryClient); | |||
} | |||
</filebox> | |||
= Send telemetry to Application Insights = | = Send telemetry to Application Insights = |
Version du 8 août 2020 à 11:25
Liens
Read ApplicationInsights.conf
// Reads ApplicationInsights.config file in the working directory TelemetryConfiguration config = TelemetryConfiguration.Active; // Reads a specific ApplicationInsights.config file TelemetryConfiguration configuration = TelemetryConfiguration.CreateFromConfiguration(File.ReadAllText("C:\\ApplicationInsights.config")); var telemetryClient = new TelemetryClient(configuration); |
Dependency injection in Prism WPF application
App.xaml.cs |
// classe de type PrismApplication qui hérite de PrismApplicationBase (Prism.DryIoc) public partial class App { protected override void RegisterTypes(IContainerRegistry containerRegistry) { var config = TelemetryConfiguration.Active; // Reads ApplicationInsights.config file if present var telemetryClient = new TelemetryClient(config); containerRegistry.RegisterInstance(telemetryClient); } |
Send telemetry to Application Insights
App_Start\WebApiConfig.cs |
public static class WebApiConfig { public static void Register(HttpConfiguration config) { /* ... */ config.Services.Add(typeof(IExceptionLogger), new AiExceptionLogger()); |
AiExceptionLogger.cs |
public class AiExceptionLogger : ExceptionLogger { public TelemetryClient AppInsights { get; set; } public AiExceptionLogger() { AppInsights = new TelemetryClient(); } public override void Log(ExceptionLoggerContext context) { if (context != null && context.Exception != null) { AppInsights.TrackException(context.Exception); } base.Log(context); |
Visualiser les données dans visual studio
Cloud Explorer → My Subcription → Application Insights → clique-droit sur My Application Insight → Search
Installation
- Automatique: Azure web app → Monitoring → Application Insights → No data? Automatically instrument your ASP.NET app (restart required)
- Manuel: Azure web app → Extensions → Add → Application Insights
Ajouter les paquets NuGet
- Tous: Clique-droit sur le projet → Add → Application Insights Telemetry
- Exception tracking: Microsoft.ApplicationInsights.Web
ApplicationInsights.config |
<?xml version="1.0" encoding="utf-8"?> <ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings"> <TelemetryInitializers> <!-- ... --> </TelemetryInitializers> <TelemetryModules> <!-- ... --> </TelemetryModules> <TelemetryProcessors> <!-- ... --> </TelemetryProcessors> <TelemetryChannel Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.ServerTelemetryChannel, Microsoft.AI.ServerTelemetryChannel"/> </ApplicationInsights> |
Modules | Description | Package Nuget |
---|---|---|
Dependency Tracking | appels au bdd et services externes | Microsoft.ApplicationInsights.DependencyCollector |
Performance collector | CPU, mémoire, charge réseau | Microsoft.ApplicationInsights.PerfCounterCollector |
Application Insights Diagnostics Telemetry | erreur dans l'App Insight elle-même | Microsoft.ApplicationInsights |
Developer Mode | force l'envoie des données immédiatement lorsque le debugger est attaché | Microsoft.ApplicationInsights.WindowsServer |
Web Request Tracking | code et temps de réponse des requêtes HTTP | Microsoft.ApplicationInsights.Web |
Exception tracking | exceptions non-gérées | Microsoft.ApplicationInsights.Web |
EventSource Tracking | envoyer les EventSource comme des traces | Microsoft.ApplicationInsights.EventSourceListener |
ETW Event Tracking | envoyer les événements des ETW providers comme des traces | Microsoft.ApplicationInsights.EtwCollector |
Microsoft.ApplicationInsights | Core API pour le SDK | Microsoft.ApplicationInsights |
Erreurs
AI: Performance counter is not available in the web app supported list
These warnings are expected as computer level counters are not accessible from the Azure Web App environment. There's no way to turn off any particular counter from the default counters collection, so please safely ignore them as it doesn't affect anything.
AI: Server telemetry channel was not initialized
AI: Server telemetry channel was not initialized. So persistent storage is turned off. You need to call ServerTelemetryChannel.Initialize(). Currently monitoring will continue but if telemetry cannot be sent it will be dropped.
Le fichier ApplicationInsights.config est manquant.