fix(auth): exception initial character after login + otel

This commit is contained in:
Timothy Schenk 2024-09-16 21:10:52 +02:00
parent 2aedc9dae9
commit 4e9e5f4730
Signed by: rainote
SSH key fingerprint: SHA256:pnkNSDwpAnaip00xaZlVFHKKsS7T8UtOomMzvs0yITE
4 changed files with 51 additions and 101 deletions

View file

@ -1,24 +1,19 @@
repos: repos:
- repo: local - repo: local
hooks: hooks:
#Use dotnet format already installed on your machine #Use dotnet format already installed on your machine
- id: dotnet-format - id: dotnet-format
name: dotnet-format name: dotnet-format
language: system language: system
entry: dotnet format --include entry: dotnet format --include
types_or: [c#, vb] types_or: [c#, vb]
- repo: https://github.com/Mateusz-Grzelinski/actionlint-py - repo: https://github.com/Mateusz-Grzelinski/actionlint-py
rev: v1.6.26.11 rev: v1.6.26.11
hooks: hooks:
- id: actionlint - id: actionlint
additional_dependencies: [pyflakes>=3.0.1, shellcheck-py>=0.9.0.5] additional_dependencies: [pyflakes>=3.0.1, shellcheck-py>=0.9.0.5]
- repo: https://github.com/hadolint/hadolint - repo: https://github.com/hadolint/hadolint
rev: v2.12.0 rev: v2.12.0
hooks: hooks:
- id: hadolint-docker - id: hadolint-docker
args: [--ignore, SC2086] args: [--ignore, SC2086]
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.12.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --indent, '2']

View file

@ -31,7 +31,7 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var account = var account =
await _wonderkingContext.Accounts.FirstOrDefaultAsync(a => a.Id == session.AccountId, cancellationToken); await _wonderkingContext.Accounts.Include(a => a.Characters).FirstOrDefaultAsync(a => a.Id == session.AccountId, cancellationToken);
if (account is null) if (account is null)
{ {

View file

@ -40,57 +40,37 @@ var loggerFactory = LoggerFactory.Create(loggingBuilder =>
loggingBuilder.AddFile("logs/Continuity.AuthServer-{Date}.log", LogLevel.Trace); loggingBuilder.AddFile("logs/Continuity.AuthServer-{Date}.log", LogLevel.Trace);
loggingBuilder.AddFile("logs/Continuity.AuthServer-{Date}.json.log", LogLevel.Trace, isJson: true); loggingBuilder.AddFile("logs/Continuity.AuthServer-{Date}.json.log", LogLevel.Trace, isJson: true);
loggingBuilder.AddConsole(); loggingBuilder.AddConsole();
loggingBuilder.AddOpenTelemetry();
}); });
var configuration = builder.Configuration; var configuration = builder.Configuration;
if (configuration.GetValue<bool>("Tracing:Enabled"))
builder.Logging.AddOpenTelemetry(logging =>
{ {
Action<ResourceBuilder> resourceBuilderAction = r => r logging.IncludeFormattedMessage = true;
.AddService("Continuity", serviceInstanceId: Environment.MachineName); logging.IncludeScopes = true;
});
builder.Services.AddOpenTelemetry() builder.Services.AddOpenTelemetry()
.ConfigureResource(resourceBuilderAction) .WithMetrics(metrics =>
.WithTracing(tracing => {
metrics.AddRuntimeInstrumentation().AddProcessInstrumentation().AddMeter("Microsoft.AspNetCore.Hosting", nameof(Continuity.AuthServer))
.ConfigureResource(resourceBuilder => resourceBuilder.AddService("Continuity", serviceNamespace: "Wonderking", serviceVersion: "0.0.1"));
})
.WithTracing(tracing =>
{
if (builder.Environment.IsDevelopment())
{ {
tracing.AddSource(nameof(Server)); tracing.SetSampler<AlwaysOnSampler>();
tracing.AddSource("MassTransit"); }
tracing.AddEntityFrameworkCoreInstrumentation(options => options.SetDbStatementForText = true); tracing.AddEntityFrameworkCoreInstrumentation(options => options.SetDbStatementForText = true).AddNpgsql();
tracing.AddNpgsql(); });
})
.WithMetrics(metrics =>
{
metrics.AddRuntimeInstrumentation();
metrics.AddProcessInstrumentation();
});
builder.Logging.AddOpenTelemetry(logging => builder.Services.AddMetrics();
{
var resourceBuilder = ResourceBuilder.CreateDefault(); builder.Services.Configure<OpenTelemetryLoggerOptions>(logging => logging.AddOtlpExporter());
resourceBuilderAction(resourceBuilder); builder.Services.ConfigureOpenTelemetryMeterProvider(meter => meter.AddOtlpExporter());
logging.SetResourceBuilder(resourceBuilder); builder.Services.ConfigureOpenTelemetryTracerProvider(tracer => tracer.AddOtlpExporter());
logging.IncludeFormattedMessage = true;
logging.IncludeScopes = true;
});
builder.Services.Configure<OpenTelemetryLoggerOptions>(logging =>
{
logging.AddOtlpExporter(options =>
{
options.Endpoint = new Uri(configuration["OTLP:Logging:Endpoint"] ?? string.Empty);
});
});
builder.Services.ConfigureOpenTelemetryMeterProvider(metrics =>
{
metrics.AddOtlpExporter(options =>
options.Endpoint = new Uri(configuration["OTLP:Metrics:Endpoint"] ?? string.Empty));
});
builder.Services.ConfigureOpenTelemetryTracerProvider(tracing =>
{
tracing.AddZipkinExporter(options =>
options.Endpoint = new Uri(configuration["Zipkin:Endpoint"] ?? string.Empty));
tracing.AddOtlpExporter(options =>
options.Endpoint = new Uri(configuration["OTLP:Tracing:Endpoint"] ?? string.Empty));
});
}
builder.Services.AddHealthChecks() builder.Services.AddHealthChecks()
.AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]); .AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]);
@ -99,7 +79,7 @@ builder.Services.AddDbContextPool<WonderkingContext>(o =>
{ {
o.UseNpgsql( o.UseNpgsql(
$"Host={configuration["DB:Host"]};Username={configuration["DB:Username"]};Password={configuration["DB:Password"]};Database={configuration["DB:Database"]};Port={configuration["DB:Port"]}") $"Host={configuration["DB:Host"]};Username={configuration["DB:Username"]};Password={configuration["DB:Password"]};Database={configuration["DB:Database"]};Port={configuration["DB:Port"]}")
.EnableSensitiveDataLogging().UseLazyLoadingProxies().UseLoggerFactory(loggerFactory); .EnableSensitiveDataLogging().UseLoggerFactory(loggerFactory);
}); });
builder.Services.AddSingleton<CharacterStatsMappingConfiguration>( builder.Services.AddSingleton<CharacterStatsMappingConfiguration>(

View file

@ -14,10 +14,8 @@ services:
- DB:Password=continuity - DB:Password=continuity
- Game:Data:Path=/app/data/ - Game:Data:Path=/app/data/
- Tracing:Enabled=true - Tracing:Enabled=true
- OTLP:Tracing:Endpoint=http://otel-collector:4317 - OTEL_EXPORTER_OTLP_ENDPOINT=http://aspire:18889
- OTLP:Logging:Endpoint=http://otel-collector:4317 - Logging:LogLevel:Default=Debug
- OTLP:Metrics:Endpoint=http://otel-collector:4317
- Zipkin:Endpoint=http://zipkin:9411/api/v2/spans
networks: networks:
- continuity - continuity
ports: ports:
@ -43,47 +41,24 @@ services:
- POSTGRES_PASSWORD=continuity - POSTGRES_PASSWORD=continuity
networks: networks:
- continuity - continuity
ports:
- 5432:5432
volumes: volumes:
- db-data:/var/lib/postgresql/data - db-data:/var/lib/postgresql/data
healthcheck: healthcheck:
test: [ CMD-SHELL, 'pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}' ] test: [CMD-SHELL, "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 10s interval: 10s
timeout: 3s timeout: 3s
retries: 3 retries: 3
mem_limit: 1024m mem_limit: 1024m
jaeger: aspire:
container_name: continuity-jaeger image: mcr.microsoft.com/dotnet/aspire-dashboard:8.0.0
image: jaegertracing/all-in-one:1.53.0
restart: always
depends_on:
- server
networks: networks:
- continuity - continuity
expose:
- 14250
- 14268
- 14269
ports:
- 16686:16686
environment: environment:
- COLLECTOR_OTLP_ENABLED=true - DOTNET_DASHBOARD_UNSECURED_ALLOW_ANONYMOUS=true
- METRICS_STORAGE_TYPE=prometheus - Dashboard:Frontend:AuthMode=Unsecured
- PROMETHEUS_SERVER_URL=http://prometheus:9090
- PROMETHEUS_QUERY_SUPPORT_SPANMETRICS_CONNECTOR=true
- PROMETHEUS_QUERY_NORMALIZE_CALLS=true
- PROMETHEUS_QUERY_NORMALIZE_DURATION=true
zipkin:
container_name: continuity-zipkin
image: openzipkin/zipkin:3.0.5
restart: always
ports: ports:
- 9411:9411 - 18888:18888
networks:
- continuity
networks: networks:
continuity: continuity: