in example/HelloWorldFunction/src/main/java/helloworld/App.java [42:84]
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("X-Custom-Header", "application/json");
metricsLogger().putMetric("CustomMetric1", 1, Unit.COUNT);
withSingleMetric("CustomMetrics2", 1, Unit.COUNT, "Another", (metric) -> {
metric.setDimensions(DimensionSet.of("AnotherService", "CustomService"));
metric.setDimensions(DimensionSet.of("AnotherService1", "CustomService1"));
});
LoggingUtils.appendKey("test", "willBeLogged");
APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent()
.withHeaders(headers);
try {
final String pageContents = this.getPageContents("https://checkip.amazonaws.com");
log.info(pageContents);
TracingUtils.putAnnotation("Test", "New");
String output = String.format("{ \"message\": \"hello world\", \"location\": \"%s\" }", pageContents);
TracingUtils.withSubsegment("loggingResponse", subsegment -> {
String sampled = "log something out";
log.info(sampled);
log.info(output);
});
threadOption1();
threadOption2();
log.info("After output");
return response
.withStatusCode(200)
.withBody(output);
} catch (IOException | InterruptedException e) {
return response
.withBody("{}")
.withStatusCode(500);
}
}