diff --git a/Cargo.lock b/Cargo.lock index 30dd2087..9d9783fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -173,6 +173,22 @@ dependencies = [ "syn 2.0.33", ] +[[package]] +name = "axum-tracing-opentelemetry" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "164b95427e83b79583c7699a72b4a6b485a12bbdef5b5c054ee5ff2296d82f52" +dependencies = [ + "axum", + "futures", + "http", + "opentelemetry 0.18.0", + "tower", + "tower-http 0.3.5", + "tracing", + "tracing-opentelemetry 0.18.0", +] + [[package]] name = "backtrace" version = "0.3.69" @@ -434,6 +450,19 @@ dependencies = [ "syn 2.0.33", ] +[[package]] +name = "dashmap" +version = "5.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" +dependencies = [ + "cfg-if", + "hashbrown 0.14.0", + "lock_api", + "once_cell", + "parking_lot_core", +] + [[package]] name = "deranged" version = "0.3.8" @@ -527,6 +556,21 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.28" @@ -534,6 +578,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -588,6 +633,7 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ + "futures-channel", "futures-core", "futures-io", "futures-macro", @@ -991,7 +1037,7 @@ source = "git+http://github.com/hasura/ndc-spec.git?tag=v0.1.0-rc.6#af2a6fa44761 dependencies = [ "async-trait", "indexmap 1.9.3", - "opentelemetry", + "opentelemetry 0.20.0", "reqwest", "schemars", "serde", @@ -1008,16 +1054,17 @@ dependencies = [ "async-trait", "axum", "axum-macros", + "axum-tracing-opentelemetry", "clap", "gdc_rust_types", "indexmap 1.9.3", "ndc-client", "ndc-test", - "opentelemetry", + "opentelemetry 0.20.0", "opentelemetry-otlp", "opentelemetry-semantic-conventions", - "opentelemetry_api", - "opentelemetry_sdk", + "opentelemetry_api 0.20.0", + "opentelemetry_sdk 0.20.0", "prometheus", "reqwest", "schemars", @@ -1025,9 +1072,9 @@ dependencies = [ "serde_json", "thiserror", "tokio", - "tower-http", + "tower-http 0.4.4", "tracing", - "tracing-opentelemetry", + "tracing-opentelemetry 0.20.0", "tracing-subscriber", "url", "uuid", @@ -1102,7 +1149,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75e56d5c441965b6425165b7e3223cc933ca469834f4a8b4786817a1f9dc4f13" dependencies = [ - "indexmap 1.9.3", + "indexmap 2.0.0", "serde", "serde_json", ] @@ -1151,14 +1198,24 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "opentelemetry" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69d6c3d7288a106c0a363e4b0e8d308058d56902adefb16f4936f417ffef086e" +dependencies = [ + "opentelemetry_api 0.18.0", + "opentelemetry_sdk 0.18.0", +] + [[package]] name = "opentelemetry" version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9591d937bc0e6d2feb6f71a559540ab300ea49955229c347a517a28d27784c54" dependencies = [ - "opentelemetry_api", - "opentelemetry_sdk", + "opentelemetry_api 0.20.0", + "opentelemetry_sdk 0.20.0", ] [[package]] @@ -1170,7 +1227,7 @@ dependencies = [ "async-trait", "bytes", "http", - "opentelemetry_api", + "opentelemetry_api 0.20.0", "reqwest", ] @@ -1186,8 +1243,8 @@ dependencies = [ "opentelemetry-http", "opentelemetry-proto", "opentelemetry-semantic-conventions", - "opentelemetry_api", - "opentelemetry_sdk", + "opentelemetry_api 0.20.0", + "opentelemetry_sdk 0.20.0", "prost", "reqwest", "thiserror", @@ -1201,8 +1258,8 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1e3f814aa9f8c905d0ee4bde026afd3b2577a97c10e1699912e3e44f0c4cbeb" dependencies = [ - "opentelemetry_api", - "opentelemetry_sdk", + "opentelemetry_api 0.20.0", + "opentelemetry_sdk 0.20.0", "prost", "tonic", ] @@ -1213,7 +1270,23 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73c9f9340ad135068800e7f1b24e9e09ed9e7143f5bf8518ded3d3ec69789269" dependencies = [ - "opentelemetry", + "opentelemetry 0.20.0", +] + +[[package]] +name = "opentelemetry_api" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c24f96e21e7acc813c7a8394ee94978929db2bcc46cf6b5014fc612bf7760c22" +dependencies = [ + "fnv", + "futures-channel", + "futures-util", + "indexmap 1.9.3", + "js-sys", + "once_cell", + "pin-project-lite", + "thiserror", ] [[package]] @@ -1232,6 +1305,28 @@ dependencies = [ "urlencoding", ] +[[package]] +name = "opentelemetry_sdk" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ca41c4933371b61c2a2f214bf16931499af4ec90543604ec828f7a625c09113" +dependencies = [ + "async-trait", + "crossbeam-channel", + "dashmap", + "fnv", + "futures-channel", + "futures-executor", + "futures-util", + "once_cell", + "opentelemetry_api 0.18.0", + "percent-encoding", + "rand", + "thiserror", + "tokio", + "tokio-stream", +] + [[package]] name = "opentelemetry_sdk" version = "0.20.0" @@ -1244,7 +1339,7 @@ dependencies = [ "futures-executor", "futures-util", "once_cell", - "opentelemetry_api", + "opentelemetry_api 0.20.0", "ordered-float", "percent-encoding", "rand", @@ -2131,6 +2226,25 @@ dependencies = [ "tracing", ] +[[package]] +name = "tower-http" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f873044bf02dd1e8239e9c1293ea39dad76dc594ec16185d0a1bf31d8dc8d858" +dependencies = [ + "bitflags 1.3.2", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-range-header", + "pin-project-lite", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "tower-http" version = "0.4.4" @@ -2208,6 +2322,20 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-opentelemetry" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21ebb87a95ea13271332df069020513ab70bdb5637ca42d6e492dc3bbbad48de" +dependencies = [ + "once_cell", + "opentelemetry 0.18.0", + "tracing", + "tracing-core", + "tracing-log", + "tracing-subscriber", +] + [[package]] name = "tracing-opentelemetry" version = "0.20.0" @@ -2215,7 +2343,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc09e402904a5261e42cf27aea09ccb7d5318c6717a9eec3d8e2e65c56b18f19" dependencies = [ "once_cell", - "opentelemetry", + "opentelemetry 0.20.0", "tracing", "tracing-core", "tracing-log", diff --git a/rust-connector-sdk/Cargo.toml b/rust-connector-sdk/Cargo.toml index 7aa786d8..0ef57580 100644 --- a/rust-connector-sdk/Cargo.toml +++ b/rust-connector-sdk/Cargo.toml @@ -15,6 +15,7 @@ path = "bin/main.rs" async-trait = "^0.1.68" axum = "^0.6.18" axum-macros = "^0.3.7" +axum-tracing-opentelemetry = { version = "0.10.0", features = [] } clap = { version = "^4.3.9", features = ["derive", "env"] } ndc-client = { git = "http://github.com/hasura/ndc-spec.git", tag = "v0.1.0-rc.6" } ndc-test = { git = "http://github.com/hasura/ndc-spec.git", tag = "v0.1.0-rc.6" } diff --git a/rust-connector-sdk/src/default_main.rs b/rust-connector-sdk/src/default_main.rs index d21f4c77..c883bbc8 100644 --- a/rust-connector-sdk/src/default_main.rs +++ b/rust-connector-sdk/src/default_main.rs @@ -5,7 +5,6 @@ use crate::{ connector::{Connector, InvalidRange, SchemaError, UpdateConfigurationError}, routes, }; - use async_trait::async_trait; use axum::{ body::Body, @@ -15,6 +14,7 @@ use axum::{ routing::{get, post}, Json, Router, }; +use axum_tracing_opentelemetry::{opentelemetry_tracing_layer, response_with_trace_layer}; use tower_http::validate_request::ValidateRequestHeaderLayer; use clap::{Parser, Subcommand}; @@ -322,7 +322,11 @@ where .route("/query", post(post_query::)) .route("/explain", post(post_explain::)) .route("/mutation", post(post_mutation::)) - .with_state(state); + .with_state(state) + // include trace context as header in responses to handlers above this line + .layer(response_with_trace_layer()) + // set up `TraceLayer` from tower-http + .layer(opentelemetry_tracing_layer()); let expected_auth_header: Option = service_token_secret.and_then(|service_token_secret| { @@ -331,10 +335,7 @@ where }); router - .layer( - TraceLayer::new_for_http() - .make_span_with(DefaultMakeSpan::default().level(Level::INFO)), - ) + .layer(TraceLayer::new_for_http()) .layer(ValidateRequestHeaderLayer::custom( move |request: &mut Request| { // Validate the request