fyi-core 0.1.0

Core types and traits for fyi
Documentation
//! Attribute parsing helpers for OTLP log records
//!
//! This module provides helper functions for extracting values from OTLP
//! attribute arrays, reducing code duplication across different parsers.

use super::otlp_types::KeyValue;

/// Find a string attribute value by key
pub fn get_string(attrs: &[KeyValue], key: &str) -> Option<String> {
    attrs
        .iter()
        .find(|kv| kv.key == key)
        .and_then(|kv| kv.value.string_value.clone())
}

/// Find an i64 attribute value by key (handles both string and int values)
pub fn get_i64(attrs: &[KeyValue], key: &str) -> Option<i64> {
    attrs
        .iter()
        .find(|kv| kv.key == key)
        .and_then(|kv| kv.value.as_i64())
}

/// Check if an attribute with the given key exists
pub fn has_attr(attrs: &[KeyValue], key: &str) -> bool {
    attrs.iter().any(|kv| kv.key == key)
}