Skip to content

Integration AtlasDataApi Extension

aryehcitron@gmail.com edited this page May 17, 2026 · 6 revisions

The Kronikol.Extensions.AtlasDataApi package adds MongoDB Atlas Data API operation tracking to your test diagrams. It intercepts HTTP requests to the Atlas Data API and classifies them into typed operations like Find ← users with clean atlas:///myDb/users URIs.

Using the MongoDB driver directly? If your code uses the MongoDB .NET driver (MongoClient), use the Integration MongoDB Extension instead — it hooks into the driver's native event monitoring.


How It Works

The Atlas Data API is a REST API that exposes MongoDB operations over HTTP. Requests are POST calls to action endpoints like:

POST https://data.mongodb-api.com/app/{appId}/endpoint/data/v1/action/findOne

The request body contains the dataSource, database, collection, and operation-specific parameters (filter, document, pipeline, etc.).

AtlasDataApiTrackingMessageHandler is a DelegatingHandler that:

  1. Reads the request body to extract metadata (dataSource, database, collection, filter)
  2. Parses the URL path to determine the action (findOne, insertMany, aggregate, etc.)
  3. Logs a classified request entry to RequestResponseLogger
  4. Forwards the request to the real Atlas Data API
  5. Logs the response

Because it logs to the same logger as all other extensions, Atlas Data API operations appear alongside HTTP API calls, MongoDB driver calls, and other tracked dependencies in the same sequence diagram.


Install

dotnet add package Kronikol.Extensions.AtlasDataApi

Verbosity Levels

Level Label shown URI shown Request content Response content
Raw HTTP method (POST) Original Atlas URL Full JSON body Full JSON response
Detailed Find ← users atlas:///myDb/users Full JSON body Full JSON response
Summarised Find atlas:///myDb/users None None

The default is Detailed.


Classified Operations

Category Operations
Read FindOne, Find, Aggregate
Write InsertOne, InsertMany, DeleteOne, DeleteMany
Read-modify-write UpdateOne, UpdateMany, ReplaceOne
Fallback Other (unrecognised actions)

Directional Arrows

In Detailed verbosity, labels include directional arrows indicating data flow:

Direction Arrow Examples
Read Find ← users, Aggregate ← orders
Write InsertOne → users, DeleteMany → temp
Read-modify-write UpdateOne ↔ orders, ReplaceOne ↔ users

Setup

Option A: Manual HttpClient Setup

var options = new AtlasDataApiTrackingMessageHandlerOptions
{
    ServiceName = "Atlas Data API",
    CallerName = "My API",
    Verbosity = AtlasDataApiTrackingVerbosity.Detailed,
    CurrentTestInfoFetcher = CurrentTestInfo.Fetcher,
    HttpContextAccessor = httpContextAccessor // optional: enables dual-resolution from HTTP headers
};

var handler = new AtlasDataApiTrackingMessageHandler(options, new HttpClientHandler());
var client = new HttpClient(handler)
{
    BaseAddress = new Uri("https://data.mongodb-api.com/app/myapp/endpoint/data/v1/")
};

Option B: DI Registration

builder.ConfigureTestServices(services =>
{
    services.AddAtlasDataApiTestTracking(options =>
    {
        options.ServiceName = "Atlas Data API";
        options.Verbosity = AtlasDataApiTrackingVerbosity.Detailed;
    });
});

Option C: Named HttpClient in DI

builder.ConfigureTestServices(services =>
{
    var trackingOptions = new AtlasDataApiTrackingMessageHandlerOptions
    {
        ServiceName = "Atlas Data API",
        CurrentTestInfoFetcher = CurrentTestInfo.Fetcher
    };

    services.AddHttpClient("AtlasDataApi")
        .AddHttpMessageHandler(() => new AtlasDataApiTrackingMessageHandler(trackingOptions));
});

Configuration Reference

AtlasDataApiTrackingMessageHandlerOptions

Property Type Default Description
ServiceName string "AtlasDataApi" The participant name shown in the diagram
CallerName string "Caller" The participant name for the calling service
Verbosity AtlasDataApiTrackingVerbosity Detailed Controls detail level (Raw, Detailed, Summarised)
CurrentTestInfoFetcher Func<(string Name, string Id)>? null Returns current test name and ID
CurrentStepTypeFetcher Func<string?>? null Returns current BDD step type
ExcludedHeaders HashSet<string> Authorization, User-Agent, api-key, apiKey Headers to exclude from diagram notes
ExcludedOperations HashSet<AtlasDataApiOperation> [] Operations to suppress from tracking
SetupVerbosity AtlasDataApiTrackingVerbosity? null Verbosity override for Setup phase
ActionVerbosity AtlasDataApiTrackingVerbosity? null Verbosity override for Action phase
TrackDuringSetup bool true Whether to track during Setup phase
TrackDuringAction bool true Whether to track during Action phase

ITrackingComponent

AtlasDataApiTrackingMessageHandler implements ITrackingComponent and auto-registers with TrackingComponentRegistry:

var handler = new AtlasDataApiTrackingMessageHandler(options);

// ... run test ...

Assert.True(handler.WasInvoked);
Assert.Equal(3, handler.InvocationCount);

Body Metadata Extraction

The handler reads the JSON request body to extract:

Field Used for
dataSource Stored in AtlasDataApiOperationInfo.DataSource
database Used in clean URI: atlas:///database/collection
collection Used in label: Find ← collection
filter Stored in AtlasDataApiOperationInfo.FilterText

Malformed or missing JSON is handled gracefully — the operation is still classified from the URL, metadata is simply null.

Home


Demo


Getting Started

Common Tasks

Integration Guides

Extensions

Configuration

Features

Reference

Clone this wiki locally