Merge pull request 'feature/opentelemetry-support' (#92) from feature/opentelemetry-support into master
All checks were successful
Build, Package and Push Images / preprocess (push) Successful in 3s
Build, Package and Push Images / build (push) Successful in 27s
Build, Package and Push Images / sbom-scan (push) Successful in 38s
Build, Package and Push Images / sonarqube (push) Successful in 1m40s
Build, Package and Push Images / container-build (push) Successful in 1m57s
Build, Package and Push Images / container-sbom-scan (push) Successful in 38s

Reviewed-on: #92
This commit is contained in:
rainote 2023-11-20 13:29:16 +00:00
commit 5949a7dfe5
4 changed files with 81 additions and 5 deletions

View file

@ -27,7 +27,7 @@ insert_final_newline = true
[*.cs]
indent_size = 4
dotnet_sort_system_directives_first = true
dotnet_diagnostic.MA0007.severity = none
MA0004.report = DetectContext # (default) Try to detect the current context and report only if it considers ConfigureAwait is needed
MA0004.report = Always # Always report missing ConfigureAwait whatever the context
# Don't use this. qualifier

View file

@ -5,8 +5,13 @@ using MassTransit;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using Server.DB;
using Server.Services;
using Wonderking.Game.Mapping;
@ -19,9 +24,6 @@ builder.Environment.EnvironmentName = "Development";
builder.Configuration.AddJsonFile("settings.json", true, true)
.AddJsonFile($"settings.{builder.Environment.EnvironmentName}.json", true)
.AddEnvironmentVariables().Build();
builder.Services.AddSingleton<CharacterStatsMappingConfiguration>(
JsonSerializer.Deserialize<CharacterStatsMappingConfiguration>(
File.ReadAllText("config/character-stats.mapping.json")) ?? throw new InvalidOperationException());
builder.Services.AddLogging();
var loggerFactory = LoggerFactory.Create(loggingBuilder =>
@ -31,9 +33,50 @@ var loggerFactory = LoggerFactory.Create(loggingBuilder =>
loggingBuilder.AddConsole();
});
var configuration = builder.Configuration;
Action<ResourceBuilder> resourceBuilderAction = r => r
.AddService("Continuity", serviceInstanceId: Environment.MachineName);
builder.Services.AddOpenTelemetry()
.ConfigureResource(resourceBuilderAction)
.WithTracing(tracing =>
{
tracing.AddSource(nameof(Server));
tracing.SetSampler(new AlwaysOnSampler());
tracing.AddMassTransitInstrumentation();
tracing.AddEntityFrameworkCoreInstrumentation(options => options.SetDbStatementForText = true);
tracing.AddHttpClientInstrumentation();
})
.WithMetrics(metrics =>
{
metrics.AddRuntimeInstrumentation();
metrics.AddHttpClientInstrumentation();
});
builder.Logging.AddOpenTelemetry(logging =>
{
var resourceBuilder = ResourceBuilder.CreateDefault();
resourceBuilderAction(resourceBuilder);
logging.SetResourceBuilder(resourceBuilder);
logging.IncludeFormattedMessage = true;
logging.IncludeScopes = true;
});
builder.Services.Configure<OpenTelemetryLoggerOptions>(logging =>
logging.AddOtlpExporter(options => options.Endpoint = new Uri(configuration["OTLP:Endpoint"] ?? string.Empty)));
builder.Services.ConfigureOpenTelemetryMeterProvider(metrics =>
metrics.AddOtlpExporter(options => options.Endpoint = new Uri(configuration["OTLP:Endpoint"] ?? string.Empty)));
builder.Services.ConfigureOpenTelemetryTracerProvider(tracing =>
tracing.AddOtlpExporter(options => options.Endpoint = new Uri(configuration["OTLP:Endpoint"] ?? string.Empty)));
builder.Services.AddHealthChecks()
.AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]);
builder.Services.AddSingleton<CharacterStatsMappingConfiguration>(
JsonSerializer.Deserialize<CharacterStatsMappingConfiguration>(
File.ReadAllText("config/character-stats.mapping.json")) ?? throw new InvalidOperationException());
builder.Services.AddDbContextPool<WonderkingContext>(o =>
{
using var configuration = builder.Configuration;
o.UseNpgsql(
$"Host={configuration["DB:Host"]};Username={configuration["DB:Username"]};Password={configuration["DB:Password"]};Database={configuration["DB:Database"]};Port={configuration["DB:Port"]}")
.EnableSensitiveDataLogging().UseLazyLoadingProxies().UseLoggerFactory(loggerFactory);

View file

@ -89,6 +89,16 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OpenTelemetry" Version="1.7.0-alpha.1" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.7.0-alpha.1" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.7.0-alpha.1" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0-alpha.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.0.0-beta.8" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.6.0-beta.3" />
<PackageReference Include="OpenTelemetry.Instrumentation.MassTransit" Version="1.0.0-beta.3" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.5.1" />
<PackageReference Include="OpenTelemetry.PersistentStorage.FileSystem" Version="1.0.0" />
<PackageReference Include="OpenTelemetry.ResourceDetectors.Container" Version="1.0.0-beta.4" />
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0"/>
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0"/>
</ItemGroup>

View file

@ -13,6 +13,7 @@ services:
- DB:Username=continuity
- DB:Password=continuity
- Game:Data:Path=/app/data/
- OTLP:Endpoint=http://jaeger:4317
networks:
- continuity
ports:
@ -51,8 +52,30 @@ services:
timeout: 3s
retries: 3
jaeger:
container_name: continuity-jaeger
image: jaegertracing/all-in-one:1.51.0
restart: always
networks:
- continuity
ports:
- 6831:6831/udp
- 6832:6832/udp
- 5778:5778
- 16686:16686
- 4317:4317
- 4318:4318
- 14250:14250
- 14268:14268
- 14269:14269
- 9411:9411
environment:
- COLLECTOR_ZIPKIN_HOST_PORT=:9411
- COLLECTOR_OTLP_ENABLED=true
networks:
continuity:
volumes:
db-data:
prom-data: