Skip to content

Commit adc0a31

Browse files
authored
docs(examples): Enable end to end tracing for SQS batch example. (#1995)
1 parent b84c531 commit adc0a31

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

examples/powertools-examples-batch/deploy/sqs/template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Resources:
6565
DemoSQSSenderFunction:
6666
Type: AWS::Serverless::Function
6767
Properties:
68+
Tracing: Active
6869
CodeUri: ../..
6970
Handler: org.demo.batch.sqs.SqsBatchSender::handleRequest
7071
Environment:
@@ -173,7 +174,6 @@ Resources:
173174
Action:
174175
- s3:PutObject
175176
Resource: !Sub ${Bucket.Arn}/*
176-
177177
Events:
178178
MySQSEvent:
179179
Type: SQS

examples/powertools-examples-batch/src/main/java/org/demo/batch/sqs/AbstractSqsBatchHandler.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@
1414

1515
package org.demo.batch.sqs;
1616

17-
import com.amazonaws.services.lambda.runtime.Context;
18-
import com.fasterxml.jackson.databind.ObjectMapper;
1917
import java.io.File;
2018
import java.io.IOException;
2119
import java.util.Arrays;
2220
import java.util.Random;
21+
2322
import org.demo.batch.model.Product;
2423
import org.slf4j.Logger;
2524
import org.slf4j.LoggerFactory;
2625
import org.slf4j.MDC;
26+
27+
import com.fasterxml.jackson.databind.ObjectMapper;
28+
2729
import software.amazon.awssdk.core.sync.RequestBody;
2830
import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
2931
import software.amazon.awssdk.services.s3.S3Client;
3032
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
31-
import software.amazon.lambda.powertools.logging.Logging;
3233
import software.amazon.lambda.powertools.tracing.Tracing;
3334
import software.amazon.lambda.powertools.tracing.TracingUtils;
3435

@@ -43,23 +44,23 @@ public class AbstractSqsBatchHandler {
4344
* Simulate some processing (I/O + S3 put request)
4445
* @param p deserialized product
4546
*/
46-
@Logging
4747
@Tracing
4848
protected void processMessage(Product p) {
4949
TracingUtils.putAnnotation("productId", p.getId());
5050
TracingUtils.putAnnotation("Thread", Thread.currentThread().getName());
5151
MDC.put("product", String.valueOf(p.getId()));
5252
LOGGER.info("Processing product {}", p);
5353

54-
char c = (char)(r.nextInt(26) + 'a');
54+
char c = (char) (r.nextInt(26) + 'a');
5555
char[] chars = new char[1024 * 1000];
5656
Arrays.fill(chars, c);
5757
p.setName(new String(chars));
5858
try {
59-
File file = new File("/tmp/"+p.getId()+".json");
59+
File file = new File("/tmp/" + p.getId() + ".json");
6060
mapper.writeValue(file, p);
6161
s3.putObject(
62-
PutObjectRequest.builder().bucket(bucket).key(p.getId()+".json").build(), RequestBody.fromFile(file));
62+
PutObjectRequest.builder().bucket(bucket).key(p.getId() + ".json").build(),
63+
RequestBody.fromFile(file));
6364
} catch (IOException e) {
6465
throw new RuntimeException(e);
6566
} finally {

0 commit comments

Comments
 (0)