From 8ca4f2ed1f846cccaa0a5e2f5ccd4af616273a1a Mon Sep 17 00:00:00 2001 From: "Eric J. Smith" Date: Thu, 31 Oct 2024 15:13:07 -0500 Subject: [PATCH] Various telemetry updates --- src/Directory.Build.props | 2 +- .../Exceptionless.Insulation.csproj | 12 ++--- src/Exceptionless.Job/Program.cs | 3 +- .../appsettings.Development.yml | 2 +- src/Exceptionless.Web/ApmExtensions.cs | 44 ++++++++++++++++++- src/Exceptionless.Web/Program.cs | 3 +- .../appsettings.Development.yml | 2 +- 7 files changed, 54 insertions(+), 14 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index dfc8b7fcfc..37b1a28030 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -16,7 +16,7 @@ true false false - 11.0.5 + 11.0.6-alpha.0.18 true diff --git a/src/Exceptionless.Insulation/Exceptionless.Insulation.csproj b/src/Exceptionless.Insulation/Exceptionless.Insulation.csproj index d2c3122cf3..5c8ab350b6 100644 --- a/src/Exceptionless.Insulation/Exceptionless.Insulation.csproj +++ b/src/Exceptionless.Insulation/Exceptionless.Insulation.csproj @@ -2,12 +2,12 @@ - - - - - - + + + + + + diff --git a/src/Exceptionless.Job/Program.cs b/src/Exceptionless.Job/Program.cs index 1a147545d1..80da975ef5 100644 --- a/src/Exceptionless.Job/Program.cs +++ b/src/Exceptionless.Job/Program.cs @@ -62,8 +62,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) var options = AppOptions.ReadFromConfiguration(config); var apmConfig = new ApmConfig(config, $"job-{jobOptions.JobName.ToLowerUnderscoredWords('-')}", options.InformationalVersion, options.CacheOptions.Provider == "redis"); - var configDictionary = config.ToDictionary("Serilog"); - Log.Information("Bootstrapping Exceptionless {JobName} job(s) in {AppMode} mode ({InformationalVersion}) on {MachineName} with settings {@Settings}", jobOptions.JobName ?? "All", environment, options.InformationalVersion, Environment.MachineName, configDictionary); + Log.Information("Bootstrapping Exceptionless {JobName} job(s) in {AppMode} mode ({InformationalVersion}) on {MachineName} with options {@Options}", jobOptions.JobName ?? "All", environment, options.InformationalVersion, Environment.MachineName, options); var builder = Host.CreateDefaultBuilder() .UseEnvironment(environment) diff --git a/src/Exceptionless.Job/appsettings.Development.yml b/src/Exceptionless.Job/appsettings.Development.yml index 063d606a2a..438c3a12c0 100644 --- a/src/Exceptionless.Job/appsettings.Development.yml +++ b/src/Exceptionless.Job/appsettings.Development.yml @@ -13,7 +13,7 @@ BaseURL: 'http://localhost:9001/#!' Serilog: MinimumLevel: - Default: Debug + Default: Information Apm: EnableLogs: false diff --git a/src/Exceptionless.Web/ApmExtensions.cs b/src/Exceptionless.Web/ApmExtensions.cs index c9d8f1bfbf..c17cd3da81 100644 --- a/src/Exceptionless.Web/ApmExtensions.cs +++ b/src/Exceptionless.Web/ApmExtensions.cs @@ -28,7 +28,7 @@ public static IHostBuilder AddApm(this IHostBuilder builder, ApmConfig config) builder.ConfigureServices(services => { services.AddSingleton(config); - services.AddHostedService(sp => new SelfDiagnosticsLoggingHostedService(sp.GetRequiredService(), config.Debug ? EventLevel.Verbose : null)); + //services.AddHostedService(sp => new SelfDiagnosticsLoggingHostedService(sp.GetRequiredService(), config.Debug ? EventLevel.Verbose : null)); services.AddOpenTelemetry().WithTracing(b => { @@ -41,6 +41,9 @@ public static IHostBuilder AddApm(this IHostBuilder builder, ApmConfig config) if (context.Request.Path.StartsWithSegments("/api/v2/push", StringComparison.OrdinalIgnoreCase)) return false; + if (context.Request.Path.StartsWithSegments("/health", StringComparison.OrdinalIgnoreCase)) + return false; + if (context.Request.Headers.UserAgent.ToString().Contains("HealthChecker")) return false; @@ -84,7 +87,30 @@ public static IHostBuilder AddApm(this IHostBuilder builder, ApmConfig config) b.AddConsoleExporter(); if (config.EnableExporter) + { + b.AddProcessor(new FilteringProcessor(activity => + { + // filter out insignificant activities + if (config.MinDurationMs > 0 && activity.Duration < TimeSpan.FromMilliseconds(config.MinDurationMs)) + return false; + + if (activity is { DisplayName: "LLEN", Parent: null }) + return false; + + if (activity.DisplayName == "Elasticsearch HEAD") + return false; + + if (activity.GetTagItem("db.statement") is not string statement) + return true; + + if (statement.EndsWith("__PING__")) + return false; + + return true; + })); + b.AddOtlpExporter(); + } }); services.AddOpenTelemetry().WithMetrics(b => @@ -174,3 +200,19 @@ public ApmConfig(IConfigurationRoot config, string processName, string? serviceV public bool Debug => _apmConfig.GetValue("Debug", false); public bool Console => _apmConfig.GetValue("Console", false); } + +public class FilteringProcessor : BaseProcessor +{ + private readonly Func _filter; + + public FilteringProcessor(Func filter) + { + _filter = filter ?? throw new ArgumentNullException(nameof(filter)); + } + + public override void OnEnd(Activity activity) + { + if (!_filter(activity)) + activity.ActivityTraceFlags &= ~ActivityTraceFlags.Recorded; + } +} diff --git a/src/Exceptionless.Web/Program.cs b/src/Exceptionless.Web/Program.cs index 38e5e2b483..ef2fa06082 100644 --- a/src/Exceptionless.Web/Program.cs +++ b/src/Exceptionless.Web/Program.cs @@ -63,8 +63,7 @@ public static IHostBuilder CreateHostBuilder(IConfigurationRoot config, string e var options = AppOptions.ReadFromConfiguration(config); var apmConfig = new ApmConfig(config, "web", options.InformationalVersion, options.CacheOptions.Provider == "redis"); - var configDictionary = config.ToDictionary("Serilog"); - Log.Information("Bootstrapping Exceptionless Web in {AppMode} mode ({InformationalVersion}) on {MachineName} with settings {@Settings}", environment, options.InformationalVersion, Environment.MachineName, configDictionary); + Log.Information("Bootstrapping Exceptionless Web in {AppMode} mode ({InformationalVersion}) on {MachineName} with options {@Options}", environment, options.InformationalVersion, Environment.MachineName, options); SetClientEnvironmentVariablesInDevelopmentMode(options); diff --git a/src/Exceptionless.Web/appsettings.Development.yml b/src/Exceptionless.Web/appsettings.Development.yml index d2b522da66..a399826abe 100644 --- a/src/Exceptionless.Web/appsettings.Development.yml +++ b/src/Exceptionless.Web/appsettings.Development.yml @@ -21,7 +21,7 @@ RunJobsInProcess: true Serilog: MinimumLevel: - Default: Debug + Default: Information Apm: EnableLogs: true