Skip to content

Add emulator handler for EmitMetric with MetricStore collection#222

Open
Mielek wants to merge 2 commits into
Azure:mainfrom
Mielek:emulator/emit-metric
Open

Add emulator handler for EmitMetric with MetricStore collection#222
Mielek wants to merge 2 commits into
Azure:mainfrom
Mielek:emulator/emit-metric

Conversation

@Mielek
Copy link
Copy Markdown
Contributor

@Mielek Mielek commented Feb 26, 2026

Summary

Implement EmitMetricHandler that collects emitted metrics into a MetricStore for test assertions.

Changes

  • New: src/Testing/Emulator/Data/EmittedMetric.cs - record for collected metrics
  • New: src/Testing/Emulator/Data/MetricStore.cs - store with ImmutableArray access
  • New: test/Test.Testing/Emulator/Policies/EmitMetricTests.cs - 6 test cases
  • Modified: handler, GatewayContext, TestDocumentExtensions

Usage

var test = new MyDocument().AsTestDocument();
test.RunInbound();
var metrics = test.SetupMetricStore().Metrics;
metrics.Should().HaveCount(1);
metrics[0].Name.Should().Be("my-metric");

- Implement EmitMetricHandler with MetricStore collection
- Add MetricStore and EmittedMetric record for asserting emitted metrics
- Register MetricStore in GatewayContext and TestDocumentExtensions
- Add EmitMetricTests with 6 test cases
- Metrics collected with name, value, namespace, and dimensions
- Default value is 1 when not specified
- Callback overrides bypass metric collection
- Sections: Inbound, Outbound, OnError

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants