Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add opentracing layer #548

Merged
merged 5 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions apollo-router-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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"
Expand Down
1 change: 0 additions & 1 deletion apollo-router-core/src/layers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ pub mod cache;
pub mod deduplication;
pub mod forbid_http_get_mutations;
pub mod headers;
pub mod opentracing;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: apollo-router/src/configuration/mod.rs
assertion_line: 645
assertion_line: 474
expression: "&schema"

---
Expand Down Expand Up @@ -235,13 +235,6 @@ expression: "&schema"
}
]
},
"PropagationFormat": {
"type": "string",
"enum": [
"jaeger",
"zipkin_b3"
]
},
"RemoveConfig": {
"oneOf": [
{
Expand Down Expand Up @@ -318,11 +311,6 @@ expression: "&schema"
"required": [
"headers_remove"
]
},
{
"required": [
"opentracing"
]
}
],
"properties": {
Expand All @@ -337,9 +325,6 @@ expression: "&schema"
},
"headers_remove": {
"$ref": "#/definitions/RemoveConfig"
},
"opentracing": {
"$ref": "#/definitions/OpenTracingConfig"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions apollo-router/src/layers/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mod hello;
pub mod opentracing;
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
}
Expand All @@ -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,
}

Expand All @@ -59,7 +57,7 @@ impl<S> Layer<S> for OpenTracingLayer {
}
}

struct OpenTracingService<S> {
pub struct OpenTracingService<S> {
inner: S,
format: PropagationFormat,
}
Expand All @@ -70,7 +68,7 @@ where
{
type Response = S::Response;
type Error = S::Error;
type Future = Instrumented<<S as tower::Service<services::SubgraphRequest>>::Future>;
type Future = Instrumented<<S as tower::Service<SubgraphRequest>>::Future>;

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.inner.poll_ready(cx)
Expand Down
31 changes: 30 additions & 1 deletion apollo-router/src/plugins/reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -159,6 +167,7 @@ impl std::error::Error for ReportingError {}
struct Reporting {
config: Conf,
tx: tokio::sync::mpsc::Sender<SpaceportConfig>,
opentracing_layer: Option<OpenTracingLayer>,
}

#[derive(Debug, Deserialize, JsonSchema)]
Expand All @@ -168,6 +177,8 @@ struct Conf {
pub graph: Option<StudioGraph>,

pub opentelemetry: Option<OpenTelemetry>,

pub opentracing: Option<OpenTracingConfig>,
}

fn studio_graph() -> Option<StudioGraph> {
Expand Down Expand Up @@ -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<SubgraphRequest, SubgraphResponse, BoxError>,
) -> BoxService<SubgraphRequest, SubgraphResponse, BoxError> {
match &self.opentracing_layer {
Some(opentracing_layer) => opentracing_layer.layer(service).boxed(),
BrynCooke marked this conversation as resolved.
Show resolved Hide resolved
None => service,
}
}
}

impl Reporting {
Expand Down