diff --git a/Cargo.lock b/Cargo.lock index 130ec2f1a7..54b302fe25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -181,7 +181,6 @@ dependencies = [ "mockall", "moka", "once_cell", - "opentelemetry", "paste", "regex", "router-bridge", @@ -200,7 +199,6 @@ dependencies = [ "tower-service", "tower-test", "tracing", - "tracing-opentelemetry", "tracing-subscriber", "typed-builder", "url", diff --git a/apollo-router-core/Cargo.toml b/apollo-router-core/Cargo.toml index 69fa95efdb..ffaf8b06c2 100644 --- a/apollo-router-core/Cargo.toml +++ b/apollo-router-core/Cargo.toml @@ -28,7 +28,6 @@ miette = { version = "3.3.0", features = ["fancy"] } mockall = "0.11.0" moka = { version = "0.6.4", features = ["future", "futures-util"] } once_cell = "1.9.0" -opentelemetry = { version = "0.17.0", features = ["rt-tokio"] } paste = "1.0.6" regex = "1.5.4" router-bridge = { git = "https://github.com/apollographql/federation-rs.git", rev = "cf87257b9d58701cd9e09e8b5992f809147a2165" } @@ -46,7 +45,6 @@ tower = { version = "0.4.12", features = ["full"] } tower-service = "0.3.1" tower-test = "0.4.0" tracing = "0.1.31" -tracing-opentelemetry = "0.17.2" typed-builder = "0.9.1" url = "2.2.2" urlencoding = "2.1.0" diff --git a/apollo-router-core/src/layers/mod.rs b/apollo-router-core/src/layers/mod.rs index 807b111315..2835e51324 100644 --- a/apollo-router-core/src/layers/mod.rs +++ b/apollo-router-core/src/layers/mod.rs @@ -3,4 +3,3 @@ pub mod cache; pub mod deduplication; pub mod forbid_http_get_mutations; pub mod headers; -pub mod opentracing; diff --git a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__schema_generation.snap b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__schema_generation.snap index 9dca9eff54..ba4512fe1c 100644 --- a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__schema_generation.snap +++ b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__schema_generation.snap @@ -1,6 +1,6 @@ --- source: apollo-router/src/configuration/mod.rs -assertion_line: 645 +assertion_line: 474 expression: "&schema" --- @@ -235,13 +235,6 @@ expression: "&schema" } ] }, - "PropagationFormat": { - "type": "string", - "enum": [ - "jaeger", - "zipkin_b3" - ] - }, "RemoveConfig": { "oneOf": [ { @@ -318,11 +311,6 @@ expression: "&schema" "required": [ "headers_remove" ] - }, - { - "required": [ - "opentracing" - ] } ], "properties": { @@ -337,9 +325,6 @@ expression: "&schema" }, "headers_remove": { "$ref": "#/definitions/RemoveConfig" - }, - "opentracing": { - "$ref": "#/definitions/OpenTracingConfig" } } } diff --git a/apollo-router/src/layers/mod.rs b/apollo-router/src/layers/mod.rs index 8cb6ff0069..44908cdb9f 100644 --- a/apollo-router/src/layers/mod.rs +++ b/apollo-router/src/layers/mod.rs @@ -1 +1,2 @@ mod hello; +pub mod opentracing; diff --git a/apollo-router-core/src/layers/opentracing.rs b/apollo-router/src/layers/opentracing.rs similarity index 90% rename from apollo-router-core/src/layers/opentracing.rs rename to apollo-router/src/layers/opentracing.rs index 5a99deb0d7..0ff0f4d9a6 100644 --- a/apollo-router-core/src/layers/opentracing.rs +++ b/apollo-router/src/layers/opentracing.rs @@ -1,8 +1,7 @@ use std::fmt::Display; use std::task::{Context, Poll}; -use crate::layer::ConfigurableLayer; -use crate::{register_layer, services, SubgraphRequest}; +use apollo_router_core::{ConfigurableLayer, SubgraphRequest}; use http::HeaderValue; use opentelemetry::trace::TraceContextExt; use schemars::JsonSchema; @@ -12,11 +11,9 @@ use tracing::instrument::Instrumented; use tracing::{span, Instrument, Level, Span}; use tracing_opentelemetry::OpenTelemetrySpanExt; -register_layer!("opentracing", OpenTracingLayer); - #[derive(Clone, JsonSchema, Deserialize, Debug)] #[serde(rename_all = "snake_case")] -enum PropagationFormat { +pub enum PropagationFormat { Jaeger, ZipkinB3, } @@ -30,12 +27,13 @@ impl Display for PropagationFormat { } } -#[derive(Clone, JsonSchema, Deserialize)] -struct OpenTracingConfig { +#[derive(Clone, JsonSchema, Deserialize, Debug)] +pub struct OpenTracingConfig { format: PropagationFormat, } -struct OpenTracingLayer { +#[derive(Debug)] +pub struct OpenTracingLayer { format: PropagationFormat, } @@ -59,7 +57,7 @@ impl Layer for OpenTracingLayer { } } -struct OpenTracingService { +pub struct OpenTracingService { inner: S, format: PropagationFormat, } @@ -70,7 +68,7 @@ where { type Response = S::Response; type Error = S::Error; - type Future = Instrumented<>::Future>; + type Future = Instrumented<>::Future>; fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { self.inner.poll_ready(cx) diff --git a/apollo-router/src/plugins/reporting.rs b/apollo-router/src/plugins/reporting.rs index 43843a773c..c28dddf26a 100644 --- a/apollo-router/src/plugins/reporting.rs +++ b/apollo-router/src/plugins/reporting.rs @@ -5,8 +5,14 @@ use crate::apollo_telemetry::new_pipeline; use crate::apollo_telemetry::SpaceportConfig; use crate::apollo_telemetry::StudioGraph; use crate::configuration::{default_service_name, default_service_namespace}; +use crate::layers::opentracing::OpenTracingConfig; +use crate::layers::opentracing::OpenTracingLayer; use crate::set_subscriber; use crate::GLOBAL_ENV_FILTER; + +use apollo_router_core::ConfigurableLayer; +use apollo_router_core::SubgraphRequest; +use apollo_router_core::SubgraphResponse; use apollo_router_core::{register_plugin, Plugin}; use apollo_spaceport::server::ReportSpaceport; use derivative::Derivative; @@ -28,7 +34,9 @@ use std::net::SocketAddr; use std::pin::Pin; use std::str::FromStr; use std::sync::Arc; -use tower::BoxError; +use tower::util::BoxService; +use tower::Layer; +use tower::{BoxError, ServiceExt}; use tracing_subscriber::prelude::*; use tracing_subscriber::EnvFilter; @@ -159,6 +167,7 @@ impl std::error::Error for ReportingError {} struct Reporting { config: Conf, tx: tokio::sync::mpsc::Sender, + opentracing_layer: Option, } #[derive(Debug, Deserialize, JsonSchema)] @@ -168,6 +177,8 @@ struct Conf { pub graph: Option, pub opentelemetry: Option, + + pub opentracing: Option, } fn studio_graph() -> Option { @@ -254,11 +265,29 @@ impl Plugin for Reporting { } tracing::debug!("terminating spaceport loop"); }); + + let mut opentracing_layer = None; + if let Some(opentracing_conf) = &configuration.opentracing { + opentracing_layer = OpenTracingLayer::new(opentracing_conf.clone())?.into(); + } + Ok(Reporting { config: configuration, tx, + opentracing_layer, }) } + + fn subgraph_service( + &mut self, + _name: &str, + service: BoxService, + ) -> BoxService { + match &self.opentracing_layer { + Some(opentracing_layer) => opentracing_layer.layer(service).boxed(), + None => service, + } + } } impl Reporting {