From 421488ef491b66e8f7621b8c22d96e23e9137825 Mon Sep 17 00:00:00 2001 From: david-perez Date: Tue, 4 Apr 2023 09:58:29 +0200 Subject: [PATCH] Error log server response rejections (#2524) All `ResponseRejection`s are errors; the service owners are to blame. So we centrally log them here to let them know. --- .../protocols/ServerHttpBoundProtocolGenerator.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt index 1cf2debcba..6bf8dba7ba 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt @@ -135,6 +135,7 @@ class ServerHttpBoundProtocolTraitImplGenerator( "ResponseRejection" to protocol.responseRejection(runtimeConfig), "PinProjectLite" to ServerCargoDependency.PinProjectLite.toType(), "http" to RuntimeType.Http, + "Tracing" to RuntimeType.Tracing, ) fun generateTraitImpls(operationWriter: RustWriter, operationShape: OperationShape, customizations: List) { @@ -251,17 +252,22 @@ class ServerHttpBoundProtocolTraitImplGenerator( // Implement `into_response` for output types. val errorSymbol = symbolProvider.symbolForOperationError(operationShape) + // All `ResponseRejection`s are errors; the service owners are to blame. So we centrally log them here + // to let them know. rustTemplate( """ impl #{SmithyHttpServer}::response::IntoResponse<#{Marker}> for #{O} { fn into_response(self) -> #{SmithyHttpServer}::response::Response { match #{serialize_response}(self) { Ok(response) => response, - Err(e) => #{SmithyHttpServer}::response::IntoResponse::<#{Marker}>::into_response(#{RuntimeError}::from(e)) + Err(e) => { + #{Tracing}::error!(error = %e, "failed to serialize response"); + #{SmithyHttpServer}::response::IntoResponse::<#{Marker}>::into_response(#{RuntimeError}::from(e)) + } } } } - """.trimIndent(), + """, *codegenScope, "O" to outputSymbol, "Marker" to protocol.markerStruct(), @@ -278,7 +284,10 @@ class ServerHttpBoundProtocolTraitImplGenerator( response.extensions_mut().insert(#{SmithyHttpServer}::extension::ModeledErrorExtension::new(self.name())); response }, - Err(e) => #{SmithyHttpServer}::response::IntoResponse::<#{Marker}>::into_response(#{RuntimeError}::from(e)) + Err(e) => { + #{Tracing}::error!(error = %e, "failed to serialize response"); + #{SmithyHttpServer}::response::IntoResponse::<#{Marker}>::into_response(#{RuntimeError}::from(e)) + } } } }