diff --git a/Directory.Packages.props b/Directory.Packages.props index 9cedd9e..08b73f6 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -7,7 +7,19 @@ + + + + + + + + + + + + diff --git a/README.md b/README.md index 14e3abf..9de1cf6 100644 --- a/README.md +++ b/README.md @@ -104,3 +104,5 @@ dotnet new nkz-template -o My.NewApp1 --EnableGraphQL false --EnableGrpc false - [EasyCaching](https://github.com/dotnetcore/EasyCaching): EasyCaching is an open source caching library that contains basic usages and some advanced usages of caching which can help us to handle caching more easily! [Helm](https://github.com/helm/helm): Helm is a tool for managing Charts. Charts are packages of pre-configured Kubernetes resources. + +[OpenTelemetry .NET](https://github.com/open-telemetry/opentelemetry-dotnet): The .NET OpenTelemetry client. diff --git a/deployment/docker/docker-compose-infrastructure.yaml b/deployment/docker/docker-compose-infrastructure.yaml index 78da0e6..3e1c971 100644 --- a/deployment/docker/docker-compose-infrastructure.yaml +++ b/deployment/docker/docker-compose-infrastructure.yaml @@ -52,5 +52,16 @@ services: timeout: 30s retries: 15 + jaeger: + image: jaegertracing/all-in-one:1.41 + environment: + - COLLECTOR_OTLP_ENABLED=true + - LOG_LEVEL=debug + ports: + - "0.0.0.0:16686:16686" + - "0.0.0.0:4317:4317" + networks: + - dev-network + networks: dev-network: diff --git a/src/NKZSoft.Template.MessageBrokers.RabbitMq/Extensions/TracerProviderBuilderExtension.cs b/src/NKZSoft.Template.MessageBrokers.RabbitMq/Extensions/TracerProviderBuilderExtension.cs new file mode 100644 index 0000000..7fec17a --- /dev/null +++ b/src/NKZSoft.Template.MessageBrokers.RabbitMq/Extensions/TracerProviderBuilderExtension.cs @@ -0,0 +1,18 @@ +namespace NKZSoft.Template.MessageBrokers.RabbitMq.Extensions; + +using OpenTelemetry.Trace; + +public static class TracerProviderBuilderExtension +{ + /// + /// Enables the incoming requests automatic data collection for the MassTransit. + /// + /// being configured. + /// The containing settings to be used. + /// The instance of to chain the calls. + public static TracerProviderBuilder AddMassTransitOpenTelemetry(this TracerProviderBuilder builder) + { + ArgumentNullException.ThrowIfNull(builder); + return builder.AddSource("MassTransit"); + } +} diff --git a/src/NKZSoft.Template.MessageBrokers.RabbitMq/NKZSoft.Template.MessageBrokers.RabbitMq.csproj b/src/NKZSoft.Template.MessageBrokers.RabbitMq/NKZSoft.Template.MessageBrokers.RabbitMq.csproj index f5922ae..8ac199c 100644 --- a/src/NKZSoft.Template.MessageBrokers.RabbitMq/NKZSoft.Template.MessageBrokers.RabbitMq.csproj +++ b/src/NKZSoft.Template.MessageBrokers.RabbitMq/NKZSoft.Template.MessageBrokers.RabbitMq.csproj @@ -5,6 +5,7 @@ + diff --git a/src/NKZSoft.Template.Persistence.PostgreSQL/Extensions/TracerProviderBuilderExtension.cs b/src/NKZSoft.Template.Persistence.PostgreSQL/Extensions/TracerProviderBuilderExtension.cs new file mode 100644 index 0000000..8a59c3f --- /dev/null +++ b/src/NKZSoft.Template.Persistence.PostgreSQL/Extensions/TracerProviderBuilderExtension.cs @@ -0,0 +1,18 @@ +namespace NKZSoft.Template.Persistence.PostgreSQL.Extensions; + +public static class TracerProviderBuilderExtension +{ + /// + /// Enables the incoming requests automatic data collection for the PostgreSQL persistence level. + /// + /// being configured. + /// The containing settings to be used. + /// The instance of to chain the calls. + public static TracerProviderBuilder AddNgpSqlPersistenceOpenTelemetry(this TracerProviderBuilder builder) + { + ArgumentNullException.ThrowIfNull(builder); + builder.AddEntityFrameworkCoreInstrumentation(o => o.SetDbStatementForText = true) + .AddNpgsql(); + return builder; + } +} diff --git a/src/NKZSoft.Template.Persistence.PostgreSQL/GlobalUsings.cs b/src/NKZSoft.Template.Persistence.PostgreSQL/GlobalUsings.cs index 768a7aa..8007a8c 100644 --- a/src/NKZSoft.Template.Persistence.PostgreSQL/GlobalUsings.cs +++ b/src/NKZSoft.Template.Persistence.PostgreSQL/GlobalUsings.cs @@ -19,4 +19,6 @@ global using NKZSoft.Template.Common; global using NKZSoft.Template.Domain.AggregatesModel.ToDoAggregates.Entities; global using NKZSoft.Template.Domain.Common; +global using Npgsql; +global using OpenTelemetry.Trace; global using Serilog; diff --git a/src/NKZSoft.Template.Persistence.PostgreSQL/NKZSoft.Template.Persistence.PostgreSQL.csproj b/src/NKZSoft.Template.Persistence.PostgreSQL/NKZSoft.Template.Persistence.PostgreSQL.csproj index 49a6621..8a2c9a3 100644 --- a/src/NKZSoft.Template.Persistence.PostgreSQL/NKZSoft.Template.Persistence.PostgreSQL.csproj +++ b/src/NKZSoft.Template.Persistence.PostgreSQL/NKZSoft.Template.Persistence.PostgreSQL.csproj @@ -22,6 +22,9 @@ + + + @@ -49,7 +52,7 @@ - + diff --git a/src/NKZSoft.Template.Presentation.GraphQL/Extensions/ServiceCollectionExtension.cs b/src/NKZSoft.Template.Presentation.GraphQL/Extensions/ServiceCollectionExtension.cs index bc75f97..3f02ad8 100644 --- a/src/NKZSoft.Template.Presentation.GraphQL/Extensions/ServiceCollectionExtension.cs +++ b/src/NKZSoft.Template.Presentation.GraphQL/Extensions/ServiceCollectionExtension.cs @@ -20,7 +20,8 @@ public static IServiceCollection AddGraphQLPresentation(this IServiceCollection .AddFiltering() .AddSorting() .AddMutationType() - .AddMutationConventions(); + .AddMutationConventions() + .AddInstrumentation(); return services; } diff --git a/src/NKZSoft.Template.Presentation.GraphQL/NKZSoft.Template.Presentation.GraphQL.csproj b/src/NKZSoft.Template.Presentation.GraphQL/NKZSoft.Template.Presentation.GraphQL.csproj index b43fa3b..1985b3d 100644 --- a/src/NKZSoft.Template.Presentation.GraphQL/NKZSoft.Template.Presentation.GraphQL.csproj +++ b/src/NKZSoft.Template.Presentation.GraphQL/NKZSoft.Template.Presentation.GraphQL.csproj @@ -8,6 +8,7 @@ + diff --git a/src/NKZSoft.Template.Presentation.Grpc/Extensions/TracerProviderBuilderExtension.cs b/src/NKZSoft.Template.Presentation.Grpc/Extensions/TracerProviderBuilderExtension.cs new file mode 100644 index 0000000..a77212d --- /dev/null +++ b/src/NKZSoft.Template.Presentation.Grpc/Extensions/TracerProviderBuilderExtension.cs @@ -0,0 +1,18 @@ +namespace NKZSoft.Template.Presentation.Grpc.Extensions; + +public static class TracerProviderBuilderExtension +{ + /// + /// Enables the incoming requests automatic data collection for the grpc presentation level. + /// + /// being configured. + /// The containing settings to be used. + /// The instance of to chain the calls. + public static TracerProviderBuilder AddGrpcOpenTelemetry( + this TracerProviderBuilder builder) + { + ArgumentNullException.ThrowIfNull(builder); + builder.AddGrpcClientInstrumentation(); + return builder; + } +} diff --git a/src/NKZSoft.Template.Presentation.Grpc/GlobalUsings.cs b/src/NKZSoft.Template.Presentation.Grpc/GlobalUsings.cs index 9292190..4f963fa 100644 --- a/src/NKZSoft.Template.Presentation.Grpc/GlobalUsings.cs +++ b/src/NKZSoft.Template.Presentation.Grpc/GlobalUsings.cs @@ -21,4 +21,5 @@ global using NKZSoft.Template.Application.TodoItems.Models; global using NKZSoft.Template.Application.TodoItems.Queries.Get; global using NKZSoft.Template.Application.TodoItems.Queries.GetPage; +global using OpenTelemetry.Trace; diff --git a/src/NKZSoft.Template.Presentation.Grpc/NKZSoft.Template.Presentation.Grpc.csproj b/src/NKZSoft.Template.Presentation.Grpc/NKZSoft.Template.Presentation.Grpc.csproj index 20daac6..0e54613 100644 --- a/src/NKZSoft.Template.Presentation.Grpc/NKZSoft.Template.Presentation.Grpc.csproj +++ b/src/NKZSoft.Template.Presentation.Grpc/NKZSoft.Template.Presentation.Grpc.csproj @@ -12,6 +12,7 @@ + @@ -20,4 +21,8 @@ + + + + diff --git a/src/NKZSoft.Template.Presentation.Rest/Extensions/TracerProviderBuilderExtension.cs b/src/NKZSoft.Template.Presentation.Rest/Extensions/TracerProviderBuilderExtension.cs new file mode 100644 index 0000000..dc59ab1 --- /dev/null +++ b/src/NKZSoft.Template.Presentation.Rest/Extensions/TracerProviderBuilderExtension.cs @@ -0,0 +1,17 @@ +namespace NKZSoft.Template.Presentation.Rest.Extensions; + +public static class TracerProviderBuilderExtension +{ + /// + /// Enables the incoming requests automatic data collection for the rest presentation level. + /// + /// being configured. + /// The containing settings to be used. + /// The instance of to chain the calls. + public static TracerProviderBuilder AddRestOpenTelemetry( + this TracerProviderBuilder builder) + { + ArgumentNullException.ThrowIfNull(builder); + return builder.AddHttpClientInstrumentation(); + } +} diff --git a/src/NKZSoft.Template.Presentation.Rest/GlobalUsings.cs b/src/NKZSoft.Template.Presentation.Rest/GlobalUsings.cs index 4b5506f..b498fb5 100644 --- a/src/NKZSoft.Template.Presentation.Rest/GlobalUsings.cs +++ b/src/NKZSoft.Template.Presentation.Rest/GlobalUsings.cs @@ -31,6 +31,7 @@ global using NKZSoft.Template.Application.TodoItems.Queries.GetPage; global using NKZSoft.Template.Common; global using NKZSoft.Service.Configuration.Swagger; +global using OpenTelemetry.Trace; global using Serilog; diff --git a/src/NKZSoft.Template.Presentation.Rest/NKZSoft.Template.Presentation.Rest.csproj b/src/NKZSoft.Template.Presentation.Rest/NKZSoft.Template.Presentation.Rest.csproj index cad04af..e13b94e 100644 --- a/src/NKZSoft.Template.Presentation.Rest/NKZSoft.Template.Presentation.Rest.csproj +++ b/src/NKZSoft.Template.Presentation.Rest/NKZSoft.Template.Presentation.Rest.csproj @@ -10,6 +10,8 @@ + + diff --git a/src/NKZSoft.Template.Presentation.Starter/NKZSoft.Template.Presentation.Starter.csproj b/src/NKZSoft.Template.Presentation.Starter/NKZSoft.Template.Presentation.Starter.csproj index 367804c..af65c7c 100644 --- a/src/NKZSoft.Template.Presentation.Starter/NKZSoft.Template.Presentation.Starter.csproj +++ b/src/NKZSoft.Template.Presentation.Starter/NKZSoft.Template.Presentation.Starter.csproj @@ -20,6 +20,11 @@ + + + + + diff --git a/src/NKZSoft.Template.Presentation.Starter/Program.cs b/src/NKZSoft.Template.Presentation.Starter/Program.cs index 48b393d..d7c35b5 100644 --- a/src/NKZSoft.Template.Presentation.Starter/Program.cs +++ b/src/NKZSoft.Template.Presentation.Starter/Program.cs @@ -1,5 +1,9 @@ +using System.Reflection; using EFCoreSecondLevelCacheInterceptor; using NKZSoft.Template.EFCore.Caching.Redis.Extensions; +using OpenTelemetry; +using OpenTelemetry.Resources; +using OpenTelemetry.Trace; var builder = WebApplication.CreateBuilder(args); @@ -35,6 +39,26 @@ .AddMessageBroker(configuration) .AddHealthChecks(); +builder.Services.AddOpenTelemetry() + .ConfigureResource(builder => builder + .AddService( + serviceName: Assembly.GetExecutingAssembly().GetName().Name!, + serviceVersion: Assembly.GetExecutingAssembly().GetName().Version?.ToString(), + serviceInstanceId: Environment.MachineName)) + .WithTracing(builder => builder + .AddAspNetCoreInstrumentation(options => + { + options.EnableGrpcAspNetCoreSupport = true; + options.RecordException = true; + }) + .AddRestOpenTelemetry() + .AddNgpSqlPersistenceOpenTelemetry() + .AddMassTransitOpenTelemetry() + .AddOtlpExporter() + .AddConsoleExporter() + ) + .StartWithHost(); + var app = builder.Build(); using (var scope = app.Services.CreateScope()) diff --git a/src/NKZSoft.Template.Presentation.Starter/appsettings.Development.json b/src/NKZSoft.Template.Presentation.Starter/appsettings.Development.json index 59229b6..763071b 100644 --- a/src/NKZSoft.Template.Presentation.Starter/appsettings.Development.json +++ b/src/NKZSoft.Template.Presentation.Starter/appsettings.Development.json @@ -1,9 +1,9 @@ { "Serilog": { "MinimumLevel": { - "Default": "Verbose", + "Default": "Debug", "Override": { - "System.Net.Http": "Verbose" + "System.Net.Http": "Debug" } }, "EnableDbLogging": true