Skip to content

Integration MySqlConnector Extension

aryehcitron@gmail.com edited this page May 24, 2026 · 5 revisions

The Kronikol.Extensions.MySqlConnector package adds MySQL operation tracking to your test diagrams via MySqlConnector's built-in DiagnosticSource instrumentation. No production code changes required.

Zero production changes. MySqlConnector emits diagnostic events automatically. This extension subscribes to them globally.


How It Works

MySqlConnector publishes DiagnosticSource events under "MySqlConnector". The MySqlDiagnosticTracker subscribes and correlates command execution events by ExecutionId GUID, classifies operations via UnifiedSqlClassifier, and logs to RequestResponseLogger.


Install

dotnet add package Kronikol.Extensions.MySqlConnector

Setup

Option A — Dependency Injection

services.AddMySqlTestTracking(options =>
{
    options.Verbosity = SqlTrackingVerbosityLevel.Detailed;
});

Option B — Static (No DI)

MySqlTestTracking.EnsureTracking(new MySqlTrackingOptions
{
    Verbosity = SqlTrackingVerbosityLevel.Detailed
});

// In teardown:
MySqlTestTracking.Reset();

Configuration

Property Default Description
ServiceName "MySQL" 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 "MySQL" Controls participant shape/colour
UriScheme "mysql" 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.


Verbosity Levels

Level Arrow label URI
Raw Full SQL text mysql://host/database
Detailed SELECT FROM Users mysql://host/database/Users
Summarised SELECT mysql:///database/Users

Response Payload Capture (v2.37.0+)

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.


Wrapping Alternative (v2.37.0+)

In addition to the zero-change DiagnosticSource approach above, the MySqlConnector 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.

Classes

Class Wraps Purpose
TrackingMySqlConnection MySqlConnection Intercepts command creation and transaction begin
TrackingMySqlCommand MySqlCommand Intercepts ExecuteReader, ExecuteNonQuery, ExecuteScalar (sync + async)
TrackingMySqlTransaction MySqlTransaction Logs BEGIN, COMMIT, ROLLBACK

Extension Method

using MySqlConnector;
using Kronikol.Extensions.MySqlConnector;

var connection = new MySqlConnection(connectionString)
    .WithTestTracking(new MySqlTrackingOptions
    {
        ServiceName = "MySQL",
        Verbosity = SqlTrackingVerbosityLevel.Detailed,
        CurrentTestInfoFetcher = CurrentTestInfo.Fetcher
    });

MySqlConnection.WithTestTracking() returns a TrackingMySqlConnection (which extends DbConnection), so it works transparently with any code that accepts DbConnection — including Dapper, raw ADO.NET, and DI registrations.

DI Registration

builder.ConfigureTestServices(services =>
{
    services.AddScoped<DbConnection>(sp =>
    {
        var inner = new MySqlConnection(connectionString);
        return inner.WithTestTracking(new MySqlTrackingOptions
        {
            ServiceName = "MySQL",
            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 ExecuteReader and ExecuteScalar, but requires the connection to be wrapped. Choose based on your needs — you can use both in the same project for different connections.

Home


Demo


Getting Started

Common Tasks

Integration Guides

Extensions

Configuration

Features

Reference

Clone this wiki locally