Crate spotflow_logger

Crate spotflow_logger 

Source
Expand description

An unofficial Spotflow Observability Platform client.

§Overview

This crate provides a simple API for logging messages to the Spotflow Observability Platform. It could be used directly or as an integration with tracing crate. For tracing it provides a tracing-subscriber Layer.

Current implementation is std and requires async environment.

§Examples

let (spotflow_logger, spotflow_task, spotflow_stopper) = SpotflowLogger::builder()
    // name of device to be displayed in Spotflow Observability Platform
    .set_device_id("test1")
    // spotflow ingest key from https://app.spotflow.io/ingest-keys
    .set_password(mqtt_password)
    .build();

// spawn task handling MQTT communication with spotflow platform
let spotflow_task = task::spawn(spotflow_task);

// register client with tracing-subscriber
tracing_subscriber::registry()
    .with(LevelFilter::INFO)
    .with(spotflow_logger)
    .init();

tracing::info!("test message");

// send a request to finish `spotflow_task`
spotflow_stopper.stop().unwrap();
// join the `spotflow_task`
_ = spotflow_task.await;

§API

The entry point to this crate is SpotflowLogger::builder, which creates a SpotflowLoggerBuilder instance.

§Unresolved Issues

Currently there are following issues:

  • Errors during log line send or processing are suppressed.

  • MQTT QoS is forced to be AtMostOnce.

  • TRACE log level is mapped to DEBUG since spotflow does not support TRACE.

  • Some large integral types like u128 are not supported for cbor.

  • Tracing span and instrument are not supported.

  • no_std environment is not supported.

§Feature Flags

Following features are supported:

  • cbor (on by default). Uses CBOR object representation for log messages. This feature flag is mutually exclusive with json.

  • json. Uses JSON format for log messages. This feature flag is mutually exclusive with cbor.

  • tracing. Provides additianal API for tracing crate integration.

Structs§

LabelName
LogLine
SpotflowLogger
SpotflowLoggerBuilder

Enums§

LabelValue
Severity
SpotflowError