-
Notifications
You must be signed in to change notification settings - Fork 273
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
Telemetry enhancements #850
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
cc3a570
Add docs public to git ignore.
00726e8
Move the apollo config, update changelog
fcd4c69
Split configuration for Apollo so that tracing can go in the tracing …
3e20545
Introduce instrument layer
bec20dc
Print errors if config could not be reloaded.
2dda2aa
Update test config files
48675e0
Integration test for jaeger
94ab1d3
Fix build for windows and osx.
8efc39b
Lint + take in feedback around operation name
0be78a5
Add logic to kill node processes on test termination
BrynCooke 055df22
Remove all piping from external commands, it's not safe unless we rea…
23ba2f7
Revert operation suggestion, operation should be extracted before the…
93ba22e
Take in feedback
28a795a
Removed instructions for developing without docker compose. It is onl…
8113eed
Router span name moved to constant.
68c2c6b
Update NEXT_CHANGELOG.md
BrynCooke ddca621
Rename QueryCache#parse_query back to `get`.
ef6b533
Extended integration test to also do hot reloading. Had to do some wo…
0f5dd0f
Simplify flush on drop for trace provider.
bf40b73
Added some minimal documentation.
5017c68
Fix compile error after rebase.
4b15150
Fix doc error.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
//! Instrumentation layer that allows services to be wrapped in a span. | ||
//! | ||
//! See [`Layer`] and [`Service`] for more details. | ||
//! | ||
//! Using ServiceBuilderExt: | ||
//! ```rust | ||
//! # use tower::ServiceBuilder; | ||
//! # use tower_service::Service; | ||
//! # use tracing::info_span; | ||
//! # use apollo_router_core::ServiceBuilderExt; | ||
//! # fn test<T>(service: impl Service<T>) { | ||
//! let instrumented = ServiceBuilder::new() | ||
//! .instrument(|_request| info_span!("query_planning")) | ||
//! .service(service); | ||
//! # } | ||
//! ``` | ||
//! Now calls to the wrapped service will be wrapped in a span. You can attach attributes to the span from the request. | ||
//! | ||
|
||
use futures::future::BoxFuture; | ||
use futures::FutureExt; | ||
use std::marker::PhantomData; | ||
use std::task::{Context, Poll}; | ||
use tower::Layer; | ||
use tower_service::Service; | ||
use tracing::Instrument; | ||
|
||
/// [`Layer`] for instrumentation. | ||
pub struct InstrumentLayer<F, Request> | ||
where | ||
F: Fn(&Request) -> tracing::Span, | ||
{ | ||
span_fn: F, | ||
phantom: PhantomData<Request>, | ||
} | ||
|
||
impl<F, Request> InstrumentLayer<F, Request> | ||
where | ||
F: Fn(&Request) -> tracing::Span, | ||
{ | ||
pub fn new(span_fn: F) -> InstrumentLayer<F, Request> { | ||
Self { | ||
span_fn, | ||
phantom: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
impl<F, S, Request> Layer<S> for InstrumentLayer<F, Request> | ||
where | ||
S: Service<Request>, | ||
F: Fn(&Request) -> tracing::Span + Clone, | ||
{ | ||
type Service = InstrumentService<F, S, Request>; | ||
|
||
fn layer(&self, inner: S) -> Self::Service { | ||
InstrumentService { | ||
inner, | ||
span_fn: self.span_fn.clone(), | ||
phantom: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
/// [`Service`] for instrumentation. | ||
pub struct InstrumentService<F, S, Request> | ||
where | ||
S: Service<Request>, | ||
F: Fn(&Request) -> tracing::Span, | ||
{ | ||
inner: S, | ||
span_fn: F, | ||
phantom: PhantomData<Request>, | ||
} | ||
|
||
impl<F, S, Request> Service<Request> for InstrumentService<F, S, Request> | ||
where | ||
F: Fn(&Request) -> tracing::Span, | ||
S: Service<Request>, | ||
<S as Service<Request>>::Future: Send + 'static, | ||
{ | ||
type Response = S::Response; | ||
type Error = S::Error; | ||
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>; | ||
|
||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
self.inner.poll_ready(cx) | ||
} | ||
|
||
fn call(&mut self, req: Request) -> Self::Future { | ||
let span = (self.span_fn)(&req); | ||
self.inner.call(req).instrument(span).boxed() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
After the plugin utils etc stuff merges, you'll see the minimal style of documentation that is required. You can lift some of the documentation from that PR and use it to document the new components (such as this instrument layer/service) that you are adding.
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.
I've added some minimal docs, I'm happy to revisit in a larger docs effort.