testing library

Test helpers for the Dartastic OpenTelemetry SDK.

Import this library from test/ only:

import 'package:dartastic_opentelemetry/testing.dart';

It is intentionally not exported from the main package:dartastic_opentelemetry/dartastic_opentelemetry.dart barrel so production bundles don't carry the in-memory exporter classes.

Provides:

The shape mirrors the test harness used in the OTel-Dart reference demo at https://github.com/MindfulSoftwareLLC/dart-otel-reference-demo so wrappers, customer apps, and the reference demo all use the same scaffolding.

Classes

InMemoryLogExporter
Log-record exporter that buffers records in memory for inspection.
InMemoryMetricExporter
Metric exporter that buffers exported metric snapshots in memory.
InMemorySpanExporter
Span exporter that buffers spans in memory for inspection.
OnDemandMetricReader
Metric reader for tests. Never fires on a timer; tests drive collect() explicitly via TestHarness.collectMetrics so assertions don't race against a periodic export.
TestHarness
Bundles the three in-memory exporters and the on-demand metric reader so tests have one handle to clear() between cases.

Functions

maybeInitializeOtelForTest({String serviceName = 'otel-test', String endpoint = 'http://localhost:4317'}) Future<TestHarness>
Initializes the OpenTelemetry SDK once per test process with in-memory exporters for spans / logs / metrics, and returns the same TestHarness on subsequent calls.