InMemorySpanExporter class

Span exporter that buffers spans in memory for inspection.

Tests typically:

setUpAll(() async {
  harness = await maybeInitializeOtelForTest();
  spans = harness.spans;
});
setUp(() => harness.clear());

test('my_op emits a span', () {
  doMyOp();
  expect(spans.findSpanByName('my_op'), isNotNull);
});

Use findSpanByName / findSpansByName / findSpansStartingWith instead of indexing into spans directly — they make test failures read more clearly.

Implemented types

Constructors

InMemorySpanExporter()
Creates an exporter.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
spanNames List<String>
All exported span names, in export order. Handy in expect assertions when you want to check the trace shape.
no setter
spans List<Span>
All spans exported since the last clear.
no setter

Methods

clear() → void
Clears the recorded spans. Call between tests.
export(List<Span> spans) Future<void>
Exports a batch of finished Spans.
override
findSpanByName(String name) Span?
Returns the most recently exported span with the given name, or null if none match. Most-recent makes per-test reads stable when a span name happens to be reused across tests.
findSpansByName(String name) List<Span>
Returns every exported span whose name equals name.
findSpansStartingWith(String prefix) List<Span>
Returns every exported span whose name starts with prefix. Useful for category-level assertions (e.g. findSpansStartingWith('http ')).
forceFlush() Future<void>
Flushes any pending data.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
shutdown() Future<void>
Shuts down the exporter.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited