apollo-opentelemetry 0.8.0

OpenTelemetry configuration types for Apollo platform
Documentation
//! Integration tests for the `experimental-code-location` feature.
//!
//! Verifies that when this feature is enabled, both the `log` and `tracing`
//! bridges include code location attributes on emitted log records.

#![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();

    // opentelemetry-appender-log uses the newer semconv key names
    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();

    // opentelemetry-appender-tracing uses the older semconv key names
    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:?}"
    );
}