-
Notifications
You must be signed in to change notification settings - Fork 1
Integration EventHubs Extension
Track Azure Event Hubs operations in your test diagrams using the Kronikol.Extensions.EventHubs NuGet package. This extension wraps EventHubProducerClient and EventHubConsumerClient to intercept send/receive operations.
Using a shared library or abstraction layer? If your code doesn't use the Event Hubs 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.EventHubs
v2.27.14+ Use the built-in DI extension methods. They automatically resolve
IHttpContextAccessorfrom DI.
// In your test's ConfigureTestServices:
services.AddEventHubsTestTracking(options =>
{
options.ServiceName = "EventHubs";
options.CallerName = "OrdersApi";
options.Verbosity = EventHubsTrackingVerbosity.Detailed;
options.CurrentTestInfoFetcher = CurrentTestInfo.Fetcher;
});This decorates both EventHubProducerClient and EventHubConsumerClient registrations. You can also decorate them individually:
services.AddEventHubsProducerTestTracking(options => { /* ... */ });
services.AddEventHubsConsumerTestTracking(options => { /* ... */ });Uses DecorateAll<EventHubProducerClient> / DecorateAll<EventHubConsumerClient> internally and preserves the original service lifetime. No changes to production code required.
Note:
TrackingEventHubProducerClientnow inherits fromEventHubProducerClient. The base class properties (EventHubName,FullyQualifiedNamespace,IsClosed) are not virtual in the Azure SDK and are accessed vianewshadowing — they work correctly when accessed through the tracking type directly, but may throw if accessed through a polymorphicEventHubProducerClientreference with no underlying connection. The virtual methods (SendAsync,CreateBatchAsync,CloseAsync, etc.) work correctly in all scenarios.
using Azure.Messaging.EventHubs.Producer;
using Kronikol.Extensions.EventHubs;
var options = new EventHubsTrackingOptions
{
ServiceName = "EventHubs",
CallerName = "OrdersApi",
Verbosity = EventHubsTrackingVerbosity.Detailed,
CurrentTestInfoFetcher = () => (TestContext.CurrentTestName, TestContext.CurrentTestId)
};
var innerClient = new EventHubProducerClient(connectionString, eventHubName);
var producer = new TrackingEventHubProducerClient(innerClient, options);
await producer.SendAsync(new[] { new EventData("order-created") });Azure Event Hubs uses AMQP internally and does not expose an HTTP DelegatingHandler pipeline. Like the Service Bus and Pub/Sub extensions, this extension uses the wrapper/decorator pattern — standalone classes that wrap the SDK client and intercept method calls.
The EventHubsTracker (central logging helper) handles all request/response logging with RequestResponseMetaType.Event for async messaging notation in PlantUML diagrams.
| Operation | Enum Value | Source |
|---|---|---|
| Send | EventHubsOperation.Send |
Single event via SendAsync
|
| SendBatch | EventHubsOperation.SendBatch |
Multiple events via SendAsync
|
| CreateBatch | EventHubsOperation.CreateBatch |
CreateBatchAsync |
| ReadEvents | EventHubsOperation.ReadEvents |
ReadEventsAsync |
| ReadEventsFromPartition | EventHubsOperation.ReadEventsFromPartition |
ReadEventsFromPartitionAsync |
| GetPartitionIds | EventHubsOperation.GetPartitionIds |
GetPartitionIdsAsync |
| GetEventHubProperties | EventHubsOperation.GetEventHubProperties |
GetEventHubPropertiesAsync |
| GetPartitionProperties | EventHubsOperation.GetPartitionProperties |
GetPartitionPropertiesAsync |
| StartProcessing | EventHubsOperation.StartProcessing |
StartProcessingAsync |
| StopProcessing | EventHubsOperation.StopProcessing |
StopProcessingAsync |
| ProcessEvent | EventHubsOperation.ProcessEvent |
Event handler callback |
Wraps EventHubProducerClient:
-
SendAsync(IEnumerable<EventData>)— tracks single/batch sends -
SendAsync(IEnumerable<EventData>, SendEventOptions)— tracks with partition key -
SendAsync(EventDataBatch)— tracks batch sends -
CreateBatchAsync()— delegates without tracking -
CloseAsync()— delegates without tracking -
Innerproperty for direct access to the underlying client
Wraps EventHubConsumerClient:
-
ReadEventsAsync()— logs start, yields events, logs completion -
ReadEventsFromPartitionAsync()— logs with partition ID -
GetPartitionIdsAsync()— delegates directly -
CloseAsync()— delegates without tracking -
Innerproperty for direct access
-
Label: Operation name (e.g.
Send) - Content: Omitted
-
URI:
eventhubs:///hub-name
-
Label: Contextual (e.g.
Send → telemetry,Read ← telemetry[2]) - Content: Event body included
-
URI:
eventhubs:///hub-name/partition-idwhen applicable
-
Label: Full details (e.g.
Send hub=telemetry partition=1 count=3) - Content: Full event data
-
URI:
eventhubs:///hub-name/partition-id
new EventHubsTrackingOptions
{
ServiceName = "EventHubs",
CallerName = "OrdersApi",
Verbosity = EventHubsTrackingVerbosity.Detailed,
CurrentTestInfoFetcher = () => (testName, testId),
}| Property | Type | Default | Description |
|---|---|---|---|
ServiceName |
string |
"EventHubs" |
Display name in diagrams for the Event Hubs service |
CallerName |
string |
"Caller" |
Calling service name in diagrams |
Verbosity |
EventHubsTrackingVerbosity |
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+) |
SetupVerbosity |
EventHubsTrackingVerbosity? |
null |
Verbosity override for the Setup phase. See Phase-Aware Tracking |
ActionVerbosity |
EventHubsTrackingVerbosity? |
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
|
PropagateTestIdentity |
bool |
true |
When true, producers inject kronikol-test-name / kronikol-test-id into EventData.Properties and consumers extract them to establish TestIdentityScope. See Background Thread Correlation#Solution 1b: Automatic Message Header Propagation (v2.34.0+)
|
AutoCorrelateOnConsume |
bool |
true |
When true, consumed events auto-populate TestCorrelationStore for parallel-safe background thread correlation |
v2.23.0+ Dual-Resolution:
EventHubsTrackeraccepts an optionalIHttpContextAccessor? httpContextAccessorconstructor parameter for resolving test identity from HTTP request headers when running inside the SUT's request pipeline. v2.26.3+: SetHttpContextAccessoronEventHubsTrackingOptionsinstead — the tracker reads it automatically. See HTTP Tracking Setup#Dual-Resolution Test Identity (v2.23.0+) for details.
EventHubsTracker implements ITrackingComponent and auto-registers with TrackingComponentRegistry. This provides:
-
ComponentName:"EventHubsTracker ({ServiceName})" -
WasInvoked:trueafter first operation -
InvocationCount: Total operations tracked
eventhubs:///telemetry (hub-level operations)
eventhubs:///telemetry/2 (partition-specific operations)
When your application processes Event Hubs events on background threads (e.g. inside an EventProcessorClient), the test framework's TestContext is unavailable. The extension solves this automatically via EventData.Properties propagation.
-
Producer side:
TrackingEventHubProducerClientinjectskronikol-test-nameandkronikol-test-idinto each event'sPropertiesdictionary before sending. -
Consumer side:
TrackingEventHubConsumerClientreads these properties from each received event and callsTestIdentityScope.SetFromMessage(). - All subsequent tracking within the event handler resolves to the originating test.
var options = new EventHubsTrackingOptions
{
PropagateTestIdentity = false,
// ...
};See Background Thread Correlation#Solution 1b: Automatic Message Header Propagation (v2.34.0+) for the full architecture overview.
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