Skip to content

Commit eff54d7

Browse files
committed
Change condition to be targeted to when using old npgsql
1 parent 8eb27e6 commit eff54d7

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/Components/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
2727
</ItemGroup>
2828

29+
<!-- When targeting net8.0 or net9.0, we use older Npgsql versions (8.x/9.x) whose metrics
30+
don't align with the OpenTelemetry spec. LEGACY_NPGSQL enables custom histogram views. -->
31+
<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0' or '$(TargetFramework)' == 'net9.0'">
32+
<DefineConstants>$(DefineConstants);LEGACY_NPGSQL</DefineConstants>
33+
</PropertyGroup>
34+
2935
<!-- Npgsql EF needs to match the same major version as the underlying Npgsql assemblies. -->
3036
<!-- This is to override CentralPackageTransitivePinningEnabled -->
3137
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">

src/Components/Aspire.Npgsql/NpgsqlCommon.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ public static void AddNpgsqlMetrics(MeterProviderBuilder meterProviderBuilder)
1111
meterProviderBuilder
1212
.AddMeter("Npgsql");
1313

14-
#if !NET10_0_OR_GREATER
15-
// starting with Npgsql 10.0, the metrics align with OpenTelemetry's spec
16-
// see https://github.com/npgsql/npgsql/commit/a27566ff3e75ab1f75feb6d24cb69cdbd3340ab4
14+
#if LEGACY_NPGSQL
15+
// Npgsql versions prior to 10.0 don't align their metrics with the OpenTelemetry spec,
16+
// so custom histogram bucket boundaries are needed for the duration metrics.
17+
// See https://github.com/npgsql/npgsql/commit/a27566ff3e75ab1f75feb6d24cb69cdbd3340ab4
1718
double[] secondsBuckets = [0, 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10];
1819

1920
meterProviderBuilder

0 commit comments

Comments
 (0)