Skip to content

Adds support for Postgres v4.1 through v7 #1363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Agent/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### New Features
* Postgres client instrumentation support has been extended to include the following versions: 4.0.x, 4.1.x, 5.0.x, 6.0.x and 7.0.x [#1363](https://github.com/newrelic/newrelic-dotnet-agent/pull/1363)

### Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ SPDX-License-Identifier: Apache-2.0
</match>
</tracerFactory>


<tracerFactory name="OleDbCommandTracer">
<!-- built in ODBC driver -->
<match assemblyName="System.Data" className="System.Data.OleDb.OleDbCommand">
Expand Down Expand Up @@ -120,6 +119,9 @@ SPDX-License-Identifier: Apache-2.0
<exactMethodMatcher methodName="ExecuteNonQuery" />
<exactMethodMatcher methodName="ExecuteScalar" />
</match>
<match assemblyName="Npgsql" className="Npgsql.NpgsqlCommand" minVersion="4.1">
<exactMethodMatcher methodName="ExecuteReader" parameters="System.Data.CommandBehavior" />
</match>
</tracerFactory>

<tracerFactory name="SqlCommandTracerAsync">
Expand Down Expand Up @@ -171,13 +173,15 @@ SPDX-License-Identifier: Apache-2.0

<!-- Postgres SQL Driver-->
<match assemblyName="Npgsql" className="Npgsql.NpgsqlCommand">
<exactMethodMatcher methodName="ExecuteScalarAsync"/>
<exactMethodMatcher methodName="ExecuteNonQueryAsync"/>
<exactMethodMatcher methodName="ExecuteDbDataReaderAsync"/>
<exactMethodMatcher methodName="ExecuteNonQueryAsync"/>
<exactMethodMatcher methodName="ExecuteScalarAsync"/>
</match>
<match assemblyName="Npgsql" className="Npgsql.NpgsqlCommand" minVersion="4.1">
<exactMethodMatcher methodName="ExecuteReaderAsync"/>
</match>

</tracerFactory>

<!-- DataReader methods. DISABLED by default due to possible performance impact. Set enabled to "true" (or omit completely) to enable this instrumentation. -->
<tracerFactory name="DataReaderTracer" enabled="false">
<!-- built in MS SQL driver (framework) -->
Expand Down Expand Up @@ -241,10 +245,19 @@ SPDX-License-Identifier: Apache-2.0
</match>

<!-- Postgres data provider -->
<match assemblyName="Npgsql" className="Npgsql.NpgsqlDataReader">
<match assemblyName="Npgsql" className="Npgsql.NpgsqlDataReader" minVersion="4" maxVersion="4.1">
<exactMethodMatcher methodName="NextResult" />
<exactMethodMatcher methodName="Read" parameters="System.Boolean" />
</match>
<match assemblyName="Npgsql" className="Npgsql.NpgsqlDataReader" minVersion="4.1" maxVersion="5">
<exactMethodMatcher methodName="Read" parameters="System.Boolean" />
<exactMethodMatcher methodName="TryFastRead" />
</match>
<match assemblyName="Npgsql" className="Npgsql.NpgsqlDataReader" minVersion="5">
<exactMethodMatcher methodName="NextResult" />
<exactMethodMatcher methodName="Read" parameters="System.Boolean" />
<exactMethodMatcher methodName="TryFastRead" />
</match>
</tracerFactory>

<tracerFactory name="DataReaderTracerAsync" enabled="false">
Expand Down Expand Up @@ -278,13 +291,22 @@ SPDX-License-Identifier: Apache-2.0
</match>

<!-- Postgres data provider -->
<match assemblyName="Npgsql" className="Npgsql.NpgsqlDataReader">
<exactMethodMatcher methodName="NextResultAsync" />
<exactMethodMatcher methodName="ReadAsync" />
<match assemblyName="Npgsql" className="Npgsql.NpgsqlDataReader" minVersion="4" maxVersion="4.1">
<exactMethodMatcher methodName="NextResult" parameters="System.Boolean,System.Boolean"/>
<exactMethodMatcher methodName="Read" parameters="System.Boolean"/>
</match>
<match assemblyName="Npgsql" className="Npgsql.NpgsqlDataReader" minVersion="4.1" maxVersion="5">
<exactMethodMatcher methodName="Read" parameters="System.Boolean"/>
<exactMethodMatcher methodName="TryFastRead" />
</match>
<match assemblyName="Npgsql" className="Npgsql.NpgsqlDataReader" minVersion="5">
<exactMethodMatcher methodName="NextResult" parameters="System.Boolean,System.Threading.CancellationToken" />
<exactMethodMatcher methodName="Read" parameters="System.Boolean,System.Threading.CancellationToken" />
<exactMethodMatcher methodName="TryFastRead" />
</match>
</tracerFactory>


<!-- DbConnection.Open() -->
<tracerFactory name="OpenConnectionTracer">
<!-- built in MS SQL driver (framework) -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;net462;net471;net48;net481</TargetFrameworks>
Expand Down Expand Up @@ -35,16 +35,16 @@
<PackageReference Include="log4net.Ext.Json" Version="2.0.10.1" Condition="'$(TargetFramework)' == 'net7.0'" />

<!-- Postgres SQL .NET framework references -->
<PackageReference Include="npgsql" Version="4.0.0" Condition="'$(TargetFramework)' == 'net462'" />
<PackageReference Include="npgsql" Version="4.0.5" Condition="'$(TargetFramework)' == 'net471'" />
<PackageReference Include="npgsql" Version="4.0.10" Condition="'$(TargetFramework)' == 'net48'" />
<PackageReference Include="npgsql" Version="4.0.13" Condition="'$(TargetFramework)' == 'net481'" />
<PackageReference Include="npgsql" Version="4.0.13" Condition="'$(TargetFramework)' == 'net462'" />
<PackageReference Include="npgsql" Version="5.0.15" Condition="'$(TargetFramework)' == 'net471'" />
<PackageReference Include="npgsql" Version="6.0.7" Condition="'$(TargetFramework)' == 'net48'" />
<PackageReference Include="npgsql" Version="7.0.0" Condition="'$(TargetFramework)' == 'net481'" />

<!-- Postgres SQL .NET core references -->
<PackageReference Include="npgsql" Version="4.0.0" Condition="'$(TargetFramework)' == 'netcoreapp3.1'" />
<PackageReference Include="npgsql" Version="4.0.5" Condition="'$(TargetFramework)' == 'net5.0'" />
<PackageReference Include="npgsql" Version="4.0.10" Condition="'$(TargetFramework)' == 'net6.0'" />
<PackageReference Include="npgsql" Version="4.0.13" Condition="'$(TargetFramework)' == 'net7.0'" />
<PackageReference Include="npgsql" Version="4.1.3.1" Condition="'$(TargetFramework)' == 'netcoreapp3.1'" />
<PackageReference Include="npgsql" Version="5.0.7" Condition="'$(TargetFramework)' == 'net5.0'" />
<PackageReference Include="npgsql" Version="6.0.3" Condition="'$(TargetFramework)' == 'net6.0'" />
<PackageReference Include="npgsql" Version="7.0.1" Condition="'$(TargetFramework)' == 'net7.0'" />

<!--System.Data.SqlClient (.NET Core/5+ only) -->
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" Condition="'$(TargetFramework)' == 'netcoreapp3.1'" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public async Task SimpleQueryAsync()
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public void ParameterizedStoredProcedure(string procedureName)
{
// Switches required for v6+, no effect on v5 or lower
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
AppContext.SetSwitch("Npgsql.EnableStoredProcedureCompatMode", true);

CreateProcedure(procedureName);

try
Expand All @@ -91,7 +95,7 @@ public void ParameterizedStoredProcedure(string procedureName)
command.Parameters.AddWithValue(p.ParameterName, p.Value);
}

command.ExecuteNonQuery();
ConsoleMFLogger.Info(command.ExecuteNonQuery().ToString());
}
}
finally
Expand All @@ -105,6 +109,10 @@ public void ParameterizedStoredProcedure(string procedureName)
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public async Task ParameterizedStoredProcedureAsync(string procedureName)
{
// Switches required for v6+, no effect on v5 or lower
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
AppContext.SetSwitch("Npgsql.EnableStoredProcedureCompatMode", true);

CreateProcedure(procedureName);

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public PostgresSqlIteratorAsyncTestsBase(TFixture fixture, ITestOutputHelper out
CommonUtils.ModifyOrCreateXmlAttributeInNewRelicConfig(configPath, new[] { "configuration", "transactionTracer" }, "explainThreshold", "1");

var instrumentationFilePath = $@"{fixture.DestinationNewRelicExtensionsDirectoryPath}\NewRelic.Providers.Wrapper.Sql.Instrumentation.xml";
CommonUtils.SetAttributeOnTracerFactoryInNewRelicInstrumentation(instrumentationFilePath, "DataReaderTracer", "enabled", "true");
CommonUtils.SetAttributeOnTracerFactoryInNewRelicInstrumentation(instrumentationFilePath, "DataReaderTracerAsync", "enabled", "true");
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="IBM.Data.DB2, Version=9.7.4.4, Culture=neutral, PublicKeyToken=7c307b91aa13d208">
<Private>False</Private>
<HintPath>C:\Program Files\IBM\SQLLIB\BIN\netf40\IBM.Data.DB2.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM postgres:10
FROM postgres:15

COPY database.sql /docker-entrypoint-initdb.d/database.sql

EXPOSE 5432
EXPOSE 5432