Skip to content

Commit 1296a9d

Browse files
authored
feat(logging): Support functional interface in addition to AspectJ @Logging annotation (#2205)
* Initial version of PowertoolsLogging.initializeLogging API. * Add logging-function E2E tests for new PowertoolsLogging.initializeLogging functional interface. * Add service name env var for powertools-logging unit tests. * Catch NoSuchFileException instead of IOException base class in KeyBufferTest.java. * Catch NoSuchFileException also on cleanup since order of test execution is not guaranteed. * Fix spotbugs issue. This is intended design to support unit tests. The class is in internal package. * Reduce cognitive complexity of LambdaLoggingAspect. * Suppress sonar findings needed for internal unit tests. * Add naming convention findings to sonar ignore list. * Make PowertoolsLogging thread-safe. * Make cold start tracking thread-safe. * Update protobuf generated classes after version bump. * Add merged version bump to non-release e2e logging function handler. * Add withLogging callback based interface to PowertoolsLogging.
1 parent 1e51660 commit 1296a9d

File tree

29 files changed

+1232
-349
lines changed

29 files changed

+1232
-349
lines changed

examples/powertools-examples-kafka/src/main/java/org/demo/kafka/protobuf/ProtobufProduct.java

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/powertools-examples-kafka/src/main/java/org/demo/kafka/protobuf/ProtobufProductOrBuilder.java

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/powertools-examples-kafka/src/main/java/org/demo/kafka/protobuf/ProtobufProductOuterClass.java

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>software.amazon.lambda</groupId>
7+
<artifactId>e2e-test-handlers-parent</artifactId>
8+
<version>2.5.0</version>
9+
</parent>
10+
11+
<artifactId>e2e-test-handler-logging-functional</artifactId>
12+
<packaging>jar</packaging>
13+
<name>E2E test handler – Logging Functional</name>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>software.amazon.lambda</groupId>
18+
<artifactId>powertools-logging-log4j</artifactId>
19+
</dependency>
20+
<dependency>
21+
<groupId>software.amazon.lambda</groupId>
22+
<artifactId>powertools-logging</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>com.amazonaws</groupId>
26+
<artifactId>aws-lambda-java-events</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>com.amazonaws</groupId>
30+
<artifactId>aws-lambda-java-runtime-interface-client</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>com.amazonaws</groupId>
34+
<artifactId>aws-lambda-java-core</artifactId>
35+
</dependency>
36+
</dependencies>
37+
38+
<build>
39+
<plugins>
40+
<plugin>
41+
<groupId>org.apache.maven.plugins</groupId>
42+
<artifactId>maven-shade-plugin</artifactId>
43+
</plugin>
44+
</plugins>
45+
</build>
46+
47+
<profiles>
48+
<profile>
49+
<id>native-image</id>
50+
<build>
51+
<plugins>
52+
<plugin>
53+
<groupId>org.graalvm.buildtools</groupId>
54+
<artifactId>native-maven-plugin</artifactId>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
</profile>
59+
</profiles>
60+
</project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates.
3+
* Licensed under the Apache License, Version 2.0 (the
4+
* "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*
13+
*/
14+
15+
package software.amazon.lambda.powertools.e2e;
16+
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
19+
import org.slf4j.MDC;
20+
21+
import com.amazonaws.services.lambda.runtime.Context;
22+
import com.amazonaws.services.lambda.runtime.RequestHandler;
23+
24+
import software.amazon.lambda.powertools.logging.PowertoolsLogging;
25+
26+
public class Function implements RequestHandler<Input, String> {
27+
private static final Logger LOG = LoggerFactory.getLogger(Function.class);
28+
29+
public String handleRequest(Input input, Context context) {
30+
return PowertoolsLogging.withLogging(context, () -> {
31+
input.getKeys().forEach(MDC::put);
32+
LOG.info(input.getMessage());
33+
34+
// Flush buffer manually since we buffer at INFO level to test log buffering
35+
PowertoolsLogging.flushBuffer();
36+
37+
return "OK";
38+
});
39+
}
40+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates.
3+
* Licensed under the Apache License, Version 2.0 (the
4+
* "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*
13+
*/
14+
15+
package software.amazon.lambda.powertools.e2e;
16+
17+
import java.util.Map;
18+
19+
public class Input {
20+
private String message;
21+
private Map<String, String> keys;
22+
23+
public String getMessage() {
24+
return message;
25+
}
26+
27+
public void setMessage(String message) {
28+
this.message = message;
29+
}
30+
31+
public Map<String, String> getKeys() {
32+
return keys;
33+
}
34+
35+
public void setKeys(Map<String, String> keys) {
36+
this.keys = keys;
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"name":"com.amazonaws.services.lambda.runtime.LambdaRuntime",
4+
"methods":[{"name":"<init>","parameterTypes":[] }],
5+
"fields":[{"name":"logger"}],
6+
"allPublicMethods":true
7+
},
8+
{
9+
"name":"com.amazonaws.services.lambda.runtime.LambdaRuntimeInternal",
10+
"methods":[{"name":"<init>","parameterTypes":[] }],
11+
"allPublicMethods":true
12+
}
13+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[
2+
{
3+
"name": "com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent",
4+
"allDeclaredFields": true,
5+
"allDeclaredMethods": true,
6+
"allDeclaredConstructors": true
7+
},
8+
{
9+
"name": "com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent$ProxyRequestContext",
10+
"allDeclaredFields": true,
11+
"allDeclaredMethods": true,
12+
"allDeclaredConstructors": true
13+
},
14+
{
15+
"name": "com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent$RequestIdentity",
16+
"allDeclaredFields": true,
17+
"allDeclaredMethods": true,
18+
"allDeclaredConstructors": true
19+
},
20+
{
21+
"name": "com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent",
22+
"allDeclaredFields": true,
23+
"allDeclaredMethods": true,
24+
"allDeclaredConstructors": true
25+
},
26+
{
27+
"name": "com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent",
28+
"allDeclaredConstructors": true,
29+
"allPublicConstructors": true,
30+
"allDeclaredMethods": true,
31+
"allPublicMethods": true,
32+
"allDeclaredClasses": true,
33+
"allPublicClasses": true
34+
}
35+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
{
3+
"name":"com.amazonaws.services.lambda.runtime.api.client.runtimeapi.LambdaRuntimeClientException",
4+
"methods":[{"name":"<init>","parameterTypes":["java.lang.String","int"] }]
5+
},
6+
{
7+
"name":"com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.InvocationRequest",
8+
"fields":[{"name":"id"}, {"name":"invokedFunctionArn"}, {"name":"deadlineTimeInMs"}, {"name":"xrayTraceId"}, {"name":"clientContext"}, {"name":"cognitoIdentity"}, {"name": "tenantId"}, {"name":"content"}],
9+
"allPublicMethods":true
10+
}
11+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Args = --initialize-at-build-time=jdk.xml.internal.SecuritySupport

0 commit comments

Comments
 (0)