From 41feb15386721b105f73ff4f3141f5bd3665c756 Mon Sep 17 00:00:00 2001 From: Bryan Moffatt Date: Thu, 5 Feb 2026 15:50:01 -0800 Subject: [PATCH 1/3] apply patch add-xray-response maintained by other RICs --- include/aws/lambda-runtime/runtime.h | 22 +++++++++++++++++----- src/runtime.cpp | 6 +++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/include/aws/lambda-runtime/runtime.h b/include/aws/lambda-runtime/runtime.h index 46b8817..0bae23e 100644 --- a/include/aws/lambda-runtime/runtime.h +++ b/include/aws/lambda-runtime/runtime.h @@ -85,6 +85,11 @@ class invocation_response { */ bool m_success; + /** + * The serialized XRay response header. + */ + std::string m_xray_response; + /** * Instantiate an empty response. Used by the static functions 'success' and 'failure' to create a populated * invocation_response @@ -97,10 +102,12 @@ class invocation_response { // To support clients that need to control the entire error response body (e.g. adding a stack trace), this // constructor should be used instead. // Note: adding an overload to invocation_response::failure is not feasible since the parameter types are the same. - invocation_response(std::string const& payload, std::string const& content_type, bool success) - : m_payload(payload), m_content_type(content_type), m_success(success) - { - } + invocation_response(std::string const& payload, std::string const& content_type, bool success, std::string const& xray_response = ""): + m_payload(payload), + m_content_type(content_type), + m_success(success), + m_xray_response(xray_response) + {} /** * Create a successful invocation response with the given payload and content-type. @@ -111,7 +118,7 @@ class invocation_response { * Create a failure response with the given error message and error type. * The content-type is always set to application/json in this case. */ - static invocation_response failure(std::string const& error_message, std::string const& error_type); + static invocation_response failure(std::string const& error_message, std::string const& error_type, std::string const& xray_response = ""); /** * Get the MIME type of the payload. @@ -127,6 +134,11 @@ class invocation_response { * Returns true if the payload and content-type are set. Returns false if the error message and error types are set. */ bool is_success() const { return m_success; } + + /** + * Get the XRay response string. The string isassumed to be UTF-8 encoded. + */ + std::string const& get_xray_response() const { return m_xray_response; } }; struct no_result {}; diff --git a/src/runtime.cpp b/src/runtime.cpp index 1013a19..106ed88 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -347,6 +347,9 @@ runtime::post_outcome runtime::do_post( headers = curl_slist_append(headers, ("content-type: " + handler_response.get_content_type()).c_str()); } + if (!handler_response.get_xray_response().empty()) { + headers = curl_slist_append(headers, ("lambda-runtime-function-xray-error-cause: " + handler_response.get_xray_response()).c_str()); + } headers = curl_slist_append(headers, "Expect:"); headers = curl_slist_append(headers, "transfer-encoding:"); headers = curl_slist_append(headers, m_user_agent_header.c_str()); @@ -521,13 +524,14 @@ invocation_response invocation_response::success(std::string payload, std::strin } AWS_LAMBDA_RUNTIME_API -invocation_response invocation_response::failure(std::string const& error_message, std::string const& error_type) +invocation_response invocation_response::failure(std::string const& error_message, std::string const& error_type, std::string const& xray_response) { invocation_response r; r.m_success = false; r.m_content_type = "application/json"; r.m_payload = R"({"errorMessage":")" + json_escape(error_message) + R"(","errorType":")" + json_escape(error_type) + R"(","stackTrace":[]})"; + r.m_xray_response = xray_response; return r; } From 67cd026a58fd88440e49c2cd9fd12827e93b5ac9 Mon Sep 17 00:00:00 2001 From: Bryan Moffatt Date: Thu, 5 Feb 2026 16:17:15 -0800 Subject: [PATCH 2/3] finch run --rm --entrypoint /bin/sh -v $(pwd):/wee -w /wee ubuntu:24.04 -c "apt-get update && apt-get -y install clang-format && clang-format -i src/runtime.cpp include/aws/lambda-runtime/runtime.h" --- include/aws/lambda-runtime/runtime.h | 23 ++++++++++++++--------- src/runtime.cpp | 8 ++++++-- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/include/aws/lambda-runtime/runtime.h b/include/aws/lambda-runtime/runtime.h index 0bae23e..d596161 100644 --- a/include/aws/lambda-runtime/runtime.h +++ b/include/aws/lambda-runtime/runtime.h @@ -102,12 +102,14 @@ class invocation_response { // To support clients that need to control the entire error response body (e.g. adding a stack trace), this // constructor should be used instead. // Note: adding an overload to invocation_response::failure is not feasible since the parameter types are the same. - invocation_response(std::string const& payload, std::string const& content_type, bool success, std::string const& xray_response = ""): - m_payload(payload), - m_content_type(content_type), - m_success(success), - m_xray_response(xray_response) - {} + invocation_response( + std::string const& payload, + std::string const& content_type, + bool success, + std::string const& xray_response = "") + : m_payload(payload), m_content_type(content_type), m_success(success), m_xray_response(xray_response) + { + } /** * Create a successful invocation response with the given payload and content-type. @@ -118,7 +120,10 @@ class invocation_response { * Create a failure response with the given error message and error type. * The content-type is always set to application/json in this case. */ - static invocation_response failure(std::string const& error_message, std::string const& error_type, std::string const& xray_response = ""); + static invocation_response failure( + std::string const& error_message, + std::string const& error_type, + std::string const& xray_response = ""); /** * Get the MIME type of the payload. @@ -136,8 +141,8 @@ class invocation_response { bool is_success() const { return m_success; } /** - * Get the XRay response string. The string isassumed to be UTF-8 encoded. - */ + * Get the XRay response string. The string isassumed to be UTF-8 encoded. + */ std::string const& get_xray_response() const { return m_xray_response; } }; diff --git a/src/runtime.cpp b/src/runtime.cpp index 106ed88..e77a3bb 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -348,7 +348,8 @@ runtime::post_outcome runtime::do_post( } if (!handler_response.get_xray_response().empty()) { - headers = curl_slist_append(headers, ("lambda-runtime-function-xray-error-cause: " + handler_response.get_xray_response()).c_str()); + headers = curl_slist_append( + headers, ("lambda-runtime-function-xray-error-cause: " + handler_response.get_xray_response()).c_str()); } headers = curl_slist_append(headers, "Expect:"); headers = curl_slist_append(headers, "transfer-encoding:"); @@ -524,7 +525,10 @@ invocation_response invocation_response::success(std::string payload, std::strin } AWS_LAMBDA_RUNTIME_API -invocation_response invocation_response::failure(std::string const& error_message, std::string const& error_type, std::string const& xray_response) +invocation_response invocation_response::failure( + std::string const& error_message, + std::string const& error_type, + std::string const& xray_response) { invocation_response r; r.m_success = false; From 4d27155f11faea095b60a1a1b93679be2121c8a9 Mon Sep 17 00:00:00 2001 From: Bryan Moffatt Date: Fri, 6 Feb 2026 09:08:54 -0800 Subject: [PATCH 3/3] Add an overload instead of a default argument, --- include/aws/lambda-runtime/runtime.h | 11 +++++++++-- src/runtime.cpp | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/aws/lambda-runtime/runtime.h b/include/aws/lambda-runtime/runtime.h index d596161..4d62789 100644 --- a/include/aws/lambda-runtime/runtime.h +++ b/include/aws/lambda-runtime/runtime.h @@ -102,11 +102,16 @@ class invocation_response { // To support clients that need to control the entire error response body (e.g. adding a stack trace), this // constructor should be used instead. // Note: adding an overload to invocation_response::failure is not feasible since the parameter types are the same. + invocation_response(std::string const& payload, std::string const& content_type, bool success) + : m_payload(payload), m_content_type(content_type), m_success(success) + { + } + invocation_response( std::string const& payload, std::string const& content_type, bool success, - std::string const& xray_response = "") + std::string const& xray_response) : m_payload(payload), m_content_type(content_type), m_success(success), m_xray_response(xray_response) { } @@ -120,10 +125,12 @@ class invocation_response { * Create a failure response with the given error message and error type. * The content-type is always set to application/json in this case. */ + static invocation_response failure(std::string const& error_message, std::string const& error_type); + static invocation_response failure( std::string const& error_message, std::string const& error_type, - std::string const& xray_response = ""); + std::string const& xray_response); /** * Get the MIME type of the payload. diff --git a/src/runtime.cpp b/src/runtime.cpp index e77a3bb..2a8825c 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -524,6 +524,12 @@ invocation_response invocation_response::success(std::string payload, std::strin return r; } +AWS_LAMBDA_RUNTIME_API +invocation_response invocation_response::failure(std::string const& error_message, std::string const& error_type) +{ + return failure(error_message, error_type, ""); +} + AWS_LAMBDA_RUNTIME_API invocation_response invocation_response::failure( std::string const& error_message,