#![cfg(feature = "experimental-code-location")]
use apollo_opentelemetry_test::TelemetryContext;
#[test]
fn log_bridge_includes_code_location() {
let ctx = TelemetryContext::new();
log::warn!("something happened");
let logs = ctx.logs();
assert_eq!(logs.len(), 1, "expected 1 log record");
let record = &logs[0].record;
let attr_keys: Vec<&str> = record.attributes_iter().map(|(k, _)| k.as_str()).collect();
assert!(
attr_keys.contains(&"code.function.name"),
"code.function.name missing from attributes: {attr_keys:?}"
);
assert!(
attr_keys.contains(&"code.file.path"),
"code.file.path missing from attributes: {attr_keys:?}"
);
assert!(
attr_keys.contains(&"code.line.number"),
"code.line.number missing from attributes: {attr_keys:?}"
);
}
#[test]
fn tracing_bridge_includes_code_location() {
let ctx = TelemetryContext::new();
tracing::warn!("something happened");
let logs = ctx.logs();
assert_eq!(logs.len(), 1, "expected 1 log record");
let record = &logs[0].record;
let attr_keys: Vec<&str> = record.attributes_iter().map(|(k, _)| k.as_str()).collect();
assert!(
attr_keys.contains(&"code.namespace"),
"code.namespace missing from attributes: {attr_keys:?}"
);
assert!(
attr_keys.contains(&"code.filepath"),
"code.filepath missing from attributes: {attr_keys:?}"
);
assert!(
attr_keys.contains(&"code.lineno"),
"code.lineno missing from attributes: {attr_keys:?}"
);
}