Skip to content

Commit e46dbcb

Browse files
author
Pankaj Agrawal
committed
chore: docs and javadocs update
1 parent 5964d66 commit e46dbcb

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/CorrelationIdPath.java

+23
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
package software.amazon.lambda.powertools.logging;
22

3+
/**
4+
* Supported Event types from which Correlation ID can be extracted
5+
*/
36
public enum CorrelationIdPath {
7+
/**
8+
* To use when function is expecting API Gateway Rest API Request event
9+
*/
410
API_GATEWAY_REST("/requestContext/requestId"),
11+
/**
12+
* To use when function is expecting API Gateway HTTP API Request event
13+
*/
514
API_GATEWAY_HTTP("/requestContext/requestId"),
15+
/**
16+
* To use when function is expecting Application Load balancer Request event
17+
*/
618
APPLICATION_LOAD_BALANCER("/headers/x-amzn-trace-id"),
19+
/**
20+
* To use when function is expecting Event Bridge Request event
21+
*/
722
EVENT_BRIDGE("/id"),
23+
/**
24+
* To use when function is expecting any of the supported event types to automatically
25+
* extract the correlation id. When running in this mode, if its unable to find any of the
26+
* supported types, capturing of correlation id will not be done.
27+
*/
828
AUTO_DETECT(""),
29+
/**
30+
* To use when you dont want to extract correlation id.
31+
*/
932
DISABLED("");
1033

1134
private final String path;

powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/Logging.java

+3
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,8 @@
7070

7171
double samplingRate() default 0;
7272

73+
/**
74+
* Type of Event from where to extract correlation id from.
75+
*/
7376
CorrelationIdPath correlationIdPath() default DISABLED;
7477
}

powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaLoggingAspect.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,13 @@ private void setCorrelationIdFromNode(CorrelationIdPath correlationIdPath, Proce
210210
autoDetect(pjp, jsonNode);
211211
} else {
212212
JsonNode node = jsonNode.at(JsonPointer.compile(correlationIdPath.getPath()));
213-
LoggingUtils.setCorrelationId(node.asText());
213+
214+
String asText = node.asText();
215+
if (null != asText && !asText.isEmpty()) {
216+
LoggingUtils.setCorrelationId(asText);
217+
} else {
218+
logger(pjp).debug("Unable to extract any correlation id. Is your function expecting supported event type?");
219+
}
214220
}
215221
}
216222

0 commit comments

Comments
 (0)