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

feat: disable trace_layer on_failure, only emit error event for 500s #1608

Merged
merged 1 commit into from
Feb 2, 2024
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
11 changes: 9 additions & 2 deletions auth/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ impl IntoResponse for Error {
let code = match self {
Error::Forbidden => StatusCode::FORBIDDEN,
Error::Unauthorized | Error::KeyMissing => StatusCode::UNAUTHORIZED,
Error::Database(_) | Error::UserNotFound => StatusCode::NOT_FOUND,
_ => StatusCode::INTERNAL_SERVER_ERROR,
Error::Database(sqlx::Error::RowNotFound) | Error::UserNotFound => {
StatusCode::NOT_FOUND
}
_ => {
// We only want to emit error events for internal errors, not e.g. 404s.
tracing::error!(error = %self, "control plane request error");

StatusCode::INTERNAL_SERVER_ERROR
}
};

ApiError {
Expand Down
6 changes: 5 additions & 1 deletion common/src/backends/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use axum::http::{request::Parts, Request, Response};
use opentelemetry::global;
use opentelemetry_http::HeaderExtractor;
use tower_http::classify::{ServerErrorsAsFailures, SharedClassifier};
use tower_http::trace::DefaultOnRequest;
use tower_http::trace::{DefaultOnBodyChunk, DefaultOnEos, DefaultOnRequest};
use tracing::{debug, Span};
use tracing_opentelemetry::OpenTelemetrySpanExt;

Expand Down Expand Up @@ -83,10 +83,14 @@ impl<MakeSpan: tower_http::trace::MakeSpan<Body> + MakeSpanBuilder> TraceLayer<M
MakeSpan,
DefaultOnRequest,
OnResponseStatusCode,
DefaultOnBodyChunk,
DefaultOnEos,
(),
> {
tower_http::trace::TraceLayer::new_for_http()
.make_span_with(MakeSpan::new(self.fn_span))
.on_response(OnResponseStatusCode)
.on_failure(())
}
}

Expand Down
12 changes: 9 additions & 3 deletions deployer/src/handlers/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ impl Serialize for Error {

impl IntoResponse for Error {
fn into_response(self) -> Response {
error!(error = &self as &dyn std::error::Error, "request error");

let code = match self {
Error::NotFound(_) => StatusCode::NOT_FOUND,
_ => StatusCode::INTERNAL_SERVER_ERROR,
_ => {
// We only want to emit error events for internal errors, not e.g. 404s.
error!(
error = &self as &dyn std::error::Error,
"control plane request error"
);

StatusCode::INTERNAL_SERVER_ERROR
}
};

ApiError {
Expand Down
7 changes: 5 additions & 2 deletions gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,13 @@ impl From<AcmeClientError> for Error {

impl IntoResponse for Error {
fn into_response(self) -> Response {
error!(error = %self, "request had an error");

let error: ApiError = self.kind.into();

if error.status_code >= 500 {
// We only want to emit error events for internal errors, not e.g. 404s.
error!(error = error.message, "control plane request error");
}

error.into_response()
}
}
Expand Down