aws / aws-xray-sdk-dotnet

The official AWS X-Ray SDK for .NET.
Apache License 2.0
110 stars 64 forks source link

Abstract TraceableSqlCommand to support any database backend (mySQL, postgres, Oracle, SqlLite, etc) #82

Open TWI-Ben opened 5 years ago

TWI-Ben commented 5 years ago

Currently AWS X-Ray SDK for .NET only supports SQL Server for tracing SQL commands. The code should support any DbCommand, DbConnection, and DbTransaction regardless of what server it ultimately talks to.

Examples: using (TraceableSqlCommand cmd = new TraceableSqlCommand<MySqlCommand>("SELECT * from test", conn)) { // ... Command code goes here } or using (TraceableSqlCommand cmd = new TraceableSqlCommand(new MySqlCommand("select * from test")) { // ... Command code goes here }

srprash commented 5 years ago

Hello @TWI-Ben , Thanks for opening this issue. We have added the task to our backlog and will prioritize it.

TWI-Ben commented 5 years ago

@srprash Is there any update on this?

srprash commented 5 years ago

Hi @TWI-Ben , it’s still in our backlog and is being worked against other items in our backlog.

Thanks

morquan commented 5 years ago

My company would really benefit from this feature. Can you elaborate on whether this is being worked or not?

As a reference for anyone working this or looking to understand the scope, MiniProfiler essentially handles this through the use of a connection wrapper; see: https://github.com/MiniProfiler/dotnet/blob/master/src/MiniProfiler.Shared/Data/ProfiledDbConnection.cs.

ghost commented 4 years ago

Just started looking into x-ray, and ran into this problem. Since it is already in the backlog I would like to +1 this feature request.

srprash commented 4 years ago

This feature is certainly on our roadmap and we would definitely like to offer this feature as soon as possible. Please stay tuned for updates. We also welcome any PR towards this effort.

matthewdouglas commented 4 years ago

If you're using Entity Framework, you can implement IDbCommandInterceptor and start a segment on the *Executing methods, and end a segment on *Executed. Set the namespace to remote and use AWSXRayRecorder.Instance.AddSqlInformation to annotate with properties like user, database_type, preparation, sanitized_query. The interception context will have a property to tell you if there was an exception that you can log also.

beeradmoore commented 3 months ago

As this doesn't appear to have any more progress I'll throw my 2c of workarounds in. If you use the cs files from sdk/src/Handlers/SqlServer but add the following to the top,

using SqlCommand = MySqlConnector.MySqlCommand;
using SqlConnection = MySqlConnector.MySqlConnection;
using SqlTransaction = MySqlConnector.MySqlTransaction;
using SqlParameter = MySqlConnector.MySqlParameter;
using SqlParameterCollection = MySqlConnector.MySqlParameterCollection;
using SqlDataReader = MySqlConnector.MySqlDataReader;

it will map the SqlServer classes to the relevant MySqlConnector classes. There are a few xml methods you need to also disable as they are not use in MySqlConnector.

It's not great, it may have problems, but at least I have queries logged now.