Optimze worker for backtest
This commit is contained in:
@@ -13,6 +13,10 @@
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10"/>
|
||||
<PackageReference Include="Sentry" Version="5.5.1"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Core" Version="1.1.0"/>
|
||||
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0"/>
|
||||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0"/>
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0"/>
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -6,6 +6,10 @@ using Managing.Infrastructure.Databases.PostgreSql;
|
||||
using Managing.Infrastructure.Databases.PostgreSql.Configurations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql;
|
||||
using OpenTelemetry.Logs;
|
||||
using OpenTelemetry.Metrics;
|
||||
using OpenTelemetry.Resources;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
// Explicitly set the environment before creating the host builder
|
||||
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")
|
||||
@@ -71,6 +75,44 @@ var host = hostBuilder
|
||||
options.Environment = hostContext.HostingEnvironment.EnvironmentName;
|
||||
});
|
||||
|
||||
// Configure OpenTelemetry for Rider integration (Development only)
|
||||
// Rider automatically sets OTEL_EXPORTER_OTLP_ENDPOINT when running from IDE
|
||||
if (hostContext.HostingEnvironment.IsDevelopment())
|
||||
{
|
||||
var serviceName = "Managing.Workers";
|
||||
var serviceVersion = typeof(Program).Assembly.GetName().Version?.ToString() ?? "1.0.0";
|
||||
var otlpWorkerId = configuration["BacktestComputeWorker:WorkerId"] ?? Environment.MachineName;
|
||||
|
||||
services.AddOpenTelemetry()
|
||||
.ConfigureResource(resource => resource
|
||||
.AddService(serviceName, serviceVersion: serviceVersion)
|
||||
.AddAttributes(new Dictionary<string, object>
|
||||
{
|
||||
["deployment.environment"] = hostContext.HostingEnvironment.EnvironmentName,
|
||||
["worker.id"] = otlpWorkerId
|
||||
}))
|
||||
.WithMetrics(metrics =>
|
||||
{
|
||||
metrics
|
||||
.AddRuntimeInstrumentation() // GC, thread pool, etc.
|
||||
.AddMeter("Microsoft.AspNetCore.Hosting")
|
||||
.AddMeter("Microsoft.AspNetCore.Server.Kestrel")
|
||||
.AddMeter("System.Net.Http")
|
||||
.AddOtlpExporter(); // OTLP exporter for Rider integration
|
||||
})
|
||||
.WithTracing(tracing =>
|
||||
{
|
||||
tracing
|
||||
.AddHttpClientInstrumentation() // HTTP client calls
|
||||
.AddSource("Managing.Workers") // Custom activity source
|
||||
.AddSource("Managing.Application.Workers") // Worker activities
|
||||
.AddOtlpExporter(); // OTLP exporter for Rider integration
|
||||
});
|
||||
|
||||
// Note: OTLP exporter will use OTEL_EXPORTER_OTLP_ENDPOINT from Rider or environment
|
||||
// Rider automatically sets this when running from IDE, so data will be sent to Rider's OpenTelemetry service
|
||||
}
|
||||
|
||||
// Configure database
|
||||
var postgreSqlConnectionString = configuration.GetSection(Constants.Databases.PostgreSql)["ConnectionString"];
|
||||
|
||||
@@ -172,6 +214,18 @@ var host = hostBuilder
|
||||
logging.AddConsole();
|
||||
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
|
||||
|
||||
// Add OpenTelemetry logging for Rider integration (Development only)
|
||||
if (hostingContext.HostingEnvironment.IsDevelopment())
|
||||
{
|
||||
logging.AddOpenTelemetry(options =>
|
||||
{
|
||||
options.IncludeFormattedMessage = true;
|
||||
options.IncludeScopes = true;
|
||||
options.ParseStateValues = true;
|
||||
options.AddOtlpExporter(); // Uses OTEL_EXPORTER_OTLP_ENDPOINT from Rider or environment
|
||||
});
|
||||
}
|
||||
|
||||
// Filter out EF Core database command logs (SQL queries)
|
||||
logging.AddFilter("Microsoft.EntityFrameworkCore.Database.Command", LogLevel.Warning);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user