-
Notifications
You must be signed in to change notification settings - Fork 1
Integration Spanner Extension
Track Google Cloud Spanner operations in your test diagrams using the TestTrackingDiagrams.Extensions.Spanner NuGet package. This extension supports two interception strategies: ADO.NET wrapping (for users of SpannerConnection) and gRPC client wrapping (for users of SpannerClient).
Using a shared library or abstraction layer? If your code doesn't use the Spanner SDK directly — e.g. it goes through a shared data-access library, wrapper, or custom abstraction — this extension won't be able to intercept the underlying calls. See Tracking Custom Dependencies for alternative approaches including
RequestResponseLogger.LogPair(),TrackingProxy<T>, andMessageTracker.
dotnet add package TestTrackingDiagrams.Extensions.Spanner
Google Cloud Spanner has two .NET client libraries:
-
ADO.NET (
Google.Cloud.Spanner.Data) —SpannerConnection,SpannerCommand, standardDbCommand.ExecuteReader()etc. -
Low-level gRPC (
Google.Cloud.Spanner.V1) —SpannerClient, direct RPC calls likeExecuteSql,Read,Commit.
This extension provides wrappers for both:
-
TrackingSpannerConnectionwrapsDbConnectionand intercepts all SQL commands -
SpannerTrackerprovides directLogRequest/LogResponsepairing for gRPC-style usage
Both use SpannerOperationClassifier to classify operations and SpannerTracker to log to RequestResponseLogger with RequestResponseMetaType.Event and DependencyCategory: "Database".
| Operation | SQL Pattern | gRPC Method |
|---|---|---|
Query |
SELECT ... |
ExecuteSql, ExecuteStreamingSql
|
Read |
— | Read |
StreamingRead |
— | StreamingRead |
Insert |
INSERT INTO ... |
— |
Update |
UPDATE ... |
— |
Delete |
DELETE FROM ... |
— |
InsertOrUpdate |
— | Mutation-based |
Replace |
— | Mutation-based |
Commit |
— | Commit |
Rollback |
— | Rollback |
BeginTransaction |
— | BeginTransaction |
BatchDml |
— | ExecuteBatchDml |
PartitionQuery |
— | PartitionQuery |
PartitionRead |
— | PartitionRead |
Ddl |
CREATE TABLE, ALTER TABLE, DROP TABLE
|
— |
CreateSession |
— |
CreateSession, BatchCreateSessions
|
DeleteSession |
— | DeleteSession |
-
Label: Short keyword (e.g.
SELECT,INSERT,Commit) - Content: Omitted
-
URI:
spanner:///TableNameorspanner:///unknown
-
Label: Operation with table name (e.g.
SELECT FROM Users,INSERT INTO Orders) -
Content: SQL text (if
LogSqlText = true) -
URI:
spanner:///TableName
- Label: Full SQL text
-
Content: SQL text + parameters (if
LogParameters = true) -
URI:
spanner:///databaseId/TableName
Wrap your SpannerConnection (or any DbConnection) with WithTestTracking():
using TestTrackingDiagrams.Extensions.Spanner;
var connection = new SpannerConnection(connectionString);
var trackingConnection = connection.WithTestTracking(new SpannerTrackingOptions
{
ServiceName = "Spanner",
CallingServiceName = "OrdersApi",
CurrentTestInfoFetcher = () => (TestContext.Current!.Test.TestDisplayName, TestContext.Current.Test.UniqueID)
});
// Use trackingConnection in place of connection
using var cmd = trackingConnection.CreateCommand();
cmd.CommandText = "SELECT * FROM Users WHERE Id = @id";
// ...The tracking connection creates TrackingSpannerCommand wrappers that intercept ExecuteReader, ExecuteNonQuery, and ExecuteScalar (both sync and async).
For low-level SpannerClient usage or manual logging:
using TestTrackingDiagrams.Extensions.Spanner;
var tracker = new SpannerTracker(new SpannerTrackingOptions
{
ServiceName = "Spanner",
CallingServiceName = "OrdersApi",
CurrentTestInfoFetcher = () => (testName, testId)
});
// Classify and log
var op = SpannerOperationClassifier.ClassifyGrpc("ExecuteSql", "Users", databaseId);
var (reqId, traceId) = tracker.LogRequest(op, "SELECT * FROM Users");
// ... execute operation ...
tracker.LogResponse(op, reqId, traceId, "5 rows returned");services.AddSpannerTestTracking(options =>
{
options.ServiceName = "Spanner";
options.CallingServiceName = "OrdersApi";
options.CurrentTestInfoFetcher = () => (TestContext.Current!.Test.TestDisplayName, TestContext.Current.Test.UniqueID);
});Then inject SpannerTracker where needed.
| Property | Type | Default | Description |
|---|---|---|---|
ServiceName |
string |
"Spanner" |
Display name in diagrams for the Spanner service |
CallingServiceName |
string |
"Caller" |
Calling service name in diagrams |
Verbosity |
SpannerTrackingVerbosity |
Detailed |
Verbosity level (Raw, Detailed, Summarised) |
CurrentTestInfoFetcher |
Func<(string Name, string Id)>? |
null |
Required: provides test context for log correlation |
CurrentStepTypeFetcher |
Func<string?>? |
null |
Optional — returns the current BDD step type |
LogSqlText |
bool |
true |
Include SQL text in logged content (Detailed mode) |
LogParameters |
bool |
false |
Include command parameters in logged content (Raw mode) |
ExcludedOperations |
HashSet<SpannerOperation> |
[] |
Operations to skip (e.g. CreateSession, DeleteSession) |
SetupVerbosity |
SpannerTrackingVerbosity? |
null |
Verbosity override for the Setup phase. See Phase-Aware Tracking |
ActionVerbosity |
SpannerTrackingVerbosity? |
null |
Verbosity override for the Action phase. See Phase-Aware Tracking |
TrackDuringSetup |
bool |
true |
When false, tracking is suppressed during Setup |
TrackDuringAction |
bool |
true |
When false, tracking is suppressed during Action |
If you already use the Integration Dapper Extension, it can also intercept SpannerConnection queries (since SpannerConnection is a DbConnection). The key difference:
| Spanner Extension | Dapper Extension | |
|---|---|---|
| Classification | Spanner-specific (Read, StreamingRead, Mutations, DDL, Partitioned ops) | Generic SQL (SELECT, INSERT, UPDATE, DELETE) |
| gRPC support | Yes (SpannerClient wrapping + classifier) | No |
| Dependency category | Database |
SQL |
| URI scheme | spanner:/// |
sql:/// |
Use the Spanner extension when you want Spanner-specific operation visibility. Use the Dapper extension if you only need basic SQL classification.
SpannerTracker and TrackingSpannerConnection both implement ITrackingComponent and auto-register:
-
ComponentName:"SpannerTracker ({ServiceName})" -
WasInvoked:trueafter first operation -
InvocationCount: Total operations logged
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 ClickHouse 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
- Merging Parallel Reports
Reference