Skip to content
Open
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
24 changes: 24 additions & 0 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 @@ -102,6 +107,15 @@ class invocation_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.
*/
Expand All @@ -113,6 +127,11 @@ class invocation_response {
*/
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.
*/
Expand All @@ -127,6 +146,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
14 changes: 14 additions & 0 deletions 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 @@ -522,12 +526,22 @@ 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)
{
return failure(error_message, error_type, "");
}

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 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