From 007b30948b9b0afa36fd79036c04733b0b7b4c10 Mon Sep 17 00:00:00 2001
From: Matthijs Piek <2212627+MatthijsPiek@users.noreply.github.com>
Date: Tue, 18 Jul 2023 10:58:51 +0200
Subject: [PATCH 1/2] Partial fix for #1753: Add TracingEnabled to RestAPI when
xray enabled in config.
---
chalice/package.py | 3 +++
tests/unit/test_package.py | 12 ++++++++++++
2 files changed, 15 insertions(+)
diff --git a/chalice/package.py b/chalice/package.py
index ecdd0268e..fb55676e9 100644
--- a/chalice/package.py
+++ b/chalice/package.py
@@ -334,6 +334,9 @@ def _generate_restapi(self, resource, template):
properties = resources['RestAPI']['Properties']
properties['MinimumCompressionSize'] = \
int(resource.minimum_compression)
+ if self._config.xray_enabled:
+ properties = resources['RestAPI']['Properties']
+ properties['TracingEnabled'] = True
handler_cfn_name = to_cfn_resource_name(
resource.lambda_function.resource_name)
diff --git a/tests/unit/test_package.py b/tests/unit/test_package.py
index cd01e451d..e770344be 100644
--- a/tests/unit/test_package.py
+++ b/tests/unit/test_package.py
@@ -1335,6 +1335,17 @@ def test_can_generate_scheduled_event(self):
},
}
+ def test_can_generate_rest_api_with_xray(
+ self, sample_app_with_auth):
+ config = Config.create(chalice_app=sample_app_with_auth,
+ project_dir='.',
+ api_gateway_stage='api',
+ xray=True
+ )
+ template = self.generate_template(config)
+ resources = template['Resources']
+ assert resources['RestAPI']['Properties']['TracingEnabled'] is True
+
def test_can_generate_rest_api_without_compression(
self, sample_app_with_auth):
config = Config.create(chalice_app=sample_app_with_auth,
@@ -1372,6 +1383,7 @@ def test_can_generate_rest_api(self, sample_app_with_auth):
assert resources['RestAPI']['Type'] == 'AWS::Serverless::Api'
assert resources['RestAPI']['Properties']['MinimumCompressionSize'] \
== 100
+ assert 'TracingEnabled' not in resources['RestAPI']['Properties']
# We should also create the auth lambda function.
assert resources['Myauth']['Type'] == 'AWS::Serverless::Function'
# Along with permission to invoke from API Gateway.
From 48c74d2b0d1240645b7d627cb18a939d23e5c396 Mon Sep 17 00:00:00 2001
From: Matthijs Piek <2212627+MatthijsPiek@users.noreply.github.com>
Date: Thu, 27 Jul 2023 11:11:33 +0200
Subject: [PATCH 2/2] Documentation moved. Fixed the broken links for you.
---
docs/source/topics/middleware.rst | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/docs/source/topics/middleware.rst b/docs/source/topics/middleware.rst
index 90a8ea0de..465315bc1 100644
--- a/docs/source/topics/middleware.rst
+++ b/docs/source/topics/middleware.rst
@@ -271,15 +271,15 @@ Integrating with AWS Lambda Powertools
--------------------------------------
`AWS Lambda Powertools
-`__ is a suite of
+`__ is a suite of
utilities for AWS Lambda functions that makes tracing with AWS X-Ray,
structured logging and creating custom metrics asynchronously easier.
You can use Chalice middleware to easily integrate Lambda Powertools with
your Chalice apps. In this example, we'll use the
`Logger
-`__
-and `Tracer `__
+`__
+and `Tracer `__
and convert them to Chalice middleware so they will be automatically applied
to all Lambda functions in our application.