#[cfg(feature = "profiling-bridge-pyroscope-rs")]
#[tokio::test]
async fn profiling_bridge_enabled_when_sub_feature_active() {
let result = otel_bootstrap::Telemetry::builder("test-service")
.with_profiling("http://localhost:4040")
.init();
assert!(
result.is_ok(),
"init should succeed — pyroscope agent start() is lazy and does not eagerly connect"
);
if let Ok(handles) = result {
let span = tracing::info_span!("profiling_test");
let _guard = span.enter();
let _ = handles.shutdown();
}
}
#[cfg(all(feature = "profiling", not(feature = "profiling-bridge-pyroscope-rs")))]
#[tokio::test]
async fn profiling_enabled_but_bridge_not_active() {
let result = otel_bootstrap::Telemetry::builder("test-service").init();
assert!(result.is_ok(), "init should succeed when profiling enabled");
if let Ok(handles) = result {
assert!(
handles.profiling_handle.is_none(),
"profiling_handle should be None when bridge feature not enabled"
);
let _ = handles.shutdown();
}
}
#[cfg(feature = "profiling-bridge-pyroscope-rs")]
#[tokio::test]
async fn profiling_bridge_initializes_without_server() {
let result = otel_bootstrap::Telemetry::builder("test-service")
.with_profiling("http://localhost:19999")
.init();
assert!(
result.is_ok(),
"init should succeed even with unreachable endpoint"
);
if let Ok(handles) = result {
assert!(
handles.profiling_handle.is_some(),
"profiling_handle should be Some when bridge is active"
);
let _ = handles.shutdown();
}
}
#[cfg(feature = "profiling-bridge-pyroscope-rs")]
#[tokio::test]
async fn profiling_bridge_rejects_non_loopback_endpoint() {
let result = otel_bootstrap::Telemetry::builder("test-service")
.with_profiling("http://10.0.1.5:4040")
.init();
assert!(
result.is_err(),
"init should fail when endpoint targets non-loopback address"
);
if let Err(e) = result {
let msg = e.to_string();
assert!(
msg.contains("loopback") || msg.contains("127.0.0.1"),
"error should mention loopback requirement: {msg}"
);
}
}
#[cfg(feature = "profiling-bridge-pyroscope-rs")]
#[tokio::test]
async fn profiling_bridge_accepts_ipv6_loopback() {
let result = otel_bootstrap::Telemetry::builder("test-service")
.with_profiling("http://[::1]:4040")
.init();
assert!(
result.is_ok(),
"init should succeed with IPv6 loopback endpoint"
);
if let Ok(handles) = result {
let _ = handles.shutdown();
}
}
#[cfg(feature = "profiling-bridge-pyroscope-rs")]
#[tokio::test]
async fn profiling_bridge_accepts_unix_socket() {
let result = otel_bootstrap::Telemetry::builder("test-service")
.with_profiling("unix:///tmp/pyroscope.sock")
.init();
assert!(
result.is_ok(),
"init should succeed with unix socket endpoint"
);
if let Ok(handles) = result {
let _ = handles.shutdown();
}
}
#[cfg(not(feature = "profiling"))]
#[tokio::test]
async fn profiling_feature_disabled() {
let result = otel_bootstrap::Telemetry::builder("test-service").init();
assert!(
result.is_ok(),
"init should succeed when profiling disabled"
);
}