Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial fix for #1753: Add TracingEnabled to RestAPI during SAM package when xray enabled in config #2058

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions chalice/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions docs/source/topics/middleware.rst
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,15 @@ Integrating with AWS Lambda Powertools
--------------------------------------

`AWS Lambda Powertools
<https://awslabs.github.io/aws-lambda-powertools-python/latest/>`__ is a suite of
<https://docs.powertools.aws.dev/lambda/python/latest/>`__ 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
<https://awslabs.github.io/aws-lambda-powertools-python/latest/core/logger/>`__
and `Tracer <https://awslabs.github.io/aws-lambda-powertools-python/latest/core/tracer/>`__
<https://docs.powertools.aws.dev/lambda/python/latest/core/logger/>`__
and `Tracer <https://docs.powertools.aws.dev/lambda/python/latest/core/tracer/>`__
and convert them to Chalice middleware so they will be automatically applied
to all Lambda functions in our application.

Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down