-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add sample app for Postgres client (Npgsql) * disable inlining in profiler * remove manual build dependencies between sample apps the native profiler * replace SQL Server integration with generic ADO.NET integration * use explicit types where possible instead of `object` * add debug logs, but keep commented in repo until we add debug mode * also look for "Host" in the connection string * fix compiler error * remove commented code * uncomment INSERT and DELETE queries * remove target signatures
- Loading branch information
1 parent
8c15495
commit 426bfca
Showing
11 changed files
with
337 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Data.Common; | ||
using System.Linq; | ||
using Datadog.Trace.ClrProfiler; | ||
using Npgsql; | ||
|
||
namespace Samples.Npgsql | ||
{ | ||
public static class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
Console.WriteLine($"Profiler attached: {Instrumentation.ProfilerAttached}"); | ||
Console.WriteLine($"Platform: {(Environment.Is64BitProcess ? "x64" : "x32")}"); | ||
Console.WriteLine(); | ||
|
||
using (var conn = new NpgsqlConnection("Host=localhost;Username=postgres;Password=postgres;Database=postgres")) | ||
{ | ||
conn.Open(); | ||
|
||
// Insert some data | ||
using (var cmd = conn.CreateCommand()) | ||
{ | ||
cmd.CommandText = "INSERT INTO employees (name, birth_date) VALUES (@name, @birth_date);"; | ||
cmd.Parameters.AddWithValue("name", "Jane Smith"); | ||
cmd.Parameters.AddWithValue("@birth_date", new DateTime(1980, 2, 3)); | ||
|
||
int count = cmd.ExecuteNonQuery(); | ||
Console.WriteLine($"{count} rows inserted."); | ||
} | ||
|
||
// Retrieve all rows | ||
using (var cmd = conn.CreateCommand()) | ||
{ | ||
cmd.CommandText = "SELECT * FROM employees sync;"; | ||
int rows = 0; | ||
|
||
using (var reader = cmd.ExecuteReader()) | ||
{ | ||
while (reader.Read()) | ||
{ | ||
var values = new object[10]; | ||
int count = reader.GetValues(values); | ||
Console.WriteLine(string.Join(", ", values.Take(count))); | ||
rows++; | ||
} | ||
} | ||
|
||
Console.WriteLine($"{rows:N0} rows returned from sync query."); | ||
Console.WriteLine(); | ||
|
||
cmd.CommandText = "SELECT * FROM employees async;"; | ||
rows = 0; | ||
|
||
using (var reader = cmd.ExecuteReaderAsync().GetAwaiter().GetResult()) | ||
{ | ||
while (reader.Read()) | ||
{ | ||
var values = new object[10]; | ||
int count = reader.GetValues(values); | ||
Console.WriteLine(string.Join(", ", values.Take(count))); | ||
rows++; | ||
} | ||
} | ||
|
||
Console.WriteLine($"{rows:N0} rows returned from async query."); | ||
} | ||
|
||
// Delete all data | ||
using (var cmd = conn.CreateCommand()) | ||
{ | ||
cmd.CommandText = "DELETE FROM employees;"; | ||
|
||
int count = cmd.ExecuteNonQuery(); | ||
Console.WriteLine($"{count} rows deleted."); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"profiles": { | ||
"Samples.Npgsql": { | ||
"commandName": "Project", | ||
"environmentVariables": { | ||
"COR_ENABLE_PROFILING": "1", | ||
"COR_PROFILER": "{846F5F1C-F9AE-4B07-969E-05C26BC060D8}", | ||
"COR_PROFILER_PATH": "%UserProfile%\\source\\repos\\dd-trace-csharp\\src\\Datadog.Trace.ClrProfiler.Native\\bin\\Debug\\x64\\Datadog.Trace.ClrProfiler.Native.dll", | ||
|
||
"CORECLR_ENABLE_PROFILING": "1", | ||
"CORECLR_PROFILER": "{846F5F1C-F9AE-4B07-969E-05C26BC060D8}", | ||
"CORECLR_PROFILER_PATH": "%UserProfile%\\source\\repos\\dd-trace-csharp\\src\\Datadog.Trace.ClrProfiler.Native\\bin\\Debug\\x64\\Datadog.Trace.ClrProfiler.Native.dll", | ||
|
||
"DD_INTEGRATIONS": "%UserProfile%\\source\\repos\\dd-trace-csharp\\integrations.json" | ||
}, | ||
"nativeDebugging": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFrameworks>net461;netcoreapp2.1</TargetFrameworks> | ||
<Platforms>AnyCPU;x64;x86</Platforms> | ||
<RuntimeIdentifiers>win-x64;win-x86;linux-x64</RuntimeIdentifiers> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT' "> | ||
<TargetFrameworks>netcoreapp2.1</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(TargetFramework)' != 'netcoreapp2.1'"> | ||
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Npgsql" Version="4.0.4" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Datadog.Trace.ClrProfiler.Managed\Datadog.Trace.ClrProfiler.Managed.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.