-
Notifications
You must be signed in to change notification settings - Fork 1
Integration SqlClient Extension
The Kronikol.Extensions.SqlClient package adds SQL Server operation tracking to your test diagrams via Microsoft.Data.SqlClient's built-in DiagnosticSource instrumentation. No production code changes required.
Zero production changes. SqlClient emits diagnostic events automatically. This extension subscribes to them globally, so every
SqlConnectionin the process is tracked.
Microsoft.Data.SqlClient publishes DiagnosticSource events under "SqlClientDiagnosticListener". The SqlClientDiagnosticTracker subscribes and handles both modern (WriteCommandBefore/WriteCommandAfter) and legacy (ExecuteReader.Start/ExecuteReader.Stop) event naming patterns. Commands are correlated via OperationId GUID, classified by UnifiedSqlClassifier, and logged to RequestResponseLogger.
dotnet add package Kronikol.Extensions.SqlClientservices.AddSqlServerTestTracking(options =>
{
options.Verbosity = SqlTrackingVerbosityLevel.Detailed;
});SqlClientTestTracking.EnsureTracking(new SqlClientTrackingOptions
{
Verbosity = SqlTrackingVerbosityLevel.Detailed
});
// In teardown:
SqlClientTestTracking.Reset();| Property | Default | Description |
|---|---|---|
ServiceName |
"SQL Server" |
Participant name in diagrams |
CallerName |
"Caller" |
The caller participant name |
Verbosity |
Detailed |
Raw, Detailed, or Summarised
|
CurrentTestInfoFetcher |
null |
Returns the current test's name and ID. Required for wrapping approach |
HttpContextAccessor |
null |
Optional — enables dual-resolution of test identity from HTTP headers |
LogSqlText |
true |
Include full SQL text in Detailed mode |
LogParameters |
false |
Include parameter values |
DependencyCategory |
"SqlServer" |
Controls participant shape/colour |
UriScheme |
"sqlserver" |
URI scheme in diagram URIs |
ExcludedOperations |
[] |
Operations to exclude from tracking |
SetupVerbosity |
null |
Verbosity override for the Setup phase. See Phase-Aware Tracking |
ActionVerbosity |
null |
Verbosity override for the Action phase. See Phase-Aware Tracking |
TrackDuringSetup |
true |
When false, tracking is suppressed during Setup |
TrackDuringAction |
true |
When false, tracking is suppressed during Action |
LogResponseContent |
true |
Include response data in diagram arrows at all verbosity levels (v2.37.0+) |
MaxResponseRows |
10 |
Maximum rows to capture in response content |
MaxValueDisplayLength |
500 |
Truncate individual cell values beyond this length |
ResponseDetail |
RowCountAndColumns |
RowCountOnly, RowCountAndColumns, or FullRows
|
All options inherit from SqlTrackingOptionsBase.
| Level | Arrow label | URI |
|---|---|---|
| Raw | Full SQL text | sqlserver://host/database |
| Detailed | SELECT FROM Users |
sqlserver://host/database/Users |
| Summarised | SELECT |
sqlserver:///database/Users |
Response arrows in diagrams now show actual data instead of being empty. The ResponseDetail option controls the level of detail:
ResponseDetail |
Example output |
|---|---|
RowCountOnly |
3 rows |
RowCountAndColumns (default)
|
3 rows [Name, Preference, CreatedAt] |
FullRows |
JSON row preview (up to MaxResponseRows) |
Set LogResponseContent = false to restore previous empty-arrow behaviour.
In addition to the zero-change DiagnosticSource approach above, the SqlClient extension also provides a connection-wrapping approach. This is useful when DiagnosticSource instrumentation is unavailable, disabled, or when you need response payload capture from ExecuteReader/ExecuteScalar.
| Class | Wraps | Purpose |
|---|---|---|
TrackingSqlConnection |
SqlConnection |
Intercepts command creation and transaction begin |
TrackingSqlCommand |
SqlCommand |
Intercepts ExecuteReader, ExecuteNonQuery, ExecuteScalar (sync + async) |
TrackingSqlTransaction |
SqlTransaction |
Logs BEGIN, COMMIT, ROLLBACK
|
using Microsoft.Data.SqlClient;
using Kronikol.Extensions.SqlClient;
var connection = new SqlConnection(connectionString)
.WithTestTracking(new SqlClientTrackingOptions
{
ServiceName = "SQL Server",
Verbosity = SqlTrackingVerbosityLevel.Detailed,
CurrentTestInfoFetcher = CurrentTestInfo.Fetcher
});SqlConnection.WithTestTracking() returns a TrackingSqlConnection (which extends DbConnection), so it works transparently with any code that accepts DbConnection — including Dapper, raw ADO.NET, and DI registrations.
builder.ConfigureTestServices(services =>
{
services.AddScoped<DbConnection>(sp =>
{
var inner = new SqlConnection(connectionString);
return inner.WithTestTracking(new SqlClientTrackingOptions
{
ServiceName = "SQL Server",
Verbosity = SqlTrackingVerbosityLevel.Detailed,
CurrentTestInfoFetcher = CurrentTestInfo.Fetcher
});
});
});DiagnosticSource vs Wrapping: The DiagnosticSource approach (Option A/B above) requires zero production code changes but cannot capture response payloads. The wrapping approach captures response data from
ExecuteReaderandExecuteScalar, but requires the connection to be wrapped. Choose based on your needs — you can use both in the same project for different connections.
Getting Started
Common Tasks
Integration Guides
- Integration xUnit3
- Integration xUnit2
- Integration NUnit
- Integration MSTest
- Integration TUnit
- Integration BDDfy xUnit3
- Integration LightBDD xUnit2
- Integration LightBDD xUnit3
- Integration LightBDD TUnit
- Integration ReqNRoll xUnit2
- Integration ReqNRoll xUnit3
- Integration ReqNRoll TUnit
Extensions
- Integration AtlasDataApi Extension
- Integration BigQuery Extension
- Integration Bigtable Extension
- Integration BlobStorage Extension
- Integration CloudStorage Extension
- Integration CosmosDB Extension
- Integration Dapper Extension
- Integration DynamoDB Extension
- Integration EF Core Relational Extension
- Integration Elasticsearch Extension
- Integration EventBridge Extension
- Integration EventHubs Extension
- Integration Grpc Extension
- Integration Kafka Extension
- Integration MassTransit Extension
- Integration MongoDB Extension
- Integration MySqlConnector Extension
- Integration Npgsql Extension
- Integration Oracle Extension
- Integration PubSub Extension
- Integration Redis Extension
- Integration S3 Extension
- Integration ServiceBus Extension
- Integration SNS Extension
- Integration Spanner Extension
- Integration SqlClient Extension
- Integration Sqlite Extension
- Integration SQS Extension
- Integration StorageQueues Extension
- Integration OpenTelemetry Extension
- Integration DispatchProxy Extension
- Integration MediatR Extension
- Integration PlantUML IKVM
Configuration
- Tracking Dependencies
- Tracking Custom Dependencies
- HTTP Tracking Setup
- Report Configuration
- Diagram Customisation
- Phase-Aware Tracking
- Content Formatting
- PlantUML Server Configuration
Features
- Generated Reports
- Search Syntax
- Component Diagrams
- PlantUML Browser Rendering
- Inline SVG Rendering
- Internal Flow Tracking
- Tags and Attributes
- Excluding Requests
- Excluded Headers
- Multi-Host Test Architectures
- Event-Driven Architecture Testing
- Service Bus Tracking Patterns
- Background Thread Correlation
- Parallel-Safe Background Correlation
- Event & Message Tracking
- Assertion Tracking
- Step Tracking
- Tabular Attributes
- Large Response and Diagram Handling
- Diagnostics and Debugging
- CI Summary Integration
- CI Artifact Upload
Reference