diff --git a/include/aws/lambda-runtime/runtime.h b/include/aws/lambda-runtime/runtime.h
 index 0dc292c..be77d93 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 e2ee7cd..d895c4b 100644
 --- a/src/runtime.cpp
 +++ b/src/runtime.cpp
 @@ -337,6 +337,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, get_user_agent_header().c_str());
 @@ -511,13 +512,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;
  }