Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,6 @@ dependencies = [
"tower-test",
"tracing",
"tracing-core",
"tracing-fluent-assertions",
"tracing-futures",
"tracing-opentelemetry",
"tracing-serde",
Expand Down Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion apollo-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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": {}
}
}
}
69 changes: 35 additions & 34 deletions apollo-router/src/plugins/connectors/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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]
Expand Down