弃用 OpenTelemetry,并建立日志驱动的真实慢接口基线

This commit is contained in:
2026-08-11 11:32:50 +08:00 Unverified
parent 9708f81764
commit 292d029459
9 changed files with 87 additions and 157 deletions
@@ -1,6 +1,6 @@
using System.Diagnostics.Metrics;
using Jiaowu.Api.Infrastructure.Observability;
using Jiaowu.Api.Infrastructure.Persistence;
using Microsoft.AspNetCore.Http;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging.Abstractions;
@@ -40,7 +40,7 @@ public sealed class DatabaseCommandTelemetryInterceptorTests
}
[Fact]
public async Task Ef_command_records_duration_metric()
public async Task Ef_command_executes_with_logging_interceptor()
{
await using var connection =
new SqliteConnection("Data Source=:memory:");
@@ -52,25 +52,9 @@ public sealed class DatabaseCommandTelemetryInterceptorTests
await using (var setupDb = new AppDbContext(setupOptions))
await setupDb.Database.EnsureCreatedAsync();
double? recordedDuration = null;
using var listener = new MeterListener
{
InstrumentPublished = (instrument, meterListener) =>
{
if (instrument.Meter.Name ==
DatabaseCommandTelemetryInterceptor.MeterName &&
instrument.Name == "jiaowu.db.command.duration")
{
meterListener.EnableMeasurementEvents(instrument);
}
}
};
listener.SetMeasurementEventCallback<double>(
(_, measurement, _, _) => recordedDuration = measurement);
listener.Start();
var interceptor = new DatabaseCommandTelemetryInterceptor(
new ObservabilityOptions(),
new HttpContextAccessor(),
NullLogger<DatabaseCommandTelemetryInterceptor>.Instance);
var queryOptions = new DbContextOptionsBuilder<AppDbContext>()
.UseSqlite(connection)
@@ -82,7 +66,6 @@ public sealed class DatabaseCommandTelemetryInterceptorTests
.TagWith("Observability.Tests.TermCount")
.CountAsync();
Assert.NotNull(recordedDuration);
Assert.True(recordedDuration >= 0);
Assert.Equal(0, await db.AcademicTerms.CountAsync());
}
}