Skip to content

Commit

Permalink
squash
Browse files Browse the repository at this point in the history
  • Loading branch information
carolabadeer committed Nov 9, 2022
1 parent dd7213b commit e99c271
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 79 deletions.
6 changes: 3 additions & 3 deletions packages/core/lib/env/sqs_message_helper.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class SqsMessageHelper {

static isSampled(message) {
const {attributes} = message; // extract attributes from message
static isSampled(message) {
const {attributes} = message; // extract attributes from message
if (!('AWSTraceHeader' in attributes)) {
return false;
return false;
}
return attributes['AWSTraceHeader'].includes('Sampled=1');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/patchers/aws3_p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const getXRayMiddleware = (config: RegionResolvedConfig, manualSegment?: Segment
}

let subsegment: Subsegment;

if (segment.subsegments && segment.subsegments[segment.subsegments.length - 1].notTraced) {
subsegment = segment.addNewSubsegmentWithoutSampling(service);
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/segments/segment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ declare class Segment {

addSubsegment(subsegment: Subsegment): void;

addSubsegmentWithoutSampling(subsegment: Subsegment): void;
addSubsegmentWithoutSampling(subsegment: Subsegment): void;

addNewSubsegmentWithoutSampling(name: string): Subsegment

Expand Down
144 changes: 72 additions & 72 deletions packages/core/test/unit/env/sqs_message_helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,78 +7,78 @@ import SqsMessageHelper from '../../../lib/env/sqs_message_helper';
chai.should();
chai.use(sinonChai);

describe('#SqsMessageHelper', function (){
describe('#SqsMessageHelper', function () {

// sample records from https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html
const 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"
}
]
}

describe('SqsMessageHelper isSampled', function(){

it('should return true when AWSTraceHeader has Sampled=1', function(){
assert.equal(SqsMessageHelper.isSampled(sampleSqsMessageEvent.Records[0]), true)
});
// sample records from https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html
const 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'
}
]
};

it('should return false when AWSTraceHeader has Sampled=0', function(){
assert.equal(SqsMessageHelper.isSampled(sampleSqsMessageEvent.Records[1]), false)
});
describe('SqsMessageHelper isSampled', function() {

it('should return false when AWSTraceHeader has no Sampled flag', function(){
assert.equal(SqsMessageHelper.isSampled(sampleSqsMessageEvent.Records[2]), false)
});

})
});
it('should return true when AWSTraceHeader has Sampled=1', function() {
assert.equal(SqsMessageHelper.isSampled(sampleSqsMessageEvent.Records[0]), true);
});

it('should return false when AWSTraceHeader has Sampled=0', function() {
assert.equal(SqsMessageHelper.isSampled(sampleSqsMessageEvent.Records[1]), false);
});

it('should return false when AWSTraceHeader has no Sampled flag', function() {
assert.equal(SqsMessageHelper.isSampled(sampleSqsMessageEvent.Records[2]), false);
});

});
});
4 changes: 2 additions & 2 deletions packages/core/test/unit/patchers/aws_p.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ describe('AWS patcher', function() {
awsRequest.emitter = new MyEmitter();

segment = new Segment('testSegment', traceId);
sub = segment.addNewSubsegmentWithoutSampling("subseg");
sub = segment.addNewSubsegmentWithoutSampling('subseg');

stubResolveManual = sandbox.stub(contextUtils, 'resolveManualSegmentParams');
stubResolve = sandbox.stub(contextUtils, 'resolveSegment').returns(segment);
Expand Down Expand Up @@ -345,4 +345,4 @@ describe('AWS patcher', function() {
});

});
});
});

0 comments on commit e99c271

Please sign in to comment.