signal-kit 0.3.0

Helpers for initializing OpenTelemetry-based observability (tracing, metrics, logs) in async Rust services.
Documentation
//! Integration test: HTTPS OTLP/JSON export through a reqwest client with
//! `reqwest-rustls`.
//!
//! Runs as its own test binary because `signal-kit` installs the process-wide
//! tracing subscriber. A local TLS endpoint presents a self-signed certificate
//! that is also installed as the system trust anchor through `SSL_CERT_FILE`:
//! the export succeeds only if the client negotiates TLS and verifies the
//! certificate against the operating system's trust store.

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

mod support;

use support::{
    PROBE, emit_probe, otlp_json,
    tls::{SelfSignedCertificate, serve_https},
};

#[tokio::test(flavor = "multi_thread")]
async fn https_transport_exports_logs_with_the_caller_resource() {
    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();
    certificate.install_as_system_trust_anchor(trust_directory.path());

    let guard = emit_probe(format!("https://{address}"), "http/json");
    otlp_json::assert_still_queued(&mut exports).await;
    guard
        .shutdown()
        .expect("shutdown must flush all exporters over TLS");
    server.abort();
    otlp_json::assert_shared_resource(&mut exports, &PROBE.expected_attributes()).await;
}