Skip to content

Commit 41feb15

Browse files
committed
apply patch add-xray-response maintained by other RICs
1 parent d89a26a commit 41feb15

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

include/aws/lambda-runtime/runtime.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ class invocation_response {
8585
*/
8686
bool m_success;
8787

88+
/**
89+
* The serialized XRay response header.
90+
*/
91+
std::string m_xray_response;
92+
8893
/**
8994
* Instantiate an empty response. Used by the static functions 'success' and 'failure' to create a populated
9095
* invocation_response
@@ -97,10 +102,12 @@ class invocation_response {
97102
// To support clients that need to control the entire error response body (e.g. adding a stack trace), this
98103
// constructor should be used instead.
99104
// Note: adding an overload to invocation_response::failure is not feasible since the parameter types are the same.
100-
invocation_response(std::string const& payload, std::string const& content_type, bool success)
101-
: m_payload(payload), m_content_type(content_type), m_success(success)
102-
{
103-
}
105+
invocation_response(std::string const& payload, std::string const& content_type, bool success, std::string const& xray_response = ""):
106+
m_payload(payload),
107+
m_content_type(content_type),
108+
m_success(success),
109+
m_xray_response(xray_response)
110+
{}
104111

105112
/**
106113
* Create a successful invocation response with the given payload and content-type.
@@ -111,7 +118,7 @@ class invocation_response {
111118
* Create a failure response with the given error message and error type.
112119
* The content-type is always set to application/json in this case.
113120
*/
114-
static invocation_response failure(std::string const& error_message, std::string const& error_type);
121+
static invocation_response failure(std::string const& error_message, std::string const& error_type, std::string const& xray_response = "");
115122

116123
/**
117124
* Get the MIME type of the payload.
@@ -127,6 +134,11 @@ class invocation_response {
127134
* Returns true if the payload and content-type are set. Returns false if the error message and error types are set.
128135
*/
129136
bool is_success() const { return m_success; }
137+
138+
/**
139+
* Get the XRay response string. The string isassumed to be UTF-8 encoded.
140+
*/
141+
std::string const& get_xray_response() const { return m_xray_response; }
130142
};
131143

132144
struct no_result {};

src/runtime.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ runtime::post_outcome runtime::do_post(
347347
headers = curl_slist_append(headers, ("content-type: " + handler_response.get_content_type()).c_str());
348348
}
349349

350+
if (!handler_response.get_xray_response().empty()) {
351+
headers = curl_slist_append(headers, ("lambda-runtime-function-xray-error-cause: " + handler_response.get_xray_response()).c_str());
352+
}
350353
headers = curl_slist_append(headers, "Expect:");
351354
headers = curl_slist_append(headers, "transfer-encoding:");
352355
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
521524
}
522525

523526
AWS_LAMBDA_RUNTIME_API
524-
invocation_response invocation_response::failure(std::string const& error_message, std::string const& error_type)
527+
invocation_response invocation_response::failure(std::string const& error_message, std::string const& error_type, std::string const& xray_response)
525528
{
526529
invocation_response r;
527530
r.m_success = false;
528531
r.m_content_type = "application/json";
529532
r.m_payload = R"({"errorMessage":")" + json_escape(error_message) + R"(","errorType":")" + json_escape(error_type) +
530533
R"(","stackTrace":[]})";
534+
r.m_xray_response = xray_response;
531535
return r;
532536
}
533537

0 commit comments

Comments
 (0)