#![cfg(test)]
use std::collections::HashMap;
#[derive(Debug, Default)]
struct ResourceAttributeBuilderFixture {
attributes: HashMap<String, String>,
}
impl ResourceAttributeBuilderFixture {
fn new() -> Self {
Self::default()
}
fn add_attribute(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.attributes.insert(key.into(), value.into());
self
}
fn build_current(&self) -> Vec<(String, String)> {
self.attributes
.iter()
.map(|(k, v)| (k.clone(), v.clone()))
.collect()
}
fn build_otlp_compliant(&self) -> Vec<(String, String)> {
self.attributes
.iter()
.filter(|(_key, value)| !value.is_empty()) .map(|(k, v)| (k.clone(), v.clone()))
.collect()
}
}
fn current_key_value_behavior(key: &str, value: &str) -> Option<(String, String)> {
Some((key.to_string(), value.to_string()))
}
fn otlp_compliant_key_value_behavior(key: &str, value: &str) -> Option<(String, String)> {
if value.is_empty() {
None
} else {
Some((key.to_string(), value.to_string()))
}
}
#[test]
fn audit_otlp_empty_resource_attribute_handling() {
println!("๐ AUDIT: OTLP resource attribute empty string value handling per ยง2.3.1");
println!("๐ OTLP ยง2.3.1 specification requirements:");
println!(" โข Empty string values MUST be dropped");
println!(" โข Resource attributes with empty values MUST NOT be exported");
println!(" โข NOT: preserve empty string in OTLP payload");
println!(" โข NOT: export {{\"string_value\": \"\"}}");
let test_scenarios = vec![
("service.name", ""),
("service.version", ""),
("deployment.environment", ""),
("telemetry.sdk.name", ""), ];
println!("๐ Testing empty string resource attributes:");
for (key, empty_value) in test_scenarios {
println!(" Testing: {}=\"{}\"", key, empty_value);
let current_result = current_key_value_behavior(key, empty_value);
let should_be_included_current = current_result.is_some();
let compliant_result = otlp_compliant_key_value_behavior(key, empty_value);
let should_be_included_compliant = compliant_result.is_some();
println!(
" Current implementation: {} (preserves empty)",
if should_be_included_current {
"INCLUDES"
} else {
"DROPS"
}
);
println!(
" OTLP ยง2.3.1 compliant: {} (drops empty)",
if should_be_included_compliant {
"INCLUDES"
} else {
"DROPS"
}
);
if should_be_included_current && !should_be_included_compliant {
println!(" โ SPEC VIOLATION: Empty value should be dropped");
} else if should_be_included_current == should_be_included_compliant {
println!(" โ
SPEC COMPLIANT: Behavior matches requirement");
}
}
println!("๐ Full resource attribute handling:");
let mixed_attributes = ResourceAttributeBuilderFixture::new()
.add_attribute("service.name", "") .add_attribute("service.version", "1.0.0") .add_attribute("deployment.environment", "") .add_attribute("service.instance.id", "instance-123") .add_attribute("telemetry.sdk.name", "asupersync") .add_attribute("custom.empty", "") .add_attribute("custom.valid", "value");
let current_attrs = mixed_attributes.build_current();
let compliant_attrs = mixed_attributes.build_otlp_compliant();
println!(" Input attributes: 7 total (4 valid, 3 empty)");
println!(
" Current implementation exports: {} attributes",
current_attrs.len()
);
println!(
" OTLP ยง2.3.1 compliant exports: {} attributes",
compliant_attrs.len()
);
let empty_count_current = current_attrs
.iter()
.filter(|(_key, value)| value.is_empty())
.count();
let empty_count_compliant = compliant_attrs
.iter()
.filter(|(_key, value)| value.is_empty())
.count();
println!(
" Current implementation empty values exported: {}",
empty_count_current
);
println!(
" OTLP compliant empty values exported: {}",
empty_count_compliant
);
if empty_count_current > 0 {
println!("๐จ OTLP ยง2.3.1 VIOLATION DETECTED");
println!("๐ก DEFECT: Empty string values are preserved in export");
println!("๐ IMPACT: OTLP payload contains invalid empty resource attributes");
println!("๐ง REQUIRED FIX:");
println!(" 1. Modify key_value() function to validate non-empty values");
println!(" 2. Filter out empty strings before OTLP serialization");
println!(" 3. Apply validation in ordered_proto_attributes()");
assert!(
empty_count_current > 0,
"Audit confirms OTLP ยง2.3.1 violation exists"
);
} else {
println!("โ
OTLP ยง2.3.1 COMPLIANCE: Empty values correctly dropped");
}
assert_eq!(
empty_count_compliant, 0,
"OTLP compliant implementation should never export empty values"
);
assert_eq!(
compliant_attrs.len(),
4,
"Should export exactly 4 valid attributes"
);
println!("โ
OTLP EMPTY RESOURCE ATTRIBUTES AUDIT COMPLETE");
}
#[test]
fn audit_empty_string_edge_cases() {
println!("๐ AUDIT: Empty string detection edge cases per OTLP ยง2.3.1");
let edge_case_scenarios = vec![
("", true, "truly empty string"),
(" ", false, "single space - valid value"),
(" ", false, "multiple spaces - valid value"),
("\t", false, "tab character - valid value"),
("\n", false, "newline character - valid value"),
("null", false, "string 'null' - valid value"),
("undefined", false, "string 'undefined' - valid value"),
("0", false, "string '0' - valid value"),
("false", false, "string 'false' - valid value"),
];
println!("๐ Edge case value analysis:");
let mut compliance_violations = 0;
for (test_value, should_be_dropped, description) in edge_case_scenarios {
println!(" Value: {:?} ({})", test_value, description);
let current_drops = current_key_value_behavior("test.key", test_value).is_none();
let otlp_drops = otlp_compliant_key_value_behavior("test.key", test_value).is_none();
println!(
" Current implementation: {}",
if current_drops { "DROPS" } else { "PRESERVES" }
);
println!(
" OTLP ยง2.3.1 spec: {}",
if should_be_dropped {
"DROP"
} else {
"PRESERVE"
}
);
let is_compliant =
(current_drops == should_be_dropped) && (otlp_drops == should_be_dropped);
if is_compliant {
println!(" โ
COMPLIANT: Correct behavior");
} else {
println!(" โ NON-COMPLIANT: Behavior mismatch");
compliance_violations += 1;
}
}
println!("๐ Edge case precision analysis:");
if compliance_violations == 0 {
println!(" โ
ALL EDGE CASES: Compliant behavior");
} else {
println!(
" โ COMPLIANCE VIOLATIONS: {} edge cases",
compliance_violations
);
}
println!("๐ OTLP ยง2.3.1 specification interpretation:");
println!(" โข Only empty string (\"\") should be dropped");
println!(" โข Whitespace-only strings are valid values");
println!(" โข String representations of null/false/0 are valid");
println!(" โข Preserve semantic meaning of user input");
println!("โ
EMPTY STRING EDGE CASES AUDIT COMPLETE");
}
#[test]
fn audit_empty_values_in_otlp_payload() {
println!("๐ AUDIT: Empty values in actual OTLP protobuf payload");
println!("๐ OTLP wire format compliance:");
println!(" โข Resource attributes section must not contain empty string values");
println!(" โข {{\"string_value\": \"\"}} violates OTLP ยง2.3.1");
println!(" โข Collectors may reject payloads with invalid empty attributes");
println!("๐ Current implementation analysis:");
println!(" File: src/observability/otel.rs");
println!(" Function: key_value() at lines 5764, 6054");
println!(" Behavior: Creates KeyValue regardless of empty value");
println!(" Result: Empty strings become {{\"string_value\": \"\"}}");
let empty_service_name = "";
let valid_service_name = "my-service";
println!("๐ OTLP wire format simulation:");
println!(" Empty service.name input: {:?}", empty_service_name);
println!(" Current wire format output:");
println!(" {{");
println!(" \"key\": \"service.name\",");
println!(
" \"value\": {{\"string_value\": \"{}\"}} โ",
empty_service_name
);
println!(" }}");
println!(" Valid service.name input: {:?}", valid_service_name);
println!(" Correct wire format output:");
println!(" {{");
println!(" \"key\": \"service.name\",");
println!(
" \"value\": {{\"string_value\": \"{}\"}} โ
",
valid_service_name
);
println!(" }}");
println!("๐จ OTLP ยง2.3.1 VIOLATION EVIDENCE:");
println!(" โข Empty string values exported to wire format");
println!(" โข Violates OTLP specification requirement");
println!(" โข May cause collector rejection or processing errors");
println!(" โข Affects telemetry data quality");
println!("๐ Collector compatibility impact:");
println!(" โข OpenTelemetry Collector: May accept but log warnings");
println!(" โข Jaeger: May reject empty service.name values");
println!(" โข Vendor collectors: Undefined behavior with empty values");
println!(" โข Standard compliance: Violates interoperability");
println!("โ
OTLP PAYLOAD EMPTY VALUES AUDIT COMPLETE");
println!("๐จ CRITICAL FINDING: Empty values reach OTLP wire format");
}