diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 17b97b4..31d6f0d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,24 +1,19 @@ repos: -- repo: local - hooks: + - repo: local + hooks: #Use dotnet format already installed on your machine - - id: dotnet-format - name: dotnet-format - language: system - entry: dotnet format --include - types_or: [c#, vb] -- repo: https://github.com/Mateusz-Grzelinski/actionlint-py - rev: v1.6.26.11 - hooks: - - id: actionlint - additional_dependencies: [pyflakes>=3.0.1, shellcheck-py>=0.9.0.5] -- repo: https://github.com/hadolint/hadolint - rev: v2.12.0 - hooks: - - id: hadolint-docker - 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'] + - id: dotnet-format + name: dotnet-format + language: system + entry: dotnet format --include + types_or: [c#, vb] + - repo: https://github.com/Mateusz-Grzelinski/actionlint-py + rev: v1.6.26.11 + hooks: + - id: actionlint + additional_dependencies: [pyflakes>=3.0.1, shellcheck-py>=0.9.0.5] + - repo: https://github.com/hadolint/hadolint + rev: v2.12.0 + hooks: + - id: hadolint-docker + args: [--ignore, SC2086] diff --git a/Continuity.AuthServer/PacketHandlers/CharacterCreationHandler.cs b/Continuity.AuthServer/PacketHandlers/CharacterCreationHandler.cs index f27a508..b2475b2 100644 --- a/Continuity.AuthServer/PacketHandlers/CharacterCreationHandler.cs +++ b/Continuity.AuthServer/PacketHandlers/CharacterCreationHandler.cs @@ -31,7 +31,7 @@ public class CharacterCreationHandler : IPacketHandler a.Id == session.AccountId, cancellationToken); + await _wonderkingContext.Accounts.Include(a => a.Characters).FirstOrDefaultAsync(a => a.Id == session.AccountId, cancellationToken); if (account is null) { diff --git a/Continuity.AuthServer/Program.cs b/Continuity.AuthServer/Program.cs index 5b76c4e..39bf472 100644 --- a/Continuity.AuthServer/Program.cs +++ b/Continuity.AuthServer/Program.cs @@ -40,57 +40,37 @@ var loggerFactory = LoggerFactory.Create(loggingBuilder => loggingBuilder.AddFile("logs/Continuity.AuthServer-{Date}.log", LogLevel.Trace); loggingBuilder.AddFile("logs/Continuity.AuthServer-{Date}.json.log", LogLevel.Trace, isJson: true); loggingBuilder.AddConsole(); + loggingBuilder.AddOpenTelemetry(); }); var configuration = builder.Configuration; -if (configuration.GetValue("Tracing:Enabled")) + +builder.Logging.AddOpenTelemetry(logging => { - Action resourceBuilderAction = r => r - .AddService("Continuity", serviceInstanceId: Environment.MachineName); + logging.IncludeFormattedMessage = true; + logging.IncludeScopes = true; +}); - builder.Services.AddOpenTelemetry() - .ConfigureResource(resourceBuilderAction) - .WithTracing(tracing => +builder.Services.AddOpenTelemetry() + .WithMetrics(metrics => + { + 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.AddSource("MassTransit"); - tracing.AddEntityFrameworkCoreInstrumentation(options => options.SetDbStatementForText = true); - tracing.AddNpgsql(); - }) - .WithMetrics(metrics => - { - metrics.AddRuntimeInstrumentation(); - metrics.AddProcessInstrumentation(); - }); + tracing.SetSampler(); + } + tracing.AddEntityFrameworkCoreInstrumentation(options => options.SetDbStatementForText = true).AddNpgsql(); + }); - builder.Logging.AddOpenTelemetry(logging => - { - var resourceBuilder = ResourceBuilder.CreateDefault(); - resourceBuilderAction(resourceBuilder); - logging.SetResourceBuilder(resourceBuilder); - logging.IncludeFormattedMessage = true; - logging.IncludeScopes = true; - }); - builder.Services.Configure(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.AddMetrics(); + +builder.Services.Configure(logging => logging.AddOtlpExporter()); +builder.Services.ConfigureOpenTelemetryMeterProvider(meter => meter.AddOtlpExporter()); +builder.Services.ConfigureOpenTelemetryTracerProvider(tracer => tracer.AddOtlpExporter()); builder.Services.AddHealthChecks() .AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]); @@ -99,7 +79,7 @@ builder.Services.AddDbContextPool(o => { 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); + .EnableSensitiveDataLogging().UseLoggerFactory(loggerFactory); }); builder.Services.AddSingleton( diff --git a/docker-compose.yml b/docker-compose.yml index 6c5f870..f2c7e84 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,10 +14,8 @@ services: - DB:Password=continuity - Game:Data:Path=/app/data/ - Tracing:Enabled=true - - OTLP:Tracing:Endpoint=http://otel-collector:4317 - - OTLP:Logging:Endpoint=http://otel-collector:4317 - - OTLP:Metrics:Endpoint=http://otel-collector:4317 - - Zipkin:Endpoint=http://zipkin:9411/api/v2/spans + - OTEL_EXPORTER_OTLP_ENDPOINT=http://aspire:18889 + - Logging:LogLevel:Default=Debug networks: - continuity ports: @@ -43,47 +41,24 @@ services: - POSTGRES_PASSWORD=continuity networks: - continuity - ports: - - 5432:5432 volumes: - db-data:/var/lib/postgresql/data 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 timeout: 3s retries: 3 mem_limit: 1024m - jaeger: - container_name: continuity-jaeger - image: jaegertracing/all-in-one:1.53.0 - restart: always - depends_on: - - server + aspire: + image: mcr.microsoft.com/dotnet/aspire-dashboard:8.0.0 networks: - continuity - expose: - - 14250 - - 14268 - - 14269 - ports: - - 16686:16686 environment: - - COLLECTOR_OTLP_ENABLED=true - - METRICS_STORAGE_TYPE=prometheus - - 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 + - DOTNET_DASHBOARD_UNSECURED_ALLOW_ANONYMOUS=true + - Dashboard:Frontend:AuthMode=Unsecured ports: - - 9411:9411 - networks: - - continuity + - 18888:18888 networks: continuity: