Comments (6)
I wrote a variant of https://docs.rs/tracing-test/0.1.0/tracing_test/ and then switched to it at a former company, I'd love to have a stab at this, and try to provide us with nice regression test primitives
from router.
that would be useful, I just saw a regression while debugging #180, where trace ids change in the middle of a query
from router.
#276 Is a first step towards integration testing, we now have a Tree like structure that represents the spans we're working on, here's a simple example:
this code:
async fn main() {
let res = do_stuff().await;
assert_eq!(res, 104);
}
#[tracing::instrument(name = "do_stuff", level = "info")]
async fn do_stuff() -> u8 {
let number = do_stuff_2(42).await;
tokio::task::spawn_blocking(|| async { tracing::warn!("in a separate context!") })
.await
.unwrap()
.await;
tracing::info!("here i am!");
tracing::info!(number);
number * 2
}
#[tracing::instrument(
name = "do_stuff2",
target = "my_crate::an_other_target",
level = "info"
)]
async fn do_stuff_2(number: u8) -> u8 {
tracing::info!("here i am again!");
number + 10
}
outputs this structure:
{
"id": 0,
"target": "root",
"records": [
[],
null
],
"children": {
"integration_tests::do_stuff": {
"id": 1,
"target": "integration_tests::do_stuff",
"records": [
[],
{
"name": "do_stuff",
"target": "integration_tests",
"level": "INFO",
"module_path": "integration_tests",
"fields": {
"names": []
}
}
],
"children": {
"my_crate::an_other_target::do_stuff2": {
"id": 2,
"target": "my_crate::an_other_target::do_stuff2",
"records": [
[
[
"number",
{
"Value": 42
}
]
],
{
"name": "do_stuff2",
"target": "my_crate::an_other_target",
"level": "INFO",
"module_path": "integration_tests",
"fields": {
"names": [
"number"
]
}
}
],
"children": {}
}
}
}
}
}
The next steps for me would be:
- add span IDs or something to the keys, so several calls are displayed
- update our code with the latest ADR best practices (especially instrument(skip_all)) and generate snapshots based on this.
- generate snapshots
- add functions that allow us to assert the spans we get "kinda" match a shape, because we probably don't care what the span contents exactly look like, but we do care that a specific span has a specific field / value, and that spans are nested the right way.
This should cover most of our use cases, and open up for regression testing, and maybe let this bit of code live somewhere else, maybe a separate crate eventually?
from router.
I still need to flesh things out a bit, but this pr turns this:
#[test_span(tokio::test)]
async fn async_tracing_macro_works() {
let res = do_stuff().await;
assert_eq!(res, 104);
let res2 = do_stuff().await;
assert_eq!(res2, 104);
let logs = get_logs();
assert!(logs.contains_message("here i am!"));
assert!(logs.contains_value("number", RecordedValue::Value(52.into())));
assert!(logs.contains_message("in a separate context!"));
insta::assert_json_snapshot!(logs);
insta::assert_json_snapshot!(get_span());
}
into logs and spans that are ready to be snapshotted 📸
Here's what it looks like on a basic router request.
Team how do we feel about this? Would this be a good first step, or is it a terrible idea and we should use an other approach?
from router.
looks great! Why are the logs separated? When looking at traces in jaeger, the logs are attached to spans, is it possible to do it here too?
from router.
Oh indeed, I think we can! Lemme check
EDIT: I d have to make sure log events always apply to the current span, but I can definitely test that!
from router.
Related Issues (20)
- Create integration test for experimental_response_trace_id
- Document Context keys
- Add a metric tracking GraphQL errors
- Allow setting metric attributes from a context sub key HOT 2
- [Rhai] Allow logging to be disabled for specific thrown messages/statuses
- Logs sent to Datadog do not have `dd.trace_id` in a location that allows correlation
- Feature Request: Origin and Method Mirroring in CorsLayer
- Helm chart - cannot unset values.router.configuration safely
- Ability to modify request post parsing, but pre-supergraph service HOT 3
- Using `@defer` in a Subscription returns `router-bridge` error vs. nicer user-facing erorr
- tracing otlp exporter endpoint configuration for http doesn't append the right path
- Allow fully disabling response compression HOT 2
- Document `apollo_router_span` and all span metrics as deprecated in docs
- Tracing service name reported as `unknown_service`
- Schema-based authN/Z data fencing on responses
- Otel metric and trace scope should be consistent
- Query planner metrics HOT 1
- AuthZ plugin does not strip arguments, causing validation errors HOT 1
- Add google log format
- More accurately nest spans in tracing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from router.