- 23 Feb 2022
- 3 Minutes to read
-
Print
Python lambda
- Updated on 23 Feb 2022
- 3 Minutes to read
-
Print
Traceable provides tracing agent if you are using python lambda in your application. Configuring Traceable for your application using python lambda consists of deploying a lambda, adding the Traceable python and Traceable collector layers. The final step is to configure the Traceable python and Traceable collector layers. The following diagram shows a high-level deployment architecture for Traceable's python lambda.
Traceable's python lambda currently supports only the observability features.
Before you begin
Make a note of the following points before you begin installation and configuration:
- Make sure that you have installed and configured Traceable Platform agent. For more information, see Platform agent.
- Make a note of the Traceable Platform agent IP address. It will be used in step 3 during configuration of layers.
- Make sure that the port number 4318 is available.
- The supported python versions are 3.6, 3.7, 3.8, and 3.9
- Make sure that you have an AWS account.
Step 1 - Deploy a lambda
To deploy a lambda, you should first find or create a python 3.6, 3.7, 3.8, or 3.9 lambda. Make sure that you increase you lambda timeout settings. The default timeout value is 3 seconds. Make a note of the following points:
- An API gateway must be on the frontend of the lambda.
- The lambda must be using x86_64 architecture. Arm64 is currently not supported.
Step 2 - Add the layers
In step 2, you need to add two layers of Traceable python and Traceable collector. Complete the following steps to add the layers:
- Log into your AWS account.
- Search for Lambda from the search bar.
- Navigate to Functions from the Lambda page and click on the function name that you want to choose.
- Click on the function name. The function page is displayed.
- Click on Layers from the function page.
- Click on Add a layer from the Layers section.
- Click on the Specify an ARN radio button. Enter the ARNs mentioned below for Python and Traceable collector layers.
- Python ARN -
arn:aws:lambda:<aws-region>:031394183954:layer:traceableai-python3X:1
. Replace X in the ARN with your python version. - Collector ARN -
arn:aws:lambda:<aws-region>:031394183954:layer:traceableai-collector:5
- Python ARN -
Before proceeding to configuring layers, make sure that Lambda has the following:
- traceableai-python3X
- traceableai-collector
Supported AWS regions
Following is a list of supported AWS regions:
- us-east-1 and us-east-2
- us-west-1 and us-west-2
- ap-northeast-1, ap-northeast-2, and ap-northeast-3"
- ap-south-1
- ap-southeast-1 and ap-southeast-2
- ca-central-1
- eu-central-1
- eu-north-1
- eu-west-1, eu-west-2, and eu-west-3
- sa-east-1
Step 3 - Configure layers
Configuring layers is different for python 3.6 and 3.7 than configuring layers for python 3.8 and 3.9. Make a note of the following points before configuring layers:
- Configure
TPA_ENDPOINT: http://<insert_your_tpa_ip>:4318
as an environment variable;tpa
is the Traceable Platform agent IP address that you made a note of in the Before you begin section. - Make sure that the port number is 4318. This is important to connect to the Traceable Platform agent OTLP HTTP endpoint.
Depending on your python versions, follow the steps from one of the following two sections:
Configure Python 3.6 and 3.7 layers
Complete the following steps to configure layers for Python 3.6 and 3.7:
- Add an environment variable
ORIG_HANDLER
. Set the value of the environment variable to your current lambda function handler function module path. You can view the current handler value in lambda in the Code tab. In the current example, the value of the ORIG_HANDLER would beORIG_HANDLER=lambda_function.lambda_handler
. - Update the defined handler value marked in the box above with a new value,
traceableai_wrapper.lambda_handler
.
Configure Python 3.8 and 3.9 layers
To configure Python 3.8 and 3.9 layers, set AWS_LAMBDA_EXEC_WRAPPER: /opt/traceableai-instrument
environment variable on the lambda. This instructs the lambda to invoke Traceable's wrapper script instead of the default lambda handler. Traceable in turn invokes your original handler.
Verification
To verify a successful configuration of python lambda, invoke the lambda function by sending traffic through the API gateway endpoint. Login to Traceable platform and check whether the service and associated traces and spans are displayed.
Troubleshooting
Following are a few troubleshooting tips for the python lambda deployment:
Problem | Troubleshooting tip |
---|---|
No data is reported | Set the TA_LOG_LEVEL=DEBUG environment variable in the lambda. Reinvoke the lambda and view the logs in cloudwatch for any errors that could help determining the root cause. |
The response body is not captured | Check if the lambda returns a “Content-Type” header, that is set to a value including: application/json . If not, then update the lambda to return a content-type header. |
The request body is not captured | Check if the incoming request is sending a “Content-Type” header, that is set to a value including: application/json ? If not, then update the request to include a content-type header. |
The status code is not reported | Check whether the lambda returns a statusCode field to indicate the HTTP status code?If not, then update the lambda to return a statusCode field. |