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
{{ message }}
Repository navigation
Would be great to have a test mode that stub out the library #17
It would be nice to have a stub version of the wrapper. Currently when I'm running test on the lambda function code locally it will trigger error in two places:
extract_dd_trace_context() in the class _LambdaDecorator will throw exception because missing trace segment.
When metric.lambda_metric() is run in tests, it throws exception because it cannot send metrics to datadog.
Thanks for the feedback @jackyjjc-canva, we will look into this! Meanwhile, do you mind sharing a little bit more details with us, say a code snippet from your tests that you expect to work?
The first issue happens when I import the module to be tested because _LambdaDecorator is invoked at that point in time. The exact exception was:
cannot find the current segment/subsegment, please make sure you have a segment open
Traceback (most recent call last):
File "/lambda/.ve/lib/python3.7/site-packages/datadog_lambda/wrapper.py", line 60, in _before
set_correlation_ids()
File "/lambda/.ve/lib/python3.7/site-packages/datadog_lambda/tracing.py", line 127, in set_correlation_ids
context = get_dd_trace_context()
File "/lambda/.ve/lib/python3.7/site-packages/datadog_lambda/tracing.py", line 98, in get_dd_trace_context
xray_trace_entity = xray_recorder.get_trace_entity() # xray (sub)segment
File "/lambda/.ve/lib/python3.7/site-packages/aws_xray_sdk/core/recorder.py", line 369, in get_trace_entity
return self.context.get_trace_entity()
File "/lambda/.ve/lib/python3.7/site-packages/aws_xray_sdk/core/context.py", line 93, in get_trace_entity
return self.handle_context_missing()
File "/lambda/.ve/lib/python3.7/site-packages/aws_xray_sdk/core/context.py", line 118, in handle_context_missing
raise SegmentNotFoundException(MISSING_SEGMENT_MSG)
aws_xray_sdk.core.exceptions.exceptions.SegmentNotFoundException: cannot find the current segment/subsegment, please make sure you have a segment open
The second issue happens when I run the tests. Of course someone can make the case that I should test the business logic separated and I don't need to test the Lambda code. However I would still like to have an end-to-end test that test the whole Lambda code path besides my business logic tests.
@jackyjjc-canva after a quick look, I believe the issue was introduced in the latest version (v6). While we are fixing the issue, you can probably work around this issue by using version 5 (or 0.5.0 for pip).
#18 should fix the specific issue caused the exception. Do you mind trying it out and let us know if it works for you?
You can install it using pip install git+https://github.com/DataDog/datadog-lambda-layer-python@tian.chu/check-for-lambda-context
I agree, in the long run, there should be a toggle to short-circuit (turn off) all datadog operations for testing purpose. I will queue a ticket in our internal backlog and leave this issue open for tracking.
Activity
tianchu commentedon Oct 1, 2019
Thanks for the feedback @jackyjjc-canva, we will look into this! Meanwhile, do you mind sharing a little bit more details with us, say a code snippet from your tests that you expect to work?
jackyjjc-canva commentedon Oct 2, 2019
This is my Lamdba function (I took out the parts with business logic)
This is my test:
The first issue happens when I import the module to be tested because
_LambdaDecoratoris invoked at that point in time. The exact exception was:The second issue happens when I run the tests. Of course someone can make the case that I should test the business logic separated and I don't need to test the Lambda code. However I would still like to have an end-to-end test that test the whole Lambda code path besides my business logic tests.
tianchu commentedon Oct 2, 2019
@jackyjjc-canva end-to-end tests make perfect sense for Lambda. We will have a fix soon.
tianchu commentedon Oct 2, 2019
@jackyjjc-canva after a quick look, I believe the issue was introduced in the latest version (v6). While we are fixing the issue, you can probably work around this issue by using version 5 (or 0.5.0 for pip).
tianchu commentedon Oct 3, 2019
#18 should fix the specific issue caused the exception. Do you mind trying it out and let us know if it works for you?
You can install it using
pip install git+https://github.com/DataDog/datadog-lambda-layer-python@tian.chu/check-for-lambda-contextI agree, in the long run, there should be a toggle to short-circuit (turn off) all datadog operations for testing purpose. I will queue a ticket in our internal backlog and leave this issue open for tracking.
jackyjjc-canva commentedon Oct 4, 2019
Thank you @tianchu I will take a look.
jackyjjc-canva commentedon Oct 8, 2019
Sorry for the delay but I can confirm it has resolved the issue. Thank you! @tianchu
tedyu commentedon Nov 8, 2023
@tianchu
Can you tell me how to stub out datadog handler for unit testing (with node.js) ?
Thanks