Skip to content

Conversation

@tianchu
Copy link
Collaborator

@tianchu tianchu commented Oct 3, 2019

What does this PR do?

Certain xray_recorder operations only work in the LambdaContext, and it breaks when working in the non-lambda X-Ray Context (testing functions locally).

Motivation

Fix #17

Return True if the X-Ray context is `LambdaContext`, rather than the
regular `Context` (e.g., when testing lambda functions locally).
"""
return type(xray_recorder.context) == LambdaContext
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, could this throw if X-Ray is not enabled? The technique I've been using to detect lambda is to look for the 'AWS_LAMBDA_FUNCTION_NAME' environment variable.

Copy link
Collaborator Author

@tianchu tianchu Oct 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did consider checking the env var, but I felt that env var is only a proxy for truth. E.g., developers may have functions reading this env var (that's why it's provided by AWS), in this case, they still need to manually inject values to this env var for local testing as well.

BTW, I got this idea from the xray sdk: https://github.com/aws/aws-xray-sdk-python/blob/e9d3746155729a28766f866714ce082eb6612ad3/aws_xray_sdk/ext/flask/middleware.py#L23

Tested locally and in lambda, disabling AWS_XRAY_SDK_ENABLED does not cause issues.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, makes sense.

@tianchu tianchu merged commit 9a93a05 into master Oct 3, 2019
@tianchu tianchu deleted the tian.chu/check-for-lambda-context branch October 3, 2019 19:45
@tianchu tianchu restored the tian.chu/check-for-lambda-context branch October 4, 2019 03:15
@tianchu tianchu deleted the tian.chu/check-for-lambda-context branch November 5, 2019 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Would be great to have a test mode that stub out the library

3 participants