-
Notifications
You must be signed in to change notification settings - Fork 1
Integration Grpc Extension
Track gRPC client calls in your test diagrams using the TestTrackingDiagrams.Extensions.Grpc NuGet package. This extension intercepts all gRPC call types (unary, server-streaming, client-streaming, duplex-streaming) via the standard Grpc.Core.Interceptors.Interceptor API.
dotnet add package TestTrackingDiagrams.Extensions.Grpc
using Grpc.Net.Client;
using TestTrackingDiagrams.Extensions.Grpc;
var channel = GrpcChannel.ForAddress("https://localhost:5001");
var invoker = channel.WithTestTracking(new GrpcTrackingOptions
{
ServiceName = "GreeterService",
CallingServiceName = "MyApi",
Verbosity = GrpcTrackingVerbosity.Detailed,
CurrentTestInfoFetcher = () => (TestContext.CurrentTestName, TestContext.CurrentTestId)
});
var client = new Greeter.GreeterClient(invoker);Or using the interceptor directly:
var invoker = channel.Intercept(new GrpcTrackingInterceptor(options));
var client = new Greeter.GreeterClient(invoker);GrpcTrackingInterceptor extends Grpc.Core.Interceptors.Interceptor, overriding all five call types:
| Call Type | Override | Tracking |
|---|---|---|
| Async Unary | AsyncUnaryCall |
Full request + response |
| Blocking Unary | BlockingUnaryCall |
Full request + response |
| Server Streaming | AsyncServerStreamingCall |
Request + call initiation |
| Client Streaming | AsyncClientStreamingCall |
Call initiation + response |
| Duplex Streaming | AsyncDuplexStreamingCall |
Call initiation + response |
Streaming calls are tracked at the initiation level (not per-message) to keep diagrams clean.
| Method Type | Enum Value |
|---|---|
| Unary | GrpcOperation.UnaryCall |
| Server Streaming | GrpcOperation.ServerStreamingCall |
| Client Streaming | GrpcOperation.ClientStreamingCall |
| Duplex Streaming | GrpcOperation.DuplexStreamingCall |
Request and response messages are serialized for diagram content:
-
Protobuf
IMessage: UsesGoogle.Protobuf.JsonFormatter.Default.Format()for JSON output -
Other types: Falls back to
.ToString() - Summarised verbosity: Content omitted entirely
gRPC status codes are mapped to HTTP status codes for consistent diagram logging:
| gRPC Status | HTTP Status |
|---|---|
| OK | 200 OK |
| NotFound | 404 Not Found |
| PermissionDenied | 403 Forbidden |
| Unauthenticated | 401 Unauthorized |
| InvalidArgument | 400 Bad Request |
| DeadlineExceeded | 408 Request Timeout |
| AlreadyExists | 409 Conflict |
| ResourceExhausted | 429 Too Many Requests |
| Unavailable | 503 Service Unavailable |
| Unimplemented | 501 Not Implemented |
| Cancelled | 408 Request Timeout |
| Other | 500 Internal Server Error |
Minimal output:
-
Label: Method name only (e.g.
SayHello) -
URI:
grpc:///ServiceName/ - Content: Omitted
- Headers: Omitted
Balanced output:
-
Label: Method name with streaming annotation (e.g.
SayHello,StreamMessages (server-stream)) -
URI:
grpc:///ServiceName/MethodName - Content: Serialized protobuf messages
- Headers: Omitted
Full output:
-
Label:
/package.Service/Method [UnaryCall] -
URI:
grpc:///package.Service/Method - Content: Serialized protobuf messages
- Headers: Included (non-binary metadata entries)
new GrpcTrackingOptions
{
// Display name in diagrams (default: "GrpcService")
ServiceName = "GreeterService",
// Calling service name in diagrams (default: "Caller")
CallingServiceName = "MyApi",
// Verbosity level (default: Detailed)
Verbosity = GrpcTrackingVerbosity.Detailed,
// Required: provides test context
CurrentTestInfoFetcher = () => (testName, testId),
// Use proto service name instead of ServiceName (default: false)
UseProtoServiceNameInDiagram = false
}When true, the proto service name from the method definition (e.g. greet.Greeter) is used as the service name in diagrams instead of the configured ServiceName. Useful when tracking multiple gRPC services through a single interceptor.
GrpcTrackingInterceptor implements ITrackingComponent and auto-registers with TrackingComponentRegistry:
-
ComponentName:"GrpcTrackingInterceptor ({ServiceName})" -
WasInvoked:trueafter first call -
InvocationCount: Total calls processed (all call types)
| Verbosity | Format | Example |
|---|---|---|
| Summarised | grpc:///ServiceName/ |
grpc:///greet.Greeter/ |
| Detailed | grpc:///ServiceName/MethodName |
grpc:///greet.Greeter/SayHello |
| Raw | grpc:///FullMethodPath |
grpc:////greet.Greeter/SayHello |
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