diff --git a/Cargo.lock b/Cargo.lock index f8f206d697..1028b10537 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -628,7 +628,6 @@ dependencies = [ "tower-test", "tracing", "tracing-core", - "tracing-fluent-assertions", "tracing-futures", "tracing-opentelemetry", "tracing-serde", @@ -7634,17 +7633,6 @@ dependencies = [ "valuable", ] -[[package]] -name = "tracing-fluent-assertions" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12de1a8c6bcfee614305e836308b596bbac831137a04c61f7e5b0b0bf2cfeaf6" -dependencies = [ - "tracing", - "tracing-core", - "tracing-subscriber", -] - [[package]] name = "tracing-futures" version = "0.2.5" diff --git a/apollo-router/Cargo.toml b/apollo-router/Cargo.toml index 67bd19ef8f..27fffa2157 100644 --- a/apollo-router/Cargo.toml +++ b/apollo-router/Cargo.toml @@ -338,7 +338,6 @@ tower-test = "0.4.0" # See note above in this file about `^tracing` packages which also applies to # these dev dependencies. -tracing-fluent-assertions = "0.3.0" tracing-subscriber = { version = "0.3.18", default-features = false, features = [ "env-filter", "fmt", diff --git a/apollo-router/src/plugins/connectors/snapshots/apollo_router__plugins__connectors__tests__tracing_connect_span.snap b/apollo-router/src/plugins/connectors/snapshots/apollo_router__plugins__connectors__tests__tracing_connect_span.snap new file mode 100644 index 0000000000..4fc985cf8d --- /dev/null +++ b/apollo-router/src/plugins/connectors/snapshots/apollo_router__plugins__connectors__tests__tracing_connect_span.snap @@ -0,0 +1,79 @@ +--- +source: apollo-router/src/plugins/connectors/tests.rs +expression: span +--- +{ + "name": "apollo_router::plugins::connectors::tests::root", + "record": { + "entries": [], + "metadata": { + "name": "root", + "target": "apollo_router::plugins::connectors::tests", + "level": "ERROR", + "module_path": "apollo_router::plugins::connectors::tests", + "fields": { + "names": [] + } + } + }, + "children": { + "apollo_router::services::connector_service::connect": { + "name": "apollo_router::services::connector_service::connect", + "record": { + "entries": [ + [ + "otel.kind", + "INTERNAL" + ], + [ + "apollo.connector.type", + "http" + ], + [ + "apollo.connector.field.name", + "users" + ], + [ + "apollo.connector.selection", + "{\n id\n name\n}" + ], + [ + "apollo_private.sent_time_offset", + "[sent_time_offset_redacted]" + ], + [ + "apollo.connector.detail", + "{\"GET\":\"/users\"}" + ], + [ + "apollo.connector.source.name", + "json" + ], + [ + "apollo.connector.source.detail", + "[source_detail_redacted]" + ] + ], + "metadata": { + "name": "connect", + "target": "apollo_router::services::connector_service", + "level": "INFO", + "module_path": "apollo_router::services::connector_service", + "fields": { + "names": [ + "otel.kind", + "apollo.connector.type", + "apollo.connector.detail", + "apollo.connector.field.name", + "apollo.connector.selection", + "apollo.connector.source.name", + "apollo.connector.source.detail", + "apollo_private.sent_time_offset" + ] + } + } + }, + "children": {} + } + } +} diff --git a/apollo-router/src/plugins/connectors/tests.rs b/apollo-router/src/plugins/connectors/tests.rs index b49a97fdf2..ecae8094c6 100644 --- a/apollo-router/src/plugins/connectors/tests.rs +++ b/apollo-router/src/plugins/connectors/tests.rs @@ -8,11 +8,11 @@ use itertools::Itertools; use mime::APPLICATION_JSON; use req_asserts::Matcher; use serde_json_bytes::json; +use test_span::get_spans_for_root; +use test_span::prelude::test_span; +use test_span::Filter; use tower::ServiceExt; -use tracing_fluent_assertions::AssertionRegistry; -use tracing_fluent_assertions::AssertionsLayer; -use tracing_subscriber::layer::SubscriberExt; -use tracing_subscriber::Registry; +use tracing_core::Level; use wiremock::http::HeaderName; use wiremock::http::HeaderValue; use wiremock::matchers::body_json; @@ -23,7 +23,6 @@ use wiremock::MockServer; use wiremock::ResponseTemplate; use crate::json_ext::ValueExt; -use crate::plugins::connectors::tracing::CONNECT_SPAN_NAME; use crate::router_factory::RouterSuperServiceFactory; use crate::router_factory::YamlRouterFactory; use crate::services::new_service::ServiceFactory; @@ -475,40 +474,42 @@ async fn test_headers() { ); } -#[tokio::test] +#[test_span(tokio::test)] async fn test_tracing_connect_span() { - let assertion_registry = AssertionRegistry::default(); - let base_subscriber = Registry::default(); - let subscriber = base_subscriber.with(AssertionsLayer::new(&assertion_registry)); - let _guard = tracing::subscriber::set_default(subscriber); - - let found_connector_span = assertion_registry - .build() - .with_name(CONNECT_SPAN_NAME) - .with_span_field("apollo.connector.type") - .with_span_field("apollo.connector.detail") - .with_span_field("apollo.connector.field.name") - .with_span_field("apollo.connector.selection") - .with_span_field("apollo.connector.source.name") - .with_span_field("apollo.connector.source.detail") - .was_entered() - .was_exited() - .finalize(); - let mock_server = MockServer::start().await; mock_api::users().mount(&mock_server).await; - execute( - STEEL_THREAD_SCHEMA, - &mock_server.uri(), - "query { users { id } }", - Default::default(), - None, - |_| {}, - ) - .await; + let root_id = { + let root_span = test_span::reexports::tracing::span!(Level::ERROR, "root"); + + let root_id = root_span + .id() + .expect("couldn't get root span id; this cannot happen."); + + execute( + STEEL_THREAD_SCHEMA, + &mock_server.uri(), + "query { users { id } }", + Default::default(), + None, + |_| {}, + ) + .instrument(root_span) + .await; + root_id + }; - found_connector_span.assert(); + // Filter to just the connector service span + let filter = Filter::new(Level::ERROR).with_target( + String::from("apollo_router::services::connector_service"), + Level::INFO, + ); + + // Redact time offset and local port that change with every test run + insta::assert_json_snapshot!(get_spans_for_root(&root_id, &filter), { + ".children.*.record.entries[4][1]" => "[sent_time_offset_redacted]", + ".children.*.record.entries[7][1]" => "[source_detail_redacted]", + }); } #[tokio::test]