Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
23 changes: 20 additions & 3 deletions include/aws/lambda-runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -97,8 +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 = "")
Comment thread
bmoffatt marked this conversation as resolved.
Outdated
: m_payload(payload), m_content_type(content_type), m_success(success), m_xray_response(xray_response)
{
}

Expand All @@ -111,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);
static invocation_response failure(
std::string const& error_message,
std::string const& error_type,
std::string const& xray_response = "");
Comment thread
bmoffatt marked this conversation as resolved.
Outdated

/**
* Get the MIME type of the payload.
Expand All @@ -127,6 +139,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 {};
Expand Down
10 changes: 9 additions & 1 deletion src/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ 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());
Expand Down Expand Up @@ -521,13 +525,17 @@ 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;
}

Expand Down