pub struct DiagnosticsEmitter { /* private fields */ }Expand description
A subsystem-scoped control surface for exposing diagnostics.
A DiagnosticsEmitter is created for a single subsystem, identified by a SubsystemIdentifier, and is attached
to a specific dataspace. It hides the boilerplate of interacting with the dataspace directly, while still using it
under the hood so that other subsystems can subscribe to what is exposed in a decoupled, eventually consistent way.
It exposes two capabilities:
- Collectors: named, on-demand producers of artifact bytes (see
register_collector), stored as persistent dataspace assertions and automatically withdrawn when the owning process exits. - Events: abstract, point-in-time
DiagnosticEvents (seeemit), delivered as transient dataspace messages to any subscribers present at the time of emission.
§Example
use saluki_core::diagnostic::{DiagnosticDetails, DiagnosticEvent, DiagnosticsEmitter};
use saluki_core::runtime::state::DataspaceRegistry;
use saluki_core::support::SubsystemIdentifier;
let dataspace = DataspaceRegistry::new();
let emitter = DiagnosticsEmitter::from_dataspace(
SubsystemIdentifier::from_segments(["my-subsystem"]),
dataspace,
);
// Expose an artifact that is produced on demand:
emitter.register_collector("state.json", || b"{}");
// Emit a point-in-time event:
emitter.emit(DiagnosticEvent::new("credentials rejected", DiagnosticDetails::InvalidApiKey));Implementations§
Source§impl DiagnosticsEmitter
impl DiagnosticsEmitter
Sourcepub fn from_current(
id: SubsystemIdentifier,
) -> Result<Self, DiagnosticsEmitterError>
pub fn from_current( id: SubsystemIdentifier, ) -> Result<Self, DiagnosticsEmitterError>
Creates an emitter for the given subsystem, attaching to the current dataspace.
§Errors
If no dataspace is available, an error is returned.
Sourcepub fn from_dataspace(
id: SubsystemIdentifier,
dataspace: DataspaceRegistry,
) -> Self
pub fn from_dataspace( id: SubsystemIdentifier, dataspace: DataspaceRegistry, ) -> Self
Creates an emitter for the given subsystem from an already-held dataspace handle.
Sourcepub fn register_collector<F, T>(
&self,
artifact_name: impl Into<String>,
collect_fn: F,
)
pub fn register_collector<F, T>( &self, artifact_name: impl Into<String>, collect_fn: F, )
Registers a collector for a given artifact.
The collector is exposed until it is explicitly removed via unregister_collector, or until the owning
process exits, whichever comes first. Registering a collector with an artifact name that is already registered
by this subsystem replaces the previous one.
Care should be taken when registering a collector:
- the given artifact name should be unique within the overall system, and should be generally suitable as a file name when possible (artifact names are sanitized/normalized where necessary, but may lose useful information in the process)
- the collection function (
collect_fn) will be run synchronously and should return promptly, as it can delay the collection of artifacts for the whole system
Sourcepub fn unregister_collector(&self, artifact_name: impl AsRef<str>)
pub fn unregister_collector(&self, artifact_name: impl AsRef<str>)
Removes a previously registered collector by name
Does nothing if no collector with that name is currently registered by this subsystem.
Sourcepub fn emit(&self, event: DiagnosticEvent)
pub fn emit(&self, event: DiagnosticEvent)
Emits a diagnostic event.
Diagnostics events are transient and only delivered to active listeners.
Trait Implementations§
Source§impl Clone for DiagnosticsEmitter
impl Clone for DiagnosticsEmitter
Source§fn clone(&self) -> DiagnosticsEmitter
fn clone(&self) -> DiagnosticsEmitter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DiagnosticsEmitter
impl RefUnwindSafe for DiagnosticsEmitter
impl Send for DiagnosticsEmitter
impl Sync for DiagnosticsEmitter
impl Unpin for DiagnosticsEmitter
impl UnwindSafe for DiagnosticsEmitter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Track for T
impl<T> Track for T
§fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self>
fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self>
Tracked wrapper. Read more§fn in_current_resource_group(self) -> Tracked<Self>
fn in_current_resource_group(self) -> Tracked<Self>
Tracked wrapper. Read more