Application Insights¶
Giriş¶
Application Insights, Microsoft'un bulut tabanlı bir uygulama performans yönetimi (APM) ve izleme hizmetidir. .NET uygulamalarında performans izleme, hata tespiti ve kullanıcı davranışı analizi için kullanılır. Azure ekosistemiyle tam entegrasyon sağlar.
Application Insights'ın Önemi¶
- Performans İzleme
- Uygulama yanıt süreleri
- Bağımlılık performansı
- Kaynak kullanımı
-
Exception tracking
-
Kullanılabilirlik
- Uptime monitoring
- Web testleri
- Alerting
-
SLA takibi
-
Kullanıcı Analizi
- Kullanıcı davranışları
- Kullanım istatistikleri
- Conversion analizi
- Kullanıcı segmentasyonu
Application Insights Kullanımı¶
-
Temel Kurulum
// NuGet paketleri: // Microsoft.ApplicationInsights.AspNetCore // Microsoft.ApplicationInsights.PerfCounterCollector public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddApplicationInsightsTelemetry(Configuration); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseApplicationInsightsRequestTelemetry(); app.UseApplicationInsightsExceptionTelemetry(); } }
-
Özel Telemetri
public class TelemetryService { private readonly TelemetryClient _telemetryClient; public TelemetryService(TelemetryClient telemetryClient) { _telemetryClient = telemetryClient; } public void TrackCustomEvent(string eventName, IDictionary<string, string> properties = null) { _telemetryClient.TrackEvent(eventName, properties); } public void TrackMetric(string metricName, double value) { _telemetryClient.TrackMetric(metricName, value); } public void TrackDependency(string dependencyType, string target, string dependencyName, DateTimeOffset startTime, TimeSpan duration, bool success) { _telemetryClient.TrackDependency(dependencyType, target, dependencyName, startTime, duration, success); } }
-
Exception Tracking
public class ExceptionHandlingMiddleware { private readonly RequestDelegate _next; private readonly TelemetryClient _telemetryClient; public ExceptionHandlingMiddleware(RequestDelegate next, TelemetryClient telemetryClient) { _next = next; _telemetryClient = telemetryClient; } public async Task InvokeAsync(HttpContext context) { try { await _next(context); } catch (Exception ex) { _telemetryClient.TrackException(ex); throw; } } }
-
Performance Tracking
public class PerformanceTracker { private readonly TelemetryClient _telemetryClient; public PerformanceTracker(TelemetryClient telemetryClient) { _telemetryClient = telemetryClient; } public async Task<T> TrackOperationAsync<T>(string operationName, Func<Task<T>> operation) { var startTime = DateTimeOffset.UtcNow; var timer = System.Diagnostics.Stopwatch.StartNew(); try { var result = await operation(); timer.Stop(); _telemetryClient.TrackDependency("Custom", operationName, startTime, timer.Elapsed, true); return result; } catch (Exception ex) { timer.Stop(); _telemetryClient.TrackDependency("Custom", operationName, startTime, timer.Elapsed, false); throw; } } }
Application Insights Best Practices¶
- Telemetri Tasarımı
- Anlamlı event isimleri
- Ölçülebilir metrikler
- Context bilgileri
-
Sampling stratejileri
-
Performans
- Telemetri hacmi yönetimi
- Sampling kullanımı
- Batch işlemler
-
Async operasyonlar
-
Güvenlik
- Hassas veri filtreleme
- PII veri yönetimi
- Erişim kontrolü
-
Data retention
-
Monitoring
- Alert kuralları
- Dashboard tasarımı
- Metric aggregation
- Trend analizi
Mülakat Soruları¶
Temel Sorular¶
- Application Insights nedir ve ne için kullanılır?
-
Cevap: Application Insights, Microsoft'un bulut tabanlı bir APM ve izleme hizmetidir. Performans izleme, hata tespiti ve kullanıcı davranışı analizi için kullanılır.
-
Application Insights'ın temel özellikleri nelerdir?
-
Cevap:
- Performans izleme
- Exception tracking
- Kullanıcı analizi
- Uptime monitoring
- Alerting
-
Application Insights'ın avantajları nelerdir?
-
Cevap:
- Azure entegrasyonu
- Zengin telemetri
- Güçlü analiz
- Kolay kurulum
- Ölçeklenebilirlik
-
Telemetri nedir?
-
Cevap: Telemetri, uygulama davranışı ve performansı hakkında toplanan verilerdir. Event, metric, dependency ve exception gibi farklı türleri vardır.
-
Sampling nedir?
- Cevap: Sampling, telemetri verilerinin belirli bir yüzdesini toplama işlemidir. Performans ve maliyet optimizasyonu için kullanılır.
Teknik Sorular¶
- Application Insights nasıl yapılandırılır?
-
Cevap:
public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddApplicationInsightsTelemetry(Configuration); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseApplicationInsightsRequestTelemetry(); app.UseApplicationInsightsExceptionTelemetry(); } }
-
Özel telemetri nasıl gönderilir?
-
Cevap:
public class TelemetryService { private readonly TelemetryClient _telemetryClient; public TelemetryService(TelemetryClient telemetryClient) { _telemetryClient = telemetryClient; } public void TrackCustomEvent(string eventName, IDictionary<string, string> properties = null) { _telemetryClient.TrackEvent(eventName, properties); } public void TrackMetric(string metricName, double value) { _telemetryClient.TrackMetric(metricName, value); } }
-
Exception tracking nasıl yapılır?
-
Cevap:
public class ExceptionHandlingMiddleware { private readonly RequestDelegate _next; private readonly TelemetryClient _telemetryClient; public ExceptionHandlingMiddleware(RequestDelegate next, TelemetryClient telemetryClient) { _next = next; _telemetryClient = telemetryClient; } public async Task InvokeAsync(HttpContext context) { try { await _next(context); } catch (Exception ex) { _telemetryClient.TrackException(ex); throw; } } }
-
Performance tracking nasıl yapılır?
-
Cevap:
public class PerformanceTracker { private readonly TelemetryClient _telemetryClient; public PerformanceTracker(TelemetryClient telemetryClient) { _telemetryClient = telemetryClient; } public async Task<T> TrackOperationAsync<T>(string operationName, Func<Task<T>> operation) { var startTime = DateTimeOffset.UtcNow; var timer = System.Diagnostics.Stopwatch.StartNew(); try { var result = await operation(); timer.Stop(); _telemetryClient.TrackDependency("Custom", operationName, startTime, timer.Elapsed, true); return result; } catch (Exception ex) { timer.Stop(); _telemetryClient.TrackDependency("Custom", operationName, startTime, timer.Elapsed, false); throw; } } }
-
Sampling nasıl yapılandırılır?
- Cevap:
public void ConfigureServices(IServiceCollection services) { services.AddApplicationInsightsTelemetry(options => { options.EnableAdaptiveSampling = true; options.EnableQuickPulseMetricStream = true; }); }
İleri Seviye Sorular¶
- Application Insights performans optimizasyonu nasıl yapılır?
-
Cevap:
- Sampling stratejileri
- Telemetri hacmi yönetimi
- Batch işlemler
- Async operasyonlar
- Cache kullanımı
-
Application Insights güvenliği nasıl sağlanır?
-
Cevap:
- Hassas veri filtreleme
- PII veri yönetimi
- Erişim kontrolü
- Data retention
- Audit logging
-
Application Insights monitoring ve alerting nasıl yapılır?
-
Cevap:
- Alert kuralları
- Dashboard tasarımı
- Metric aggregation
- Trend analizi
- Notification kanalları
-
Application Insights ile log aggregation nasıl yapılır?
-
Cevap:
- Log entegrasyonu
- Log analizi
- Log enrichment
- Log rotasyonu
- Log arşivleme
-
Application Insights ile distributed tracing nasıl yapılır?
- Cevap:
- Correlation ID
- Operation context
- Dependency tracking
- End-to-end tracing
- Performance analysis