Saw AWS X-Ray SDK for Python (Beta) from Aug 8, 2017 and wondered where AWS X-Ray support was on the roadmap (or if it just works).
What were you envisioning exactly? Lambda and boto3 already support xray. Anything in particular you were thinking about with this feature?
boto3 may support the same X-Ray operations as the AWS CLI does, but boto3 has no support for automatically pushing trace segments for boto operations.
I think @hakanson is asking for a built-in version of https://github.com/racker/fleece. Fleece has compiled dependencies, so it's not very nice to use with chalice's limited support for those.
For more background, you can pip install aws-xray-sdk for code and read the (limited) aws-xray-sdk docs. I had to browse the code to find some of the details I was looking for.
By "AWS X-Ray support" I would expect a chalice deploy do things like:
To illustrate with some code, I hacked some stuff inside of the function that should come from a decorator or something.
@xray_recorder.capture()
@app.route('/')
def index():
subsegment = xray_recorder.begin_subsegment('index')
subsegment.put_http_meta('url', '/')
subsegment.put_http_meta('method', 'GET')
# some code block you want to record
xray_recorder.end_subsegment()
return {'hello': 'world'}
I added aws-xray-sdk==0.91.1 to my requirements.txt, did another chalice deploy and a trace appeared in the AWS Console. This extra 'index' subsegment is what puts the GET / in the screenshot below from the AWS X-Ray trace details.

I'm new to both AWS X-Ray and Python, so I hope this makes sense.
Ah ok, yeah that makes sense. Thanks for the feature request.
FYI, saw the source code for the AWS X-Ray SDK for Python is now available on GitHub: https://github.com/aws/aws-xray-sdk-python
There's nice middleware support for Flask, would be awesome to see Chalice treated as a first-class citizen the same way.
https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-python-middleware.html#xray-sdk-python-adding-middleware-flask
I was testing out with Chalice and X-Ray and I just can't get it to work. I can activate tracing from console for function but then I just get client -> lambda mapping and nothing else, ie. if one lambda calls other lambda I just get two totally separate entries in X-Ray. I think I should be able to get out more.
According to https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-python-patching.html
import boto3
from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core import patch_all
patch_all()
Would be needed to get tracing on calls from lambda function. But when trying to do chalice deploy I get error cannot find the current segment/subsegment, please make sure you have a segment open.
Not sure why it fails that way. Thought it would be because for some reason Chalice runs the app.py file on deploy, but it is not stuff outside methods.
@jarikujansuu did you manage to work around the deploy issue?
Chalice support request under AWS X-Ray Python SDK repo https://github.com/aws/aws-xray-sdk-python/issues/62
@jarikujansuu you have to conditionally patch based on an environment variable which will denote if the app is in lambda or not. if its not in lambda there isn't an active segment when api calls are made leading to that error.
But when trying to do chalice deploy I get
error cannot find the current segment/subsegment, please make sure you have a segment open.
You can suppress that feature using xray_recorder.configure(context_missing='LOG_ERROR')
chalice deploy works after that.
Resolving issue, xray is now supported via #1159
Most helpful comment
I was testing out with Chalice and X-Ray and I just can't get it to work. I can activate tracing from console for function but then I just get
client -> lambdamapping and nothing else, ie. if one lambda calls other lambda I just get two totally separate entries in X-Ray. I think I should be able to get out more.According to https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-python-patching.html
Would be needed to get tracing on calls from lambda function. But when trying to do
chalice deployI get errorcannot find the current segment/subsegment, please make sure you have a segment open.Not sure why it fails that way. Thought it would be because for some reason Chalice runs the
app.pyfile on deploy, but it is not stuff outside methods.