Skip to content

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

  1. Performans İzleme
  2. Uygulama yanıt süreleri
  3. Bağımlılık performansı
  4. Kaynak kullanımı
  5. Exception tracking

  6. Kullanılabilirlik

  7. Uptime monitoring
  8. Web testleri
  9. Alerting
  10. SLA takibi

  11. Kullanıcı Analizi

  12. Kullanıcı davranışları
  13. Kullanım istatistikleri
  14. Conversion analizi
  15. Kullanıcı segmentasyonu

Application Insights Kullanımı

  1. 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();
        }
    }
    

  2. Ö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);
        }
    }
    

  3. 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;
            }
        }
    }
    

  4. 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

  1. Telemetri Tasarımı
  2. Anlamlı event isimleri
  3. Ölçülebilir metrikler
  4. Context bilgileri
  5. Sampling stratejileri

  6. Performans

  7. Telemetri hacmi yönetimi
  8. Sampling kullanımı
  9. Batch işlemler
  10. Async operasyonlar

  11. Güvenlik

  12. Hassas veri filtreleme
  13. PII veri yönetimi
  14. Erişim kontrolü
  15. Data retention

  16. Monitoring

  17. Alert kuralları
  18. Dashboard tasarımı
  19. Metric aggregation
  20. Trend analizi

Mülakat Soruları

Temel Sorular

  1. Application Insights nedir ve ne için kullanılır?
  2. 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.

  3. Application Insights'ın temel özellikleri nelerdir?

  4. Cevap:

    • Performans izleme
    • Exception tracking
    • Kullanıcı analizi
    • Uptime monitoring
    • Alerting
  5. Application Insights'ın avantajları nelerdir?

  6. Cevap:

    • Azure entegrasyonu
    • Zengin telemetri
    • Güçlü analiz
    • Kolay kurulum
    • Ölçeklenebilirlik
  7. Telemetri nedir?

  8. Cevap: Telemetri, uygulama davranışı ve performansı hakkında toplanan verilerdir. Event, metric, dependency ve exception gibi farklı türleri vardır.

  9. Sampling nedir?

  10. Cevap: Sampling, telemetri verilerinin belirli bir yüzdesini toplama işlemidir. Performans ve maliyet optimizasyonu için kullanılır.

Teknik Sorular

  1. Application Insights nasıl yapılandırılır?
  2. Cevap:

    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddApplicationInsightsTelemetry(Configuration);
        }
    
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseApplicationInsightsRequestTelemetry();
            app.UseApplicationInsightsExceptionTelemetry();
        }
    }
    

  3. Özel telemetri nasıl gönderilir?

  4. 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);
        }
    }
    

  5. Exception tracking nasıl yapılır?

  6. 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;
            }
        }
    }
    

  7. Performance tracking nasıl yapılır?

  8. 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;
            }
        }
    }
    

  9. Sampling nasıl yapılandırılır?

  10. Cevap:
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddApplicationInsightsTelemetry(options =>
        {
            options.EnableAdaptiveSampling = true;
            options.EnableQuickPulseMetricStream = true;
        });
    }
    

İleri Seviye Sorular

  1. Application Insights performans optimizasyonu nasıl yapılır?
  2. Cevap:

    • Sampling stratejileri
    • Telemetri hacmi yönetimi
    • Batch işlemler
    • Async operasyonlar
    • Cache kullanımı
  3. Application Insights güvenliği nasıl sağlanır?

  4. Cevap:

    • Hassas veri filtreleme
    • PII veri yönetimi
    • Erişim kontrolü
    • Data retention
    • Audit logging
  5. Application Insights monitoring ve alerting nasıl yapılır?

  6. Cevap:

    • Alert kuralları
    • Dashboard tasarımı
    • Metric aggregation
    • Trend analizi
    • Notification kanalları
  7. Application Insights ile log aggregation nasıl yapılır?

  8. Cevap:

    • Log entegrasyonu
    • Log analizi
    • Log enrichment
    • Log rotasyonu
    • Log arşivleme
  9. Application Insights ile distributed tracing nasıl yapılır?

  10. Cevap:
    • Correlation ID
    • Operation context
    • Dependency tracking
    • End-to-end tracing
    • Performance analysis