Skip to content

Commit

Permalink
Update README.md (aws#363)
Browse files Browse the repository at this point in the history
* Update README.md
  • Loading branch information
atshaw43 authored Nov 21, 2022
1 parent 3591822 commit 1311d58
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,71 @@ try {
```
Note that in the closure-based example above, exceptions are intercepted automatically.

### Oversampling Mitigation
Oversampling mitigation allows you to ignore a parent segment/subsegment's sampled flag and instead sets the subsegment's sampled flag to false.
This ensures that downstream calls are not sampled and this subsegment is not emitted.

```Java
public class Handler implements RequestHandler<SQSEvent, String> {
public Handler() {
}

@Override
public String handleRequest(SQSEvent event, Context context) {
AWSXRay.beginSubsegmentWithoutSampling("Processing Event");

AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();

ListQueuesResult lq_result = sqs.listQueues();

System.out.println("Your SQS Queue URLs:");

for (String url : lq_result.getQueueUrls()) {
System.out.println(url);
}

AWSXRay.endSubsegment();

return "Success";
}
}
```

The code below demonstrates overriding the sampled flag based on the SQS message.

```java
public class Handler implements RequestHandler<SQSEvent, String> {
public Handler() {
}

@Override
public String handleRequest(SQSEvent event, Context context) {

int i = 1;

for (SQSMessage message: event.getRecords()) {

// Check if the message is sampled
if (SQSMessageHelper.isSampled(message)) {
AWSXRay.beginSubsegment("Processing Message - " + i);
} else {
AWSXRay.beginSubsegmentWithoutSampling("Processing Message - " + i);
}

i++;

// Do your procesing work here
System.out.println("Doing processing work");

// End your subsegment
AWSXRay.endSubsegment();
}

return "Success";
}
}
```

## Integration with ServiceLens

As of version 2.4.0, the X-Ray SDK for Java is integrated with [CloudWatch ServiceLens](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ServiceLens.html). This allows you to use a wide range of new observability features which connect your traces, logs, and metrics in one place.
Expand Down

0 comments on commit 1311d58

Please sign in to comment.