-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathaws-lambda-cpp-add-xray-response.patch
83 lines (76 loc) · 3.57 KB
/
aws-lambda-cpp-add-xray-response.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
diff --git a/include/aws/lambda-runtime/runtime.h b/include/aws/lambda-runtime/runtime.h
index 94e1e22..ee356ff 100644
--- a/include/aws/lambda-runtime/runtime.h
+++ b/include/aws/lambda-runtime/runtime.h
@@ -85,6 +85,11 @@ private:
*/
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 @@ public:
// 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 @@ public:
* 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 @@ public:
* 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 9175084..230ce6f 100644
--- a/src/runtime.cpp
+++ b/src/runtime.cpp
@@ -333,6 +333,7 @@ runtime::post_outcome runtime::do_post(
headers = curl_slist_append(headers, ("content-type: " + handler_response.get_content_type()).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:");
headers = curl_slist_append(headers, m_user_agent_header.c_str());
@@ -507,13 +508,15 @@ invocation_response invocation_response::success(std::string const& payload, std
}
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;
}