signal-kit 0.3.0

Helpers for initializing OpenTelemetry-based observability (tracing, metrics, logs) in async Rust services.
Documentation
//! Integration test: the reqwest clients verify HTTPS certificates against the
//! operating system's trust store.
//!
//! A local TLS endpoint presents a self-signed certificate while the system
//! store is emptied through `SSL_CERT_FILE`: the export must fail. The same
//! endpoint succeeds once the certificate is trusted (`otlp_https_logs`), so
//! the trust store is what refused it — `reqwest-rustls` neither skips
//! verification nor falls back to bundled roots.

#![cfg(all(
    feature = "http-json",
    feature = "reqwest-rustls",
    feature = "reqwest-client",
    feature = "logs-otlp",
    feature = "metrics",
    feature = "traces"
))]

mod support;

use signal_kit::OtelShutdownFailure;
use support::{
    emit_probe, otlp_json,
    tls::{SelfSignedCertificate, install_empty_system_trust_anchor, serve_https},
};

#[tokio::test(flavor = "multi_thread")]
async fn https_transport_rejects_certificates_outside_the_system_trust_store() {
    let certificate = SelfSignedCertificate::generate();
    let (app, mut exports) = otlp_json::receiver();
    let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
    let address = listener.local_addr().unwrap();
    let server = tokio::spawn(serve_https(app, listener, certificate.server_config()));
    let trust_directory = tempfile::tempdir().unwrap();
    install_empty_system_trust_anchor(trust_directory.path());

    let guard = emit_probe(format!("https://{address}"), "http/json");
    otlp_json::assert_still_queued(&mut exports).await;
    let error = guard
        .shutdown()
        .expect_err("the system trust store must reject the self-signed certificate");
    server.abort();

    // The OTel HTTP client reports the TLS failure only as a "network error",
    // and a failed scheduled flush can empty a batch before its shutdown, so
    // not every signal necessarily reports it.
    assert!(
        error
            .failures()
            .iter()
            .any(|failure| matches!(failure, OtelShutdownFailure::TracerProvider(_))),
        "the tracer must refuse the untrusted endpoint: {error:?}"
    );
}