From 63d6c8d9469bf77ef797e812da6a5dd6d866f7ec Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Tue, 24 Dec 2024 17:58:56 -0500 Subject: [PATCH 1/2] fixed telemetry not working --- .build/Build.CI.cs | 4 +- .../.idea.LaunchPad/.idea/git_toolbox_prj.xml | 15 +++++ .../Conventions/FluentValidationConvention.cs | 10 ++-- .../Conventions/OptionsConvention.cs | 2 +- .../Conventions/SerilogTelemetryConvention.cs | 22 ++++++++ ...Rocket.Surgery.LaunchPad.Foundation.csproj | 1 + .../Conventions/SerilogTelemetryConvention.cs | 56 ------------------- .../Rocket.Surgery.LaunchPad.Telemetry.csproj | 2 - .../Helpers/GraphQlExtension.cs | 10 ++-- 9 files changed, 51 insertions(+), 71 deletions(-) create mode 100644 .idea/.idea.LaunchPad/.idea/git_toolbox_prj.xml create mode 100644 src/Foundation/Conventions/SerilogTelemetryConvention.cs delete mode 100644 src/Telemetry/Conventions/SerilogTelemetryConvention.cs diff --git a/.build/Build.CI.cs b/.build/Build.CI.cs index 4cab168a8..7884da706 100644 --- a/.build/Build.CI.cs +++ b/.build/Build.CI.cs @@ -66,7 +66,7 @@ public static RocketSurgeonGitHubActionsConfiguration CiMiddleware(RocketSurgeon .ExcludeRepositoryConfigurationFiles() .Jobs.OfType() .First(z => z.Name.Equals("build", StringComparison.OrdinalIgnoreCase)); - _ = job + job .UseDotNetSdks("8.0", "9.0") .ConfigureStep(step => step.FetchDepth = 0) .PublishLogs(); @@ -76,7 +76,7 @@ public static RocketSurgeonGitHubActionsConfiguration CiMiddleware(RocketSurgeon public static RocketSurgeonGitHubActionsConfiguration LintStagedMiddleware(RocketSurgeonGitHubActionsConfiguration configuration) { - _ = configuration + configuration .Jobs.OfType() .First(z => z.Name.Equals("Build", StringComparison.OrdinalIgnoreCase)) .UseDotNetSdks("8.0", "9.0"); diff --git a/.idea/.idea.LaunchPad/.idea/git_toolbox_prj.xml b/.idea/.idea.LaunchPad/.idea/git_toolbox_prj.xml new file mode 100644 index 000000000..02b915b85 --- /dev/null +++ b/.idea/.idea.LaunchPad/.idea/git_toolbox_prj.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/src/Foundation/Conventions/FluentValidationConvention.cs b/src/Foundation/Conventions/FluentValidationConvention.cs index f25961bf3..898da97f2 100644 --- a/src/Foundation/Conventions/FluentValidationConvention.cs +++ b/src/Foundation/Conventions/FluentValidationConvention.cs @@ -45,7 +45,7 @@ public void Register(IConventionContext context, IConfiguration configuration, I { ArgumentNullException.ThrowIfNull(context); - _ = context.TypeProvider + context.TypeProvider .Scan( services, z => z @@ -68,13 +68,13 @@ public void Register(IConventionContext context, IConfiguration configuration, I )) { // need to do validations using ValidateOnStart - _ = services.Decorate(); - _ = services.AddSingleton(); - _ = services.AddSingleton(typeof(IValidateOptions<>), typeof(HealthCheckFluentValidationOptions<>)); + services.Decorate(); + services.AddSingleton(); + services.AddSingleton(typeof(IValidateOptions<>), typeof(HealthCheckFluentValidationOptions<>)); } else { - _ = services.AddSingleton(typeof(IValidateOptions<>), typeof(FluentValidationOptions<>)); + services.AddSingleton(typeof(IValidateOptions<>), typeof(FluentValidationOptions<>)); } services.TryAddEnumerable(ServiceDescriptor.Describe(typeof(IPipelineBehavior<,>), typeof(ValidationPipelineBehavior<,>), _options.MediatorLifetime)); diff --git a/src/Foundation/Conventions/OptionsConvention.cs b/src/Foundation/Conventions/OptionsConvention.cs index f311a7bec..0eed26ad0 100644 --- a/src/Foundation/Conventions/OptionsConvention.cs +++ b/src/Foundation/Conventions/OptionsConvention.cs @@ -57,7 +57,7 @@ public void Register(IConventionContext context, IConfiguration configuration, I { var attribute = options.GetCustomAttribute()!; #pragma warning disable IL2060 - _ = _configureMethod + _configureMethod .MakeGenericMethod(options) .Invoke(null, [services, attribute.OptionsName, configuration.GetSection(attribute.ConfigurationKey)]); #pragma warning restore IL2060 diff --git a/src/Foundation/Conventions/SerilogTelemetryConvention.cs b/src/Foundation/Conventions/SerilogTelemetryConvention.cs new file mode 100644 index 000000000..036514ae0 --- /dev/null +++ b/src/Foundation/Conventions/SerilogTelemetryConvention.cs @@ -0,0 +1,22 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; +using Rocket.Surgery.Conventions; +using Rocket.Surgery.LaunchPad.Serilog; +using Serilog; + +namespace Rocket.Surgery.LaunchPad.Foundation.Conventions; + +/// +/// Defines serilog telemetry configuration +/// +[PublicAPI] +[ExportConvention] +[ConventionCategory(ConventionCategory.Core)] +public partial class SerilogTelemetryConvention : ISerilogConvention +{ + /// + public void Register(IConventionContext context, IConfiguration configuration, IServiceProvider services, LoggerConfiguration loggerConfiguration) + { + loggerConfiguration.WriteTo.OpenTelemetry(_ => { }, configuration.GetValue); + } +} diff --git a/src/Foundation/Rocket.Surgery.LaunchPad.Foundation.csproj b/src/Foundation/Rocket.Surgery.LaunchPad.Foundation.csproj index c309f5d34..79d2b6344 100644 --- a/src/Foundation/Rocket.Surgery.LaunchPad.Foundation.csproj +++ b/src/Foundation/Rocket.Surgery.LaunchPad.Foundation.csproj @@ -38,6 +38,7 @@ + diff --git a/src/Telemetry/Conventions/SerilogTelemetryConvention.cs b/src/Telemetry/Conventions/SerilogTelemetryConvention.cs deleted file mode 100644 index 303001934..000000000 --- a/src/Telemetry/Conventions/SerilogTelemetryConvention.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using OpenTelemetry.Logs; -using OpenTelemetry.Metrics; -using OpenTelemetry.Trace; -using Rocket.Surgery.Conventions; -using Rocket.Surgery.Conventions.DependencyInjection; -using Rocket.Surgery.LaunchPad.Serilog; -using Serilog; -using Serilog.Sinks.OpenTelemetry; - -namespace Rocket.Surgery.LaunchPad.Telemetry.Conventions; - -/// -/// Defines serilog telemetry configuration -/// -[PublicAPI] -[ConventionCategory(ConventionCategory.Core)] -public partial class SerilogTelemetryConvention : ISerilogConvention, IServiceConvention -{ - /// - public void Register(IConventionContext context, IConfiguration configuration, IServiceProvider services, LoggerConfiguration loggerConfiguration) - { - loggerConfiguration.WriteTo.OpenTelemetry( - options => - { - services.GetRequiredService>(); - var di = services.GetRequiredService>(); - options.BatchingOptions.BatchSizeLimit = di.CurrentValue.BatchingOptions.BatchSizeLimit; - options.BatchingOptions.BufferingTimeLimit = di.CurrentValue.BatchingOptions.BufferingTimeLimit; - options.BatchingOptions.EagerlyEmitFirstEvent = di.CurrentValue.BatchingOptions.EagerlyEmitFirstEvent; - options.BatchingOptions.QueueLimit = di.CurrentValue.BatchingOptions.QueueLimit; - options.BatchingOptions.RetryTimeLimit = di.CurrentValue.BatchingOptions.RetryTimeLimit; - options.Endpoint = di.CurrentValue.Endpoint; - options.FormatProvider = di.CurrentValue.FormatProvider; - options.Headers = di.CurrentValue.Headers; - options.HttpMessageHandler = di.CurrentValue.HttpMessageHandler; - options.IncludedData = di.CurrentValue.IncludedData; - options.LevelSwitch = di.CurrentValue.LevelSwitch; - options.LogsEndpoint = di.CurrentValue.LogsEndpoint; - options.OnBeginSuppressInstrumentation = di.CurrentValue.OnBeginSuppressInstrumentation; - options.Protocol = di.CurrentValue.Protocol; - options.ResourceAttributes = di.CurrentValue.ResourceAttributes; - options.RestrictedToMinimumLevel = di.CurrentValue.RestrictedToMinimumLevel; - options.TracesEndpoint = di.CurrentValue.TracesEndpoint; - } - ); - } - - /// - public void Register(IConventionContext context, IConfiguration configuration, IServiceCollection services) - { - services.AddOptions(); - } -} diff --git a/src/Telemetry/Rocket.Surgery.LaunchPad.Telemetry.csproj b/src/Telemetry/Rocket.Surgery.LaunchPad.Telemetry.csproj index 8686abc7c..edf833547 100644 --- a/src/Telemetry/Rocket.Surgery.LaunchPad.Telemetry.csproj +++ b/src/Telemetry/Rocket.Surgery.LaunchPad.Telemetry.csproj @@ -7,7 +7,5 @@ - - diff --git a/test/Sample.Graphql.Tests/Helpers/GraphQlExtension.cs b/test/Sample.Graphql.Tests/Helpers/GraphQlExtension.cs index 6d5efc10a..3bb2a77ec 100644 --- a/test/Sample.Graphql.Tests/Helpers/GraphQlExtension.cs +++ b/test/Sample.Graphql.Tests/Helpers/GraphQlExtension.cs @@ -28,7 +28,7 @@ public Task Start(IAlbaHost host) public IHostBuilder Configure(IHostBuilder builder) { - _ = builder.ConfigureServices( + builder.ConfigureServices( z => z .AddW3CLogging(_ => { }) .AddHttpLogging(_ => { }) @@ -38,12 +38,12 @@ public IHostBuilder Configure(IHostBuilder builder) opt => opt.IncludeExceptionDetails = true ) ); - _ = builder.ConfigureServices( + builder.ConfigureServices( s => { - _ = s.AddHttpClient(); - _ = s.AddRocketClient(); - _ = s.ConfigureOptions(); + s.AddHttpClient(); + s.AddRocketClient(); + s.ConfigureOptions(); } ); From 9f61928c5c906cc0ea61e84880bd7d6c14d0b64d Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Wed, 25 Dec 2024 00:09:51 -0500 Subject: [PATCH 2/2] fixed telemetry --- Directory.Packages.props | 16 ++++++++-------- src/Mapping/DateTimeMapper.cs | 8 +++++--- test/coverage.runsettings | 1 + 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 60a3e7d6e..708609ff8 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -112,14 +112,14 @@ - - - - - - - - + + + + + + + + diff --git a/src/Mapping/DateTimeMapper.cs b/src/Mapping/DateTimeMapper.cs index 5407e11d0..3c1050cbd 100644 --- a/src/Mapping/DateTimeMapper.cs +++ b/src/Mapping/DateTimeMapper.cs @@ -31,8 +31,10 @@ public static DateTimeOffset ToDateTimeOffset(DateTime source) { return source switch { - { Kind: DateTimeKind.Unspecified or DateTimeKind.Local, } => new(source.ToUniversalTime(), TimeSpan.Zero), - { Kind: DateTimeKind.Utc, } => new(source, TimeSpan.Zero), + { Kind: DateTimeKind.Unspecified } => new(source.ToUniversalTime(), TimeSpan.Zero), + { Kind: DateTimeKind.Local } => new(source.ToUniversalTime(), TimeSpan.Zero), + { Kind: DateTimeKind.Utc, } => new(source, TimeSpan.Zero), + _ => new (source), }; } -} \ No newline at end of file +} diff --git a/test/coverage.runsettings b/test/coverage.runsettings index dca2d9ceb..d6874926b 100644 --- a/test/coverage.runsettings +++ b/test/coverage.runsettings @@ -132,6 +132,7 @@ .*Microsoft\.CodeAnalysis\.Analyzers\.dll .*Microsoft\.CodeAnalysis\.BannedApiAnalyzers\.dll .*Microsoft\.CodeAnalysis\.Common\.dll + .*Microsoft\.CodeAnalysis\.CSharp\.dll .*Microsoft\.CodeAnalysis\.CSharp\.Workspaces\.dll .*Microsoft\.CodeAnalysis\.Features\.dll .*Microsoft\.CodeAnalysis\.Workspaces\.Common\.dll