Developer Guide

Tracing SQL Queries with the X-Ray SDK for .NET

The SDK provides a wrapper class for System.Data.SqlClient.SqlCommand named TraceableSqlCommand that you can use in place of SqlCommand.

Example Controller.cs - SQL Client Instrumentation

Initialize an SQL command with the X-Ray SDK for .NET's TraceableSqlCommand class.

using Amazon; using Amazon.Util; using Amazon.XRay.Recorder.Core; using Amazon.XRay.Recorder.Handlers.SqlServer; private void QuerySql(int id) { var connectionString = ConfigurationManager.AppSettings["RDS_CONNECTION_STRING"]; using (var sqlConnection = new SqlConnection(connectionString)) using (var sqlCommand = new TraceableSqlCommand("SELECT " + id, sqlConnection)) { sqlCommand.Connection.Open(); sqlCommand.ExecuteNonQuery(); } }