-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implemented oversampling mitigation * updated begin_subsegment docstring to include sampling parameter * created separate API for adding subsegments without sampling * Modified add_subsegment method to log warning for orphaned subsegments * updated unit tests * addressing feedback * final design changes * remove default namespace value * minor fix
- Loading branch information
1 parent
6e30483
commit 6b64982
Showing
10 changed files
with
230 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
SQS_XRAY_HEADER = "AWSTraceHeader" | ||
class SqsMessageHelper: | ||
|
||
@staticmethod | ||
def isSampled(sqs_message): | ||
attributes = sqs_message['attributes'] | ||
|
||
if SQS_XRAY_HEADER not in attributes: | ||
return False | ||
|
||
return 'Sampled=1' in attributes[SQS_XRAY_HEADER] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from aws_xray_sdk.core.utils.sqs_message_helper import SqsMessageHelper | ||
|
||
import pytest | ||
|
||
sampleSqsMessageEvent = { | ||
"Records": [ | ||
{ | ||
"messageId": "059f36b4-87a3-44ab-83d2-661975830a7d", | ||
"receiptHandle": "AQEBwJnKyrHigUMZj6rYigCgxlaS3SLy0a...", | ||
"body": "Test message.", | ||
"attributes": { | ||
"ApproximateReceiveCount": "1", | ||
"SentTimestamp": "1545082649183", | ||
"SenderId": "AIDAIENQZJOLO23YVJ4VO", | ||
"ApproximateFirstReceiveTimestamp": "1545082649185", | ||
"AWSTraceHeader":"Root=1-632BB806-bd862e3fe1be46a994272793;Sampled=1" | ||
}, | ||
"messageAttributes": {}, | ||
"md5OfBody": "e4e68fb7bd0e697a0ae8f1bb342846b3", | ||
"eventSource": "aws:sqs", | ||
"eventSourceARN": "arn:aws:sqs:us-east-2:123456789012:my-queue", | ||
"awsRegion": "us-east-2" | ||
}, | ||
{ | ||
"messageId": "2e1424d4-f796-459a-8184-9c92662be6da", | ||
"receiptHandle": "AQEBzWwaftRI0KuVm4tP+/7q1rGgNqicHq...", | ||
"body": "Test message.", | ||
"attributes": { | ||
"ApproximateReceiveCount": "1", | ||
"SentTimestamp": "1545082650636", | ||
"SenderId": "AIDAIENQZJOLO23YVJ4VO", | ||
"ApproximateFirstReceiveTimestamp": "1545082650649", | ||
"AWSTraceHeader":"Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=0" | ||
}, | ||
"messageAttributes": {}, | ||
"md5OfBody": "e4e68fb7bd0e697a0ae8f1bb342846b3", | ||
"eventSource": "aws:sqs", | ||
"eventSourceARN": "arn:aws:sqs:us-east-2:123456789012:my-queue", | ||
"awsRegion": "us-east-2" | ||
}, | ||
{ | ||
"messageId": "2e1424d4-f796-459a-8184-9c92662be6da", | ||
"receiptHandle": "AQEBzWwaftRI0KuVm4tP+/7q1rGgNqicHq...", | ||
"body": "Test message.", | ||
"attributes": { | ||
"ApproximateReceiveCount": "1", | ||
"SentTimestamp": "1545082650636", | ||
"SenderId": "AIDAIENQZJOLO23YVJ4VO", | ||
"ApproximateFirstReceiveTimestamp": "1545082650649", | ||
"AWSTraceHeader":"Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8" | ||
}, | ||
"messageAttributes": {}, | ||
"md5OfBody": "e4e68fb7bd0e697a0ae8f1bb342846b3", | ||
"eventSource": "aws:sqs", | ||
"eventSourceARN": "arn:aws:sqs:us-east-2:123456789012:my-queue", | ||
"awsRegion": "us-east-2" | ||
} | ||
] | ||
} | ||
|
||
def test_return_true_when_sampling_1(): | ||
assert SqsMessageHelper.isSampled(sampleSqsMessageEvent['Records'][0]) == True | ||
|
||
def test_return_false_when_sampling_0(): | ||
assert SqsMessageHelper.isSampled(sampleSqsMessageEvent['Records'][1]) == False | ||
|
||
def test_return_false_with_no_sampling_flag(): | ||
assert SqsMessageHelper.isSampled(sampleSqsMessageEvent['Records'][2]) == False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters