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

Panics now output to logs #1001

Merged
merged 2 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Cargo.lock

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

7 changes: 5 additions & 2 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ In addition, the following command line flags have changed:
* `--apollo-schema-config-delivery-endpoint` -> `--apollo-uplink-url`
* `--apollo-schema-poll-interval` -> `--apollo-uplink-poll-interval`

### Rhai scripts should be able to do more things (like rust plugins) [PR #971](https://github.com/apollographql/router/pull/971)
### Add configuration to declare your own GraphQL endpoint [PR #976](https://github.com/apollographql/router/pull/976)
You are now able to declare your own GraphQL endpoint in the config like this:
```yaml
Expand All @@ -56,6 +55,10 @@ This is a re-working of our rhai scripting support. The intent is to make writin

## 🚀 Features ( :rocket: )

### Panics now output to logs [PR #1001](https://github.com/apollographql/router/pull/1001)
Previously panics would get swallowed. Now they are output to the logs.
Setting `RUST_BACKTRACE=1` or `RUST_BACKTRACE=full` enables the full backtrace to also be logged.

### Apollo studio Usage Reporting [PR #898](https://github.com/apollographql/router/pull/898)
If you have [enabled telemetry](https://www.apollographql.com/docs/router/configuration/apollo-telemetry#enabling-usage-reporting), you can now see field usage reporting for your queries by heading to the Apollo studio fields section.
Here is more information on how to [set up telemetry](https://www.apollographql.com/docs/studio/metrics/usage-reporting#pushing-metrics-from-apollo-server) and [Field Usage](https://www.apollographql.com/docs/studio/metrics/field-usage)
Expand Down Expand Up @@ -109,4 +112,4 @@ Rather than pointing to our `LICENSE` file, we now use the `Elastic-2.0` SPDX li
## 📚 Documentation ( :books: )

### Add license notice to first line of Router output [PR #986](https://github.com/apollographql/router/pull/986)
Display the [ELv2 license](https://www.elastic.co/blog/elastic-license-v2) at the start of the Router
Display the [ELv2 license](https://www.elastic.co/blog/elastic-license-v2) at the start of the Router
1 change: 1 addition & 0 deletions apollo-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ apollo-router-core = { path = "../apollo-router-core" }
apollo-uplink = { path = "../uplink" }
async-trait = "0.1.53"
atty = "0.2.14"
backtrace = "0.3.65"
buildstructor = "0.1.12"
bytes = "1.1.0"
clap = { version = "3.1.3", default-features = false, features = ["env", "derive", "std"] }
Expand Down
19 changes: 19 additions & 0 deletions apollo-router/src/executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ pub async fn rt_main() -> Result<()> {
let schema = match (opt.supergraph_path, opt.apollo_key) {
(Some(supergraph_path), _) => {
tracing::info!("{apollo_router_msg}");
setup_panic_handler();

let supergraph_path = if supergraph_path.is_relative() {
current_directory.join(supergraph_path)
} else {
Expand Down Expand Up @@ -276,6 +278,23 @@ pub async fn rt_main() -> Result<()> {
Ok(())
}

fn setup_panic_handler() {
// Redirect panics to the logs.
let backtrace_env = std::env!("RUST_BACKTRACE");
let show_backtraces = backtrace_env == "1" || backtrace_env == "full";
if show_backtraces {
tracing::warn!("RUST_BACKTRACE={} detected. This use useful for diagnostics but will have a performance impact and may leak sensitive information", backtrace_env);
}
std::panic::set_hook(Box::new(move |e| {
if show_backtraces {
let backtrace = backtrace::Backtrace::new();
tracing::error!("{}\n{:?}", e, backtrace)
} else {
tracing::error!("{}", e)
}
}));
}

fn copy_args_to_env() {
// Copy all the args to env.
// This way, Clap is still responsible for the definitive view of what the current options are.
Expand Down
4 changes: 4 additions & 0 deletions apollo-router/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ async fn setup_router_and_registry() -> (
BoxCloneService<RouterRequest, RouterResponse, BoxError>,
CountingServiceRegistry,
) {
std::panic::set_hook(Box::new(|e| {
let backtrace = backtrace::Backtrace::new();
tracing::error!("{}\n{:?}", e, backtrace)
}));
let schema: Arc<Schema> =
Arc::new(include_str!("fixtures/supergraph.graphql").parse().unwrap());
let counting_registry = CountingServiceRegistry::new();
Expand Down