-
Notifications
You must be signed in to change notification settings - Fork 1
Integration SNS Extension
Track Amazon SNS operations in your test diagrams using the Kronikol.Extensions.SNS NuGet package. This extension intercepts SNS HTTP traffic via the AWS SDK's HttpClientFactory pipeline and logs operations for diagram generation.
Using a shared library or abstraction layer? If your code doesn't use the SNS SDK directly — e.g. it goes through MassTransit, a shared messaging library, or a custom abstraction — see the MassTransit Extension or Tracking Custom Dependencies for alternative approaches including
MessageTrackerandTrackingProxy<T>.
dotnet add package Kronikol.Extensions.SNS
using Amazon.SimpleNotificationService;
using Kronikol.Extensions.SNS;
var config = new AmazonSimpleNotificationServiceConfig
{
RegionEndpoint = Amazon.RegionEndpoint.EUWest1
}
.WithTestTracking(new SnsTrackingMessageHandlerOptions
{
ServiceName = "SNS",
CallerName = "OrdersApi",
Verbosity = SnsTrackingVerbosity.Detailed,
CurrentTestInfoFetcher = () => (TestContext.CurrentTestName, TestContext.CurrentTestId)
});
var client = new AmazonSimpleNotificationServiceClient(config);The extension uses the same DelegatingHandler pattern as the S3, DynamoDB, and SQS extensions. WithTestTracking() injects a SnsTrackingMessageHandler via AmazonSimpleNotificationServiceConfig.HttpClientFactory, intercepting all HTTP requests made by the SNS SDK.
The handler:
- Reads and classifies each request using
SnsOperationClassifier - Reconstructs the request body so downstream processing is unaffected
- Logs request/response pairs via
RequestResponseLogger
SNS supports two protocols:
| Protocol | Detection | Example |
|---|---|---|
| JSON (modern) |
X-Amz-Target: AmazonSimpleNotificationService.{Operation} header |
AmazonSimpleNotificationService.Publish |
| Query (legacy) |
Action={Operation} parameter in query string or form body |
Action=Subscribe |
Both protocols are fully supported by the classifier.
| Operation | Enum Value |
|---|---|
| Publish | SnsOperation.Publish |
| PublishBatch | SnsOperation.PublishBatch |
| Subscribe | SnsOperation.Subscribe |
| Unsubscribe | SnsOperation.Unsubscribe |
| CreateTopic | SnsOperation.CreateTopic |
| DeleteTopic | SnsOperation.DeleteTopic |
| ListTopics | SnsOperation.ListTopics |
| ListSubscriptions | SnsOperation.ListSubscriptions |
| ListSubscriptionsByTopic | SnsOperation.ListSubscriptionsByTopic |
| GetTopicAttributes | SnsOperation.GetTopicAttributes |
| SetTopicAttributes | SnsOperation.SetTopicAttributes |
| ConfirmSubscription | SnsOperation.ConfirmSubscription |
Unrecognised operations are classified as SnsOperation.Other.
The classifier extracts topic names from ARN fields in the request body:
-
TopicArnfield:"TopicArn": "arn:aws:sns:us-east-1:123456789012:my-topic"→my-topic -
TargetArnfield:"TargetArn": "arn:aws:sns:us-east-1:123456789012:endpoint-topic"→endpoint-topic(used for direct publish to platform endpoints)
The topic name is extracted from the last segment of the ARN (after the final :). FIFO topic names (e.g. orders.fifo) are preserved with the .fifo suffix. The full ARN is also available via SnsOperationInfo.TopicArn.
Minimal output for clean diagrams:
-
Method label: Operation name (e.g.
Publish) -
URI:
sns:///my-topic - Content: Omitted (both request and response)
- Headers: Omitted
- Other operations: Skipped entirely
Balanced output for debugging:
-
Method label: Operation name (e.g.
Publish) -
URI:
sns:///my-topic - Content: Included (request body and response body)
- Headers: Included (with default exclusions)
Full HTTP-level output:
-
Method:
POST(actual HTTP method) - URI: Original AWS endpoint URL
- Content: Full request/response bodies
- Headers: All headers (with default exclusions)
- Other operations: Included
new SnsTrackingMessageHandlerOptions
{
// Display name for this SNS instance in diagrams
ServiceName = "SNS",
// Name of the calling service in diagrams
CallerName = "OrdersApi",
// Verbosity level (default: Detailed)
Verbosity = SnsTrackingVerbosity.Detailed,
// Required: provides test context for log correlation
CurrentTestInfoFetcher = () => (testName, testId),
// Headers excluded from logging (defaults below)
ExcludedHeaders = new HashSet<string>
{
"Authorization", "x-amz-date", "x-amz-security-token",
"x-amz-content-sha256", "User-Agent", "amz-sdk-invocation-id",
"amz-sdk-request"
}
}| Property | Type | Default | Description |
|---|---|---|---|
ServiceName |
string |
"SNS" |
Display name in diagrams for the SNS service |
CallerName |
string |
"Caller" |
Calling service name in diagrams |
Verbosity |
SnsTrackingVerbosity |
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 (Given/When/Then) |
HttpContextAccessor |
IHttpContextAccessor? |
null |
Optional — enables dual-resolution of test identity from HTTP headers. Auto-resolved by DI extensions (v2.26.3+). See HTTP Tracking Setup#Dual-Resolution Test Identity (v2.23.0+) |
ExcludedHeaders |
HashSet<string> |
See above | Headers excluded from logging |
SetupVerbosity |
SnsTrackingVerbosity? |
null |
Verbosity override for the Setup phase. See Phase-Aware Tracking |
ActionVerbosity |
SnsTrackingVerbosity? |
null |
Verbosity override for the Action phase. See Phase-Aware Tracking |
TrackDuringSetup |
bool |
true |
When false, tracking is suppressed during Setup. See Phase-Aware Tracking
|
TrackDuringAction |
bool |
true |
When false, tracking is suppressed during Action. See Phase-Aware Tracking
|
v2.23.0+ Dual-Resolution:
SnsTrackingMessageHandleraccepts an optionalIHttpContextAccessor? httpContextAccessorconstructor parameter for resolving test identity from HTTP request headers when running inside the SUT's request pipeline. v2.26.3+: SetHttpContextAccessoronSnsTrackingMessageHandlerOptionsinstead — the tracker reads it automatically. See HTTP Tracking Setup#Dual-Resolution Test Identity (v2.23.0+) for details.
SnsTrackingMessageHandler implements ITrackingComponent and auto-registers with TrackingComponentRegistry on construction. This provides:
-
ComponentName:"SnsTrackingMessageHandler ({ServiceName})" -
WasInvoked:trueafter first request -
InvocationCount: Total requests processed
Classified requests use the sns:/// URI scheme with the topic name in the path:
sns:///my-topic
sns:///orders.fifo
sns:/// (when topic name unavailable, e.g. ListTopics)
The path-based format (three slashes) preserves topic name casing, unlike host-based URIs which lowercase per RFC 3986.
The most common SNS pattern is fan-out to SQS queues. When using both extensions together:
- The SNS extension tracks the publish side (
Publish → my-topic) - The SQS extension tracks the receive side (
ReceiveMessagefrommy-queue)
Together they show the complete message flow in your test diagrams.
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