Skip to content

Integration SNS Extension

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

Integration: Amazon 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 MessageTracker and TrackingProxy<T>.

Installation

dotnet add package Kronikol.Extensions.SNS

Quick Start

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);

How It Works

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:

  1. Reads and classifies each request using SnsOperationClassifier
  2. Reconstructs the request body so downstream processing is unaffected
  3. Logs request/response pairs via RequestResponseLogger

Protocol Support

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.

Supported Operations

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.

Topic Name Extraction

The classifier extracts topic names from ARN fields in the request body:

  1. TopicArn field: "TopicArn": "arn:aws:sns:us-east-1:123456789012:my-topic"my-topic
  2. TargetArn field: "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.

Verbosity Levels

SnsTrackingVerbosity.Summarised

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

SnsTrackingVerbosity.Detailed

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)

SnsTrackingVerbosity.Raw

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

Configuration Options

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"
    }
}

SnsTrackingMessageHandlerOptions

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: SnsTrackingMessageHandler accepts an optional IHttpContextAccessor? httpContextAccessor constructor parameter for resolving test identity from HTTP request headers when running inside the SUT's request pipeline. v2.26.3+: Set HttpContextAccessor on SnsTrackingMessageHandlerOptions instead — the tracker reads it automatically. See HTTP Tracking Setup#Dual-Resolution Test Identity (v2.23.0+) for details.

ITrackingComponent

SnsTrackingMessageHandler implements ITrackingComponent and auto-registers with TrackingComponentRegistry on construction. This provides:

  • ComponentName: "SnsTrackingMessageHandler ({ServiceName})"
  • WasInvoked: true after first request
  • InvocationCount: Total requests processed

URI Scheme

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.

SNS → SQS Fan-out

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 (ReceiveMessage from my-queue)

Together they show the complete message flow in your test diagrams.

See Also

Home


Demo


Getting Started

Common Tasks

Integration Guides

Extensions

Configuration

Features

Reference

Clone this wiki locally