forked from DataDog/dd-trace-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert AdoNet to MethodBuilder (DataDog#489)
* Convert AdoNet to MethodBuilder, more sample async calls * MySql sample
- Loading branch information
1 parent
98efd8f
commit c5894f5
Showing
10 changed files
with
249 additions
and
42 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,83 @@ | ||
using System; | ||
using Datadog.Trace.ClrProfiler; | ||
using MySql.Data.MySqlClient; | ||
|
||
namespace Samples.MySql | ||
{ | ||
class Program | ||
{ | ||
private static string Host() | ||
{ | ||
return Environment.GetEnvironmentVariable("MYSQL_HOST") ?? "localhost"; | ||
} | ||
|
||
private static string ConnectionString(string database) | ||
{ | ||
return $"server={Host()};user=mysqldb;password=mysqldb;port=3306;database={database}"; | ||
} | ||
|
||
private static void Main(string[] args) | ||
{ | ||
Console.WriteLine($"Profiler attached: {Instrumentation.ProfilerAttached}"); | ||
Console.WriteLine($"Platform: {(Environment.Is64BitProcess ? "x64" : "x32")}"); | ||
Console.WriteLine(); | ||
|
||
Console.WriteLine("Opening the connection."); | ||
|
||
string connStr = ConnectionString("world"); | ||
var conn = new MySqlConnection(connStr); | ||
conn.Open(); | ||
|
||
Console.WriteLine("Creating the table for the continents."); | ||
|
||
// Create table | ||
var tableCommand = | ||
new MySqlCommand( | ||
"DROP TABLE IF EXISTS `continent`; CREATE TABLE continent (continent_id INT AUTO_INCREMENT, name VARCHAR(255) NOT NULL, PRIMARY KEY(continent_id));", | ||
conn); | ||
tableCommand.ExecuteNonQuery(); | ||
|
||
Console.WriteLine("Creating the continents."); | ||
|
||
// Create continents | ||
MySqlCommand createContinent; | ||
createContinent = new MySqlCommand("INSERT INTO continent (name) VALUES ('Africa');", conn); | ||
createContinent.ExecuteNonQuery(); | ||
createContinent = new MySqlCommand("INSERT INTO continent (name) VALUES ('Antarctica');", conn); | ||
createContinent.ExecuteNonQuery(); | ||
createContinent = new MySqlCommand("INSERT INTO continent (name) VALUES ('Asia');", conn); | ||
createContinent.ExecuteNonQuery(); | ||
createContinent = new MySqlCommand("INSERT INTO continent (name) VALUES ('Australia');", conn); | ||
createContinent.ExecuteNonQuery(); | ||
createContinent = new MySqlCommand("INSERT INTO continent (name) VALUES ('Europe');", conn); | ||
createContinent.ExecuteNonQuery(); | ||
createContinent = new MySqlCommand("INSERT INTO continent (name) VALUES ('North America');", conn); | ||
createContinent.ExecuteNonQuery(); | ||
createContinent = new MySqlCommand("INSERT INTO continent (name) VALUES ('South America');", conn); | ||
createContinent.ExecuteNonQuery(); | ||
|
||
try | ||
{ | ||
Console.WriteLine("Beginning to read the continents."); | ||
string sql = "SELECT continent_id, name FROM continent"; | ||
var readContinents = new MySqlCommand(sql, conn); | ||
using (var rdr = readContinents.ExecuteReader()) | ||
{ | ||
while (rdr.Read()) | ||
{ | ||
Console.WriteLine(rdr[0] + " -- " + rdr[1]); | ||
} | ||
rdr.Close(); | ||
} | ||
Console.WriteLine("Done reading the continents."); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.ToString()); | ||
} | ||
|
||
conn.Close(); | ||
Console.WriteLine("Done setting up, inserting, and reading from MySQL."); | ||
} | ||
} | ||
} |
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.MySql": { | ||
"commandName": "Project", | ||
"environmentVariables": { | ||
"COR_ENABLE_PROFILING": "1", | ||
"COR_PROFILER": "{846F5F1C-F9AE-4B07-969E-05C26BC060D8}", | ||
"COR_PROFILER_PATH": "$(ProjectDir)$(OutputPath)profiler-lib\\Datadog.Trace.ClrProfiler.Native.dll", | ||
|
||
"CORECLR_ENABLE_PROFILING": "1", | ||
"CORECLR_PROFILER": "{846F5F1C-F9AE-4B07-969E-05C26BC060D8}", | ||
"CORECLR_PROFILER_PATH": "$(ProjectDir)$(OutputPath)profiler-lib\\Datadog.Trace.ClrProfiler.Native.dll", | ||
|
||
"DD_INTEGRATIONS": "$(ProjectDir)$(OutputPath)profiler-lib\\integrations.json" | ||
}, | ||
"nativeDebugging": true | ||
} | ||
} | ||
} |
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,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<ApiVersion Condition="'$(ApiVersion)' == ''">8.0.17</ApiVersion> | ||
<!-- Required to build multiple projects with the same Configuration|Platform --> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="MySql.Data" Version="$(ApiVersion)" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using System; | ||
using System.Data.Common; | ||
using System.Linq; | ||
using Datadog.Trace.ClrProfiler; | ||
using Npgsql; | ||
|
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
Oops, something went wrong.