-
Notifications
You must be signed in to change notification settings - Fork 7
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
Implement trace propagation #49
Changes from 4 commits
a6155bf
b9f223e
4a17570
44bdc72
8babe0c
5cfd7fb
8410678
6ef264b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
dev: | ||
cargo watch \ | ||
-x 'run --bin ndc_hub_example \ | ||
-- serve --configuration <(echo 'null') \ | ||
--otlp-endpoint http://localhost:4317' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ use crate::{ | |
connector::{Connector, InvalidRange, SchemaError, UpdateConfigurationError}, | ||
routes, | ||
}; | ||
|
||
use async_trait::async_trait; | ||
use axum::{ | ||
body::Body, | ||
|
@@ -15,7 +14,10 @@ use axum::{ | |
routing::{get, post}, | ||
Json, Router, | ||
}; | ||
use opentelemetry_http::HeaderExtractor; | ||
use tower_http::trace::MakeSpan; | ||
use tower_http::validate_request::ValidateRequestHeaderLayer; | ||
use tracing::Span; | ||
|
||
use clap::{Parser, Subcommand}; | ||
use ndc_client::models::{ | ||
|
@@ -331,10 +333,7 @@ where | |
}); | ||
|
||
router | ||
.layer( | ||
TraceLayer::new_for_http() | ||
.make_span_with(DefaultMakeSpan::default().level(Level::INFO)), | ||
) | ||
.layer(TraceLayer::new_for_http().make_span_with(PropagateParentTraces)) | ||
.layer(ValidateRequestHeaderLayer::custom( | ||
move |request: &mut Request<Body>| { | ||
// Validate the request | ||
|
@@ -359,6 +358,19 @@ where | |
)) | ||
} | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
pub struct PropagateParentTraces; | ||
|
||
impl<B> MakeSpan<B> for PropagateParentTraces { | ||
fn make_span(&mut self, req: &Request<B>) -> Span { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This grabs the W3 trace header (ie, |
||
let parent_cx = global::get_text_map_propagator(|propagator| { | ||
propagator.extract(&HeaderExtractor(req.headers())) | ||
}); | ||
let _cx_guard = parent_cx.attach(); | ||
|
||
tracing::info_span!("Request") | ||
} | ||
} | ||
pub fn create_v2_router<C: Connector + Clone + 'static>( | ||
state: ServerState<C>, | ||
service_token_secret: Option<String>, | ||
|
@@ -374,10 +386,7 @@ where | |
// .route("/mutation", post(v2_compat::post_mutation::<C>)) | ||
// .route("/raw", post(v2_compat::post_raw::<C>)) | ||
.route("/explain", post(v2_compat::post_explain::<C>)) | ||
.layer( | ||
TraceLayer::new_for_http() | ||
.make_span_with(DefaultMakeSpan::default().level(Level::INFO)), | ||
) | ||
.layer(TraceLayer::new_for_http().make_span_with(PropagateParentTraces)) | ||
.layer(ValidateRequestHeaderLayer::custom( | ||
move |request: &mut Request<Body>| { | ||
let provided_service_token_secret = request | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this
make_span_with
means we default to the defaultTraceLayer
implementation, which makes all error responses into error traces rather than alwaysINFO
, solving #43Info: https://docs.rs/tower-http/latest/tower_http/trace/struct.TraceLayer.html#method.new_for_http