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
To modify the sampling decision at the subsegment level, subsegments that inherit the decision of their direct parent (segment or subsegment) can be created using the `addNewSubsegment` and `addSubsegment` APIs, and unsampled subsegments can be created using the `addNewSubsegmentWithoutSampling` and `addSubsegmentWithoutSampling` APIs.
406
+
407
+
The code snippet below demonstrates creating a sampled or unsampled subsegment based on the sampling decision of each SQS message processed by Lambda.
408
+
409
+
```js
410
+
exports.handler=asyncfunction(event, context) {
411
+
event.Records.forEach(message=> {
412
+
413
+
const { attributes } = message;
414
+
let facade =xrayContext.getSegment();
415
+
416
+
if(SqsMessageHelper.isSampled(message)){
417
+
418
+
let sampledSubsegment =facade.addNewSubsegment('sqs-subsegment-sampled');
419
+
xrayContext.setSegment(sampledSubsegment);
420
+
console.log("processing SQS message - sampled");
421
+
sampledSubsegment.close();
422
+
423
+
} else {
424
+
let unsampledSubsegment =facade.addNewSubsegmentWithoutSampling('sqs-subsegment-unsampled');
0 commit comments