use of software.amazon.lambda.powertools.tracing.Tracing in project aws-lambda-powertools-java by awslabs.
the class TracingLoggingStreamMessageHandler method handleRequest.
@Logging(logEvent = true)
@Tracing
@Override
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(output, mapper.readValue(input, Map.class));
}
use of software.amazon.lambda.powertools.tracing.Tracing in project serverless-webapp-mono-repo-ci-cd-java by aws-samples.
the class IndexImageHandler method updateIndexDetails.
@Tracing
private void updateIndexDetails(final String faceId, final String fullname) {
Map<String, AttributeValue> item = new HashMap<>();
item.put("RekognitionId", AttributeValue.builder().s(faceId).build());
item.put("FullName", AttributeValue.builder().s(fullname).build());
PutItemResponse putItemResponse = dynamoDbClient.putItem(PutItemRequest.builder().tableName(TABLE_NAME).item(item).build());
LOG.debug("Persistance response from dynamo db {}", putItemResponse);
}
use of software.amazon.lambda.powertools.tracing.Tracing in project serverless-webapp-mono-repo-ci-cd-java by aws-samples.
the class RecognizeImageHandler method faceSearch.
@Tracing(captureMode = ERROR)
private List<FaceMatch> faceSearch(byte[] decodedImage) {
try {
SearchFacesByImageResponse searchFacesByImageResponse = rekognitionClient.searchFacesByImage(builder -> builder.collectionId(COLLECTION_ID).image(Image.builder().bytes(SdkBytes.fromByteArray(decodedImage)).build()).maxFaces(1).faceMatchThreshold(90f));
LOG.debug("Service response for find face {}", searchFacesByImageResponse);
return searchFacesByImageResponse.faceMatches();
} catch (Exception e) {
LOG.error("Failed getting find face result. Reason: {}", e.getMessage(), e);
return emptyList();
}
}
use of software.amazon.lambda.powertools.tracing.Tracing in project aws-lambda-powertools-examples by aws-samples.
the class App method getPageContents.
@Tracing(namespace = "getPageContents", captureMode = CaptureMode.DISABLED)
private String getPageContents(String address) throws IOException {
URL url = new URL(address);
putMetadata("getPageContents", address);
try (BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))) {
return br.lines().collect(Collectors.joining(System.lineSeparator()));
}
}
use of software.amazon.lambda.powertools.tracing.Tracing in project serverless-webapp-mono-repo-ci-cd-java by aws-samples.
the class ImageUploadHandler method handleRequest.
@Logging(logEvent = true, samplingRate = 0.5)
@Tracing
@Metrics(captureColdStart = true)
@Override
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
APIGatewayProxyResponseEvent apiGatewayProxyResponseEvent = new APIGatewayProxyResponseEvent();
Map<String, String> headers = new HashMap<>();
headers.put("Access-Control-Allow-Origin", "*");
apiGatewayProxyResponseEvent.withHeaders(headers);
String contentType = input.getQueryStringParameters().getOrDefault("content-type", "");
String fileExtension = input.getQueryStringParameters().getOrDefault("file-extension", "");
if (contentType.isEmpty() || fileExtension.isEmpty()) {
return apiGatewayProxyResponseEvent.withStatusCode(400).withBody("{\n" + " \"message\": \"Both content-type and file-extension need to passed as query param!\" \n" + "}");
}
String fileName = UUID.randomUUID() + fileExtension;
String imagePath = "index/static/" + fileName;
String personName = input.getQueryStringParameters().getOrDefault("person-name", "");
LOG.debug("File path to be saved {} in bucket {}", imagePath, S3_BUCKET);
LOG.debug("Received metadata {}", personName);
HashMap<String, String> metaData = new HashMap<>();
metaData.put("fullname", personName);
PresignedPutObjectRequest requestObject = client.presignPutObject(req -> req.putObjectRequest(obj -> obj.metadata(metaData).bucket(S3_BUCKET).key(imagePath).contentType(contentType)).signatureDuration(Duration.ofSeconds(60)));
metricsLogger().putMetric("RemainingTime", context.getRemainingTimeInMillis(), Unit.MILLISECONDS);
LOG.debug("Generated pre signed url {}", requestObject.url());
LOG.debug("Generated pre signed details meta {}", requestObject.signedHeaders());
return response(apiGatewayProxyResponseEvent, fileName, requestObject.url());
}
Aggregations