You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ERROR] cannot find the current segment/subsegment, please make sure you have a segment open
[WARNING] No segment found, cannot begin subsegment foo.app.
[ERROR] Exception on / [GET]
Traceback (most recent call last):
File "/var/task/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/var/task/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/var/task/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/var/task/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/var/task/flask/_compat.py", line 35, in reraise
raise value
File "/var/task/flask/app.py", line 1811, in full_dispatch_request
rv = self.preprocess_request()
File "/var/task/flask/app.py", line 2087, in preprocess_request
rv = func()
File "/var/task/aws_xray_sdk/ext/flask/middleware.py", line 57, in _before_request
segment.save_origin_trace_header(xray_header)
AttributeError: 'NoneType' object has no attribute 'save_origin_trace_header'
For context this is under lambda execution of zappa/flask and aws-xray-sdk-python is initiated as follows:
from aws_xray_sdk.core import xray_recorder, patch_all
from aws_xray_sdk.core.lambda_launcher import check_in_lambda
from aws_xray_sdk.core.context import Context
from aws_xray_sdk.ext.flask.middleware import XRayMiddleware
[...snip...]
if check_in_lambda():
xray_recorder.configure(service=__name__, sampling=False, context=Context())
XRayMiddleware(app, xray_recorder)
patch_all()
Its obvious that this is related to application not being able to start segment (not entirely clear to me why that is happening), however if segment is not found for what ever reason expectation is that application starts (with warning) rather than crash with exception.
Thank you very much for letting us know about the issue you are having.
This new release added official support for the Serverless model. Prior to this, a common work around for customers to use middlewares in Lambda was to override the recorder to use the default context, which is what Context() is, and to not automatically use the LambdaContext.
This update changed the way middlewares behave in Lambda directly. They automatically create subsegments now instead of segments. So it is no longer necessary to override the recorder's Context.
So to fix your problem, all you have to do is remove the parameter context=Context() from your recorder configuration.
This does indicate an even deeper bug: The middleware should only opt to begin subsegments rather than segments when the LambdaContext is used. That way, middlewares would not suddenly change behaviors when custom contexts are used--even if it's being used in a lambda environment. #138
This is a regression from #127
For context this is under lambda execution of zappa/flask and aws-xray-sdk-python is initiated as follows:
Its obvious that this is related to application not being able to start segment (not entirely clear to me why that is happening), however if segment is not found for what ever reason expectation is that application starts (with warning) rather than crash with exception.
Assumption that if code is under lambda it must already have segment created is not entirely accurate?
The text was updated successfully, but these errors were encountered: