AWS X-Ray tracing

Posts   
 
    
florisotto
User
Posts: 4
Joined: 04-Aug-2021
# Posted on: 13-Oct-2021 15:18:52   

Hi Otis,

We're currently implementing an AWS service called x-ray which helps to trace requests between microservices. There's an option to also trace your SQL queries within .net core. You would need to replace the SqlCommand with an TraceableSqlCommand (from AWS) in order to trace your queries. Is there a possibility to use this in combination with llblgen? We're currently using llblgen as our orm mapper for our mssql databases and would like to keep it that way but would also like to use x-ray to trace requests.

https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-dotnet-sqlqueries.html

Thanks in advance, Floris

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 14-Oct-2021 09:16:34   

Yes this is possible.

First you have to create a subclass of the SqlServerSpecificCreator, that's part of the SqlServer DQE. In that subtype you override public virtual DbCommand CreateCommand(DbConnection connectionToUse). First you call the base method to create the SqlCommand, then in your override you create the TraceableSqlCommand by passing in the created SqlCommand.

To use your custom SqlServerSpecificCreator, you have to create a subtype of the DynamicQueryEngine of the SqlServer DQE, and override the protected override IDbSpecificCreator CreateDbSpecificCreator() method. In your override you create an instance of your custom SqlServerSpecificCreator derived class.

Last step is to make sure the system uses your custom DynamicQueryEngine type. If you're using Adapter, create a subtype of the generated DataAccessAdapter class and override the method protected internal abstract DynamicQueryEngineBase CreateDynamicQueryEngine(). In your override create a new instance of the custom DynamicQueryEngine subclass you made.

If you're using SelfServicing, it's trickier, you need to adjust the template for the DAO classes (as they create the DynamicQueryEngine in their constructor).

An alternative route could be to wrap the DbProviderFactory class. This doesn't require you to derive any subtypes of our framework, you have to create a new DbProviderFactory deriving class which basically wraps the factory passed in (in your case the SqlClientFactory) and calls the wrapped factory's methods for e.g. CreateConnection and the like. For CreateCommand you return an instance of the TraceableCommand. I'd also wrap SqlConnection and return a TraceableCommand when its CreateCommand method is called. We use this method in our orm profiler interceptor.

Frans Bouma | Lead developer LLBLGen Pro
florisotto
User
Posts: 4
Joined: 04-Aug-2021
# Posted on: 14-Oct-2021 12:31:26   

Thanks for your help, Otis. Works like a charm!