|
19 | 19 | import java.io.InputStream;
|
20 | 20 | import java.io.InputStreamReader;
|
21 | 21 | import java.io.OutputStreamWriter;
|
22 |
| -import java.util.Arrays; |
23 | 22 | import java.util.Map;
|
24 | 23 | import java.util.Optional;
|
25 | 24 | import java.util.Random;
|
26 |
| -import java.util.function.Consumer; |
27 |
| -import java.util.function.Predicate; |
28 | 25 |
|
29 | 26 | import com.fasterxml.jackson.core.JsonPointer;
|
30 | 27 | import com.fasterxml.jackson.core.JsonProcessingException;
|
|
39 | 36 | import org.aspectj.lang.annotation.Around;
|
40 | 37 | import org.aspectj.lang.annotation.Aspect;
|
41 | 38 | import org.aspectj.lang.annotation.Pointcut;
|
42 |
| -import software.amazon.lambda.powertools.logging.CorrelationIdPath; |
43 | 39 | import software.amazon.lambda.powertools.logging.Logging;
|
44 | 40 | import software.amazon.lambda.powertools.logging.LoggingUtils;
|
45 | 41 |
|
|
54 | 50 | import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.placedOnRequestHandler;
|
55 | 51 | import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.placedOnStreamHandler;
|
56 | 52 | import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.serviceName;
|
57 |
| -import static software.amazon.lambda.powertools.logging.CorrelationIdPath.AUTO_DETECT; |
58 |
| -import static software.amazon.lambda.powertools.logging.CorrelationIdPath.DISABLED; |
59 | 53 | import static software.amazon.lambda.powertools.logging.LoggingUtils.appendKey;
|
60 | 54 | import static software.amazon.lambda.powertools.logging.LoggingUtils.appendKeys;
|
61 | 55 | import static software.amazon.lambda.powertools.logging.LoggingUtils.objectMapper;
|
@@ -103,7 +97,7 @@ public Object around(ProceedingJoinPoint pjp,
|
103 | 97 | proceedArgs = logEvent(pjp);
|
104 | 98 | }
|
105 | 99 |
|
106 |
| - if (logging.correlationIdPath() != DISABLED) { |
| 100 | + if (!logging.correlationIdPath().isEmpty()) { |
107 | 101 | proceedArgs = captureCorrelationId(logging.correlationIdPath(), pjp);
|
108 | 102 | }
|
109 | 103 |
|
@@ -173,7 +167,7 @@ private Object[] logEvent(final ProceedingJoinPoint pjp) {
|
173 | 167 | return args;
|
174 | 168 | }
|
175 | 169 |
|
176 |
| - private Object[] captureCorrelationId(final CorrelationIdPath correlationIdPath, |
| 170 | + private Object[] captureCorrelationId(final String correlationIdPath, |
177 | 171 | final ProceedingJoinPoint pjp) {
|
178 | 172 | Object[] args = pjp.getArgs();
|
179 | 173 | if (isHandlerMethod(pjp)) {
|
@@ -205,37 +199,17 @@ private Object[] captureCorrelationId(final CorrelationIdPath correlationIdPath,
|
205 | 199 | return args;
|
206 | 200 | }
|
207 | 201 |
|
208 |
| - private void setCorrelationIdFromNode(CorrelationIdPath correlationIdPath, ProceedingJoinPoint pjp, JsonNode jsonNode) { |
209 |
| - if (correlationIdPath == AUTO_DETECT) { |
210 |
| - autoDetect(pjp, jsonNode); |
211 |
| - } else { |
212 |
| - JsonNode node = jsonNode.at(JsonPointer.compile(correlationIdPath.getPath())); |
| 202 | + private void setCorrelationIdFromNode(String correlationIdPath, ProceedingJoinPoint pjp, JsonNode jsonNode) { |
| 203 | + JsonNode node = jsonNode.at(JsonPointer.compile(correlationIdPath)); |
213 | 204 |
|
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 |
| - } |
| 205 | + String asText = node.asText(); |
| 206 | + if (null != asText && !asText.isEmpty()) { |
| 207 | + LoggingUtils.setCorrelationId(asText); |
| 208 | + } else { |
| 209 | + logger(pjp).debug("Unable to extract any correlation id. Is your function expecting supported event type?"); |
220 | 210 | }
|
221 | 211 | }
|
222 | 212 |
|
223 |
| - private void autoDetect(ProceedingJoinPoint pjp, |
224 |
| - JsonNode jsonNode) { |
225 |
| - Arrays.stream(CorrelationIdPath.values()) |
226 |
| - .filter(path -> path != AUTO_DETECT && path != DISABLED) |
227 |
| - .forEach(correlationIdPath1 -> { |
228 |
| - JsonNode node = jsonNode.at(JsonPointer.compile(correlationIdPath1.getPath())); |
229 |
| - String asText = node.asText(); |
230 |
| - |
231 |
| - if (null != asText && !asText.isEmpty()) { |
232 |
| - logger(pjp).debug("Auto detected correlation id from event type: {}", correlationIdPath1); |
233 |
| - LoggingUtils.setCorrelationId(asText); |
234 |
| - } |
235 |
| - }); |
236 |
| - } |
237 |
| - |
238 |
| - |
239 | 213 | private Object[] logFromInputStream(final ProceedingJoinPoint pjp) {
|
240 | 214 | Object[] args = pjp.getArgs();
|
241 | 215 |
|
|
0 commit comments