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 tracing support #720

Open
wants to merge 56 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
e0f7eb5
Add tracing support
mihai-dinculescu Jul 25, 2020
419520d
Merge branch 'master' into add_tracing_support
LegNeato Jul 28, 2020
c1f9e5f
Merge branch 'master' into add_tracing_support
LegNeato Jul 29, 2020
753c80f
Rocket can now compile on stable
LegNeato Jul 28, 2020
c599bae
Remove `boxed` in favor of `pin`.
LegNeato Jul 29, 2020
b556934
Add tracing support example
LegNeato Jul 29, 2020
0134da3
Add some coarse execution tracing
LegNeato Jul 29, 2020
5c888a8
Remove old comment / docs
LegNeato Jul 29, 2020
ef2da9b
Merge branch 'master' into add_tracing_support
LegNeato Jul 29, 2020
01b3453
Fix book tests
LegNeato Jul 29, 2020
7ac7304
fix up some imports
LegNeato Jul 29, 2020
06687dd
Add back subscriber Cargo.toml instructions
LegNeato Jul 29, 2020
697a743
Change trace errors to trace
mihai-dinculescu Jul 29, 2020
f2977d5
Tracing unit tests
mihai-dinculescu Jul 29, 2020
6c3654c
Tracing unit tests names
mihai-dinculescu Jul 29, 2020
7f746de
Revert "Rocket can now compile on stable"
LegNeato Jul 29, 2020
64cad08
Merge branch 'master' into add_tracing_support
LegNeato Jul 30, 2020
d7acba9
Merge branch 'master' into add_tracing_support
LegNeato Aug 10, 2020
88dc9c4
Fix tracing spans
LegNeato Aug 14, 2020
8a2f6ec
Do not include trailing newline on the last error
LegNeato Aug 14, 2020
83fd44d
Standard tracing labels on snake_case
LegNeato Aug 14, 2020
c92dd87
Add a validation error case to the tracing example
LegNeato Aug 14, 2020
64d8e11
Use $crate everywhere
LegNeato Aug 15, 2020
cdbc0ce
Add other levels to span macros
LegNeato Aug 15, 2020
65ab688
Merge branch 'master' into add_tracing_support
LegNeato Aug 19, 2020
6cf48d9
Merge branch 'master' into add_tracing_support
LegNeato Aug 21, 2020
5f8a4ca
Merge branch 'master' into add_tracing_support
LegNeato Sep 3, 2020
ae1054e
Merge branch 'master' into add_tracing_support
LegNeato Oct 3, 2020
5938345
Use the released tracing crate
mihai-dinculescu Oct 3, 2020
8bc07f6
Fix email address
LegNeato Oct 29, 2020
82497d3
Standardize on snake case for tracing
LegNeato Oct 29, 2020
79102a3
Add tracing support
mihai-dinculescu Jul 25, 2020
6a16cf8
Rocket can now compile on stable
LegNeato Jul 28, 2020
11bb5e2
Add tracing support example
LegNeato Jul 29, 2020
57ecb56
Add some coarse execution tracing
LegNeato Jul 29, 2020
cff6678
Remove old comment / docs
LegNeato Jul 29, 2020
cb3ee27
Fix book tests
LegNeato Jul 29, 2020
0d52c50
fix up some imports
LegNeato Jul 29, 2020
7f24509
Add back subscriber Cargo.toml instructions
LegNeato Jul 29, 2020
cb7ab0c
Change trace errors to trace
mihai-dinculescu Jul 29, 2020
7b02ccc
Tracing unit tests
mihai-dinculescu Jul 29, 2020
4000f1e
Tracing unit tests names
mihai-dinculescu Jul 29, 2020
e968c4b
Revert "Rocket can now compile on stable"
LegNeato Jul 29, 2020
58fed76
Fix tracing spans
LegNeato Aug 14, 2020
7b5ad7e
Do not include trailing newline on the last error
LegNeato Aug 14, 2020
c34a1c2
Standard tracing labels on snake_case
LegNeato Aug 14, 2020
26407e2
Add a validation error case to the tracing example
LegNeato Aug 14, 2020
94279d1
Use $crate everywhere
LegNeato Aug 15, 2020
bf35077
Add other levels to span macros
LegNeato Aug 15, 2020
2365016
Use the released tracing crate
mihai-dinculescu Oct 3, 2020
ca744b5
Fix email address
LegNeato Oct 29, 2020
62acd3f
Standardize on snake case for tracing
LegNeato Oct 29, 2020
4d7797a
Merge master
LegNeato Oct 29, 2020
72a28d4
Remove rustfmt option causing breakage
LegNeato Oct 29, 2020
2977b1f
Remove subscription helper mod
LegNeato Oct 29, 2020
264030f
Merge branch 'master' into add_tracing_support
LegNeato Nov 13, 2020
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: 2 additions & 0 deletions docs/book/content/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
- [Hyper](servers/hyper.md)
- [Third Party Integrations](servers/third-party.md)

- [Tracing](tracing/index.md)

- [Advanced Topics](advanced/index.md)

- [Introspection](advanced/introspection.md)
Expand Down
38 changes: 38 additions & 0 deletions docs/book/content/tracing/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Tracing

Juniper relies on the [tracing](https://crates.io/crates/tracing) crate for instrumentation.

!FILENAME Cargo.toml

```toml
[dependencies]
tracing = "0.1.17"
tracing-subscriber = "0.2.9"
tracing-log = "0.1.1"
```

## Usage

```rust
# extern crate tracing;
# extern crate tracing_subscriber;
# extern crate tracing_log;
fn main() {
// compatibility with the log crate (unstable)
// converts all log records into tracing events
tracing_log::LogTracer::init().expect("LogTracer init failed");

// a builder for `FmtSubscriber`.
let subscriber = tracing_subscriber::FmtSubscriber::builder()
// all spans/events with a level higher than TRACE
// (e.g, debug, info, warn, etc.) will be written to stdout.
.with_max_level(tracing::Level::TRACE)
// completes the builder.
.finish();

tracing::subscriber::set_global_default(subscriber)
.expect("Setting default tracing subscriber failed");

// ...
}
```
4 changes: 4 additions & 0 deletions docs/book/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ skeptic = "0.13"
serde_json = "1.0.39"
uuid = "0.8"

tracing = "0.1.17"
tracing-subscriber = "0.2.9"
tracing-log = "0.1.1"

[build-dependencies]
skeptic = "0.13"

Expand Down
2 changes: 2 additions & 0 deletions juniper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ url = { version = "2", optional = true }
uuid = { version = "0.8", optional = true }
graphql-parser = {version = "0.3.0", optional = true }

tracing = {version = "0.1.17", optional = true }

[dev-dependencies]
bencher = "0.1.2"
serde_json = { version = "1.0.2" }
Expand Down
25 changes: 20 additions & 5 deletions juniper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ where
let errors = validate_input_values(variables, operation, &root_node.schema);

if !errors.is_empty() {
return Err(GraphQLError::ValidationError(errors));
let gql_error = GraphQLError::ValidationError(errors);
__juniper_trace_error!("GraphQLError: {:?}", gql_error);

return Err(gql_error);
}
}

Expand Down Expand Up @@ -293,7 +296,10 @@ where

let errors = ctx.into_errors();
if !errors.is_empty() {
return Err(GraphQLError::ValidationError(errors));
let gql_error = GraphQLError::ValidationError(errors);
__juniper_trace_error!("GraphQLError: {:?}", gql_error);
mihai-dinculescu marked this conversation as resolved.
Show resolved Hide resolved

return Err(gql_error);
}
}

Expand All @@ -303,7 +309,10 @@ where
let errors = validate_input_values(variables, operation, &root_node.schema);

if !errors.is_empty() {
return Err(GraphQLError::ValidationError(errors));
let gql_error = GraphQLError::ValidationError(errors);
__juniper_trace_error!("GraphQLError: {:?}", gql_error);

return Err(gql_error);
}
}

Expand Down Expand Up @@ -338,7 +347,10 @@ where

let errors = ctx.into_errors();
if !errors.is_empty() {
return Err(GraphQLError::ValidationError(errors));
let gql_error = GraphQLError::ValidationError(errors);
__juniper_trace_error!("GraphQLError: {:?}", gql_error);

return Err(gql_error);
}
}

Expand All @@ -348,7 +360,10 @@ where
let errors = validate_input_values(&variables, operation, &root_node.schema);

if !errors.is_empty() {
return Err(GraphQLError::ValidationError(errors));
let gql_error = GraphQLError::ValidationError(errors);
__juniper_trace_error!("GraphQLError: {:?}", gql_error);

return Err(gql_error);
}
}

Expand Down
2 changes: 2 additions & 0 deletions juniper/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ mod interface;
mod tests;

pub mod subscription_helpers;

mod tracing;
48 changes: 48 additions & 0 deletions juniper/src/macros/tracing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#[doc(hidden)]
#[macro_export]
macro_rules! __juniper_trace_internal {
($trace_type:ident; $($element:expr),*) => {{
#[cfg(feature = "tracing")]
tracing::$trace_type!($($element),*);
}};
}

#[doc(hidden)]
#[macro_export]
macro_rules! __juniper_trace {
($($element:expr),*) => {{
$crate::__juniper_trace_internal!(trace; $($element),*)
}};
}

#[doc(hidden)]
#[macro_export]
macro_rules! __juniper_trace_debug {
($($element:expr),*) => {{
$crate::__juniper_trace_internal!(debug; $($element),*)
}};
}

#[doc(hidden)]
#[macro_export]
macro_rules! __juniper_trace_info {
($($element:expr),*) => {{
$crate::__juniper_trace_internal!(info; $($element),*)
}};
}

#[doc(hidden)]
#[macro_export]
macro_rules! __juniper_trace_warn {
($($element:expr),*) => {{
$crate::__juniper_trace_internal!(warn; $($element),*)
}};
}

#[doc(hidden)]
#[macro_export]
macro_rules! __juniper_trace_error {
($($element:expr),*) => {{
$crate::__juniper_trace_internal!(error; $($element),*)
}};
}