ArtifactPublisher class

Global singleton manager for artifact hooks.

Responsible for:

  • Registering and unregistering hooks
  • Publishing artifacts to all applicable hooks
  • Running hooks in priority order (low to high)
  • Catching and logging hook errors to prevent cascading failures

Usage

// Register a hook at app startup
ArtifactPublisher.instance.register(MinIOArtifactHook(
  client: MinioClient(
    endpoint: 'http://localhost:9000',
    accessKey: 'minioadmin',
    secretKey: 'minioadmin',
  ),
  bucket: 'artifacts',
));

// Publish an artifact (fire-and-forget)
ArtifactPublisher.instance.publishFireAndForget(
  data: rawHtml,
  id: entityId,
  contentType: 'text/html; charset=utf-8',
  reason: 'failure',
  source: 'NetworkClient',
  label: 'RequestFailed',
  metadata: {'entityId': 'abc-123', 'url': 'https://example.com'},
);

// Publish an image (awaited)
await ArtifactPublisher.instance.publish(
  data: imageBytes,
  id: scanId,
  contentType: 'image/jpeg',
  reason: 'scan',
  source: 'ImageCapture',
  label: 'product_scan',
  metadata: {'barcode': '1234567890'},
);

Constructors

ArtifactPublisher()
factory

Properties

hashCode → int
The hash code for this object.
no setterinherited
hooks → List<ArtifactHook>
The registered hooks (read-only, sorted by priority).
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
spanContextProvider ↔ ({String? spanId, String? traceId}) Function()?
Optional provider for the active OTel span context.
getter/setter pair

Methods

clear() → void
Unregister all hooks.
dispose() → void
Dispose the publisher and clear all hooks.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
publish(dynamic data, {required String id, required String contentType, required String reason, String? source, String? label, Map<String, dynamic> metadata = const {}, StackTrace? stackTrace, List<String> pathSegments = const [], String? traceId, String? spanId}) → Future<void>
Publish an artifact to all applicable hooks (awaited).
publishFireAndForget(dynamic data, {required String id, required String contentType, required String reason, String? source, String? label, Map<String, dynamic> metadata = const {}, StackTrace? stackTrace, List<String> pathSegments = const [], String? traceId, String? spanId}) → void
Fire-and-forget version of publish.
register(ArtifactHook hook) → void
Register a new hook.
toString() → String
A string representation of this object.
inherited
unregister(String id) → void
Unregister a hook by id.

Operators

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

Static Properties

instance → ArtifactPublisher
Convenience getter for the singleton instance.
no setter