You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(metrics): New metrics module implementation with support for Metrics providers and usage without annotations (#1863)
* Rewrite metrics module with interface abstraction and provider pattern to be able to support multiple metrics providers.
* Update default dimension and namespace logic to have the precedence: @metrics annotation. MetricsLoggerBuilder, Environment variables.
* Small cosmetic changes.
* Add unit tests.
* Update metrics documentation with new interface.
* Make unit tests compatible with GraalVM. It is not supported to mock interface with Mockito.
* Add GraalVM support bullet points to docs pages.
* Update GraalVM metadata files after re-implementing metrics module.
* Fix spotbugs issue. This is expected for this factory class for MetricsLogger to enable user configuration of the MetricsLogger singleton.
* Fix SonarCube findings.
* Rename back namespace to ServerlessAirline example.
* Fix DimensionSet validation to be inline with most recent specification.
* Overload void addDimension(DimensionSet dimensionSet) to be able to add multi-dimensional dimensions also for non default dimensions.
* Update setDefaultDimensions to take a DimensionSet instead of a Map.
* Add warning if not emitting metrics and raiseOnEmptyMetrics is false.
* Remove unused imports.
* Add namespace validation. Refacator into own Validator class. Require namespace to be set or raise an exception otherwise.
* Update docs with DimensionSet.of instead of Map.of. Fix naming consistency.
* Add example for overwriting dimension of cold start metric.
* Add note that metadata needs to be added before flushing.
* Remove test classes from GRM reflect-config.json.
* Rename pushSingleMetric to flushSingleMetric.
* Add example for high cardinality dimensions using DimensionSet.
* Add support for POWERTOOLS_METRICS_DISABLED environment variable.
* Only add service name dimension if the service is actually defined.
* Add support for POWERTOOLS_METRICS_FUNCTION_NAME.
* Add Testing your code section to docs.
* Rename @metrics to @FlushMetrics.
* Rename MetricsLogger to Metrics, rename MetricsLoggerBuilder to MetricsBuilder, rename MetricsLoggerFactory to MetricsFactory.
* Add support for setTimestamp.
* Update regex for namespace validation.
* Fix namespace regex and fix metrics e2e tests.
* Add comment in empty callAt method to satisfy pmd_analyse.
* Replace usages of standalone Powertools wording with alternative wording.
* Reduce cognitive complexity of around() method in LambdaMetricsAspect.
* Re-generate GRM files after applying MetricsLogger renaming.
Copy file name to clipboardExpand all lines: docs/FAQs.md
+23-20Lines changed: 23 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -3,16 +3,15 @@ title: FAQs
3
3
description: Frequently Asked Questions
4
4
---
5
5
6
-
7
6
## How can I use Powertools for AWS Lambda (Java) with Lombok?
8
7
9
-
Powertools uses `aspectj-maven-plugin` to compile-time weave (CTW) aspects into the project. In case you want to use `Lombok` or other compile-time preprocessor for your project, it is required to change `aspectj-maven-plugin` configuration to enable in-place weaving feature. Otherwise the plugin will ignore changes introduced by `Lombok` and will use `.java` files as a source.
8
+
Many utilities in this library use `aspectj-maven-plugin` to compile-time weave (CTW) aspects into the project. In case you want to use `Lombok` or other compile-time preprocessor for your project, it is required to change `aspectj-maven-plugin` configuration to enable in-place weaving feature. Otherwise the plugin will ignore changes introduced by `Lombok` and will use `.java` files as a source.
10
9
11
10
To enable in-place weaving feature you need to use following `aspectj-maven-plugin` configuration:
@@ -29,14 +28,14 @@ To enable in-place weaving feature you need to use following `aspectj-maven-plug
29
28
30
29
## How can I use Powertools for AWS Lambda (Java) with Kotlin projects?
31
30
32
-
Powertools uses `aspectj-maven-plugin` to compile-time weave (CTW) aspects into the project. When using it with Kotlin projects, it is required to `forceAjcCompile`.
33
-
No explicit configuration should be required for gradle projects.
31
+
Many utilities use `aspectj-maven-plugin` to compile-time weave (CTW) aspects into the project. When using it with Kotlin projects, it is required to `forceAjcCompile`.
32
+
No explicit configuration should be required for gradle projects.
34
33
35
34
To enable `forceAjcCompile` you need to use following `aspectj-maven-plugin` configuration:
36
35
37
36
```xml hl_lines="2"
38
37
<configuration>
39
-
<forceAjcCompile>true</forceAjcCompile>
38
+
<forceAjcCompile>true</forceAjcCompile>
40
39
...
41
40
<aspectLibraries>
42
41
<aspectLibrary>
@@ -49,17 +48,17 @@ To enable `forceAjcCompile` you need to use following `aspectj-maven-plugin` con
49
48
50
49
## How can I use Powertools for AWS Lambda (Java) with the AWS CRT HTTP Client?
51
50
52
-
Powertools uses the `url-connection-client` as the default HTTP client. The `url-connection-client` is a lightweight HTTP client, which keeps the impact on Lambda cold starts to a minimum.
53
-
With the [announcement](https://aws.amazon.com/blogs/developer/announcing-availability-of-the-aws-crt-http-client-in-the-aws-sdk-for-java-2-x/) of the `aws-crt-client` a new HTTP client has been released, which offers faster SDK startup time and smaller memory footprint.
51
+
Utilities relying on AWS SDK clients use the `url-connection-client` as the default HTTP client. The `url-connection-client` is a lightweight HTTP client, which keeps the impact on Lambda cold starts to a minimum.
52
+
With the [announcement](https://aws.amazon.com/blogs/developer/announcing-availability-of-the-aws-crt-http-client-in-the-aws-sdk-for-java-2-x/) of the `aws-crt-client` a new HTTP client has been released, which offers faster SDK startup time and smaller memory footprint.
54
53
55
-
Unfortunately, replacing the `url-connection-client` dependency with the `aws-crt-client` will not immediately improve the lambda cold start performance and memory footprint,
56
-
as the default version of the dependency contains native system libraries for all supported runtimes and architectures (Linux, MacOS, Windows, AMD64, ARM64, etc). This makes the CRT client portable, without the user having to consider _where_ their code will run, but comes at the cost of JAR size.
54
+
Unfortunately, replacing the `url-connection-client` dependency with the `aws-crt-client` will not immediately improve the lambda cold start performance and memory footprint,
55
+
as the default version of the dependency contains native system libraries for all supported runtimes and architectures (Linux, MacOS, Windows, AMD64, ARM64, etc). This makes the CRT client portable, without the user having to consider _where_ their code will run, but comes at the cost of JAR size.
57
56
58
57
### Configuring dependencies
59
58
60
-
Using the `aws-crt-client` in your project requires the exclusion of the `url-connection-client` transitive dependency from the powertools dependency.
59
+
Using the `aws-crt-client` in your project requires the exclusion of the `url-connection-client` transitive dependency from the `powertools-*` dependency.
61
60
62
-
```xml
61
+
```xml
63
62
<dependency>
64
63
<groupId>software.amazon.lambda</groupId>
65
64
<artifactId>powertools-parameters</artifactId>
@@ -72,8 +71,9 @@ Using the `aws-crt-client` in your project requires the exclusion of the `url-co
72
71
</exclusions>
73
72
</dependency>
74
73
```
75
-
Next, add the `aws-crt-client` and exclude the "generic" `aws-crt` dependency (contains all runtime libraries).
76
-
Instead, set a specific classifier of the `aws-crt` to use the one for your target runtime: either `linux-x86_64` for a Lambda configured for x86 or `linux-aarch_64` for Lambda using arm64.
74
+
75
+
Next, add the `aws-crt-client` and exclude the "generic" `aws-crt` dependency (contains all runtime libraries).
76
+
Instead, set a specific classifier of the `aws-crt` to use the one for your target runtime: either `linux-x86_64` for a Lambda configured for x86 or `linux-aarch_64` for Lambda using arm64.
77
77
78
78
!!! note "You will need to add a separate maven profile to build and debug locally when your development environment does not share the target architecture you are using in Lambda."
79
79
By specifying the specific target runtime, we prevent other target runtimes from being included in the jar file, resulting in a smaller Lambda package and improved cold start times.
@@ -102,10 +102,11 @@ By specifying the specific target runtime, we prevent other target runtimes from
102
102
```
103
103
104
104
### Explicitly set the AWS CRT HTTP Client
105
-
After configuring the dependencies, it's required to explicitly specify the AWS SDK HTTP client.
106
-
Depending on the Powertools module, there is a different way to configure the SDK client.
107
105
108
-
The following example shows how to use the Lambda Powertools Parameters module while leveraging the AWS CRT Client.
106
+
After configuring the dependencies, it's required to explicitly specify the AWS SDK HTTP client.
107
+
Depending on the utility you are using, there is a different way to configure the SDK client.
108
+
109
+
The following example shows how to use the Parameters module while leveraging the AWS CRT Client.
@@ -141,12 +142,12 @@ public class RequestHandlerWithParams implements RequestHandler<String, String>
141
142
}
142
143
```
143
144
144
-
The `aws-crt-client` was considered for adoption as the default HTTP client in Lambda Powertools for Java as mentioned in [Move SDK http client to CRT](https://github.com/aws-powertools/powertools-lambda-java/issues/1092),
145
+
The `aws-crt-client` was considered for adoption as the default HTTP client in Powertools for AWS Lambda (Java) as mentioned in [Move SDK http client to CRT](https://github.com/aws-powertools/powertools-lambda-java/issues/1092),
145
146
but due to the impact on the developer experience it was decided to stick with the `url-connection-client`.
146
147
147
148
## How can I use Powertools for AWS Lambda (Java) with GraalVM?
148
149
149
-
Powertools core utilities, i.e. [logging](./core/logging.md), [metrics](./core/metrics.md) and [tracing](./core/tracing.md), include the [GraalVM Reachability Metadata (GRM)](https://www.graalvm.org/latest/reference-manual/native-image/metadata/) in the `META-INF` directories of the respective JARs. You can find a working example of Serverless Application Model (SAM) based application in the [examples](../examples/powertools-examples-core-utilities/sam-graalvm/README.md) directory.
150
+
Core utilities, i.e. [logging](./core/logging.md), [metrics](./core/metrics.md) and [tracing](./core/tracing.md), include the [GraalVM Reachability Metadata (GRM)](https://www.graalvm.org/latest/reference-manual/native-image/metadata/) in the `META-INF` directories of the respective JARs. You can find a working example of Serverless Application Model (SAM) based application in the [examples](../examples/powertools-examples-core-utilities/sam-graalvm/README.md) directory.
150
151
151
152
Below, you find typical steps you need to follow in a Maven based Java project:
152
153
@@ -157,6 +158,7 @@ export JAVA_HOME=<path to GraalVM>
157
158
```
158
159
159
160
### Use log4j `>2.24.0`
161
+
160
162
Log4j version `2.24.0` adds [support for GraalVM](https://github.com/apache/logging-log4j2/issues/1539#issuecomment-2106766878). Depending on your project's dependency hierarchy, older version of log4j might be included in the final dependency graph. Make sure version `>2.24.0` of these dependencies are used by your Maven project:
161
163
162
164
```xml
@@ -245,10 +247,11 @@ Create a Docker image using a `Dockerfile` like [this](../examples/powertools-ex
Copy file name to clipboardExpand all lines: docs/core/logging.md
+6-5Lines changed: 6 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,7 @@ Logging provides an opinionated logger with output structured as JSON.
13
13
* Optionally logs Lambda response
14
14
* Optionally supports log sampling by including a configurable percentage of DEBUG logs in logging output
15
15
* Allows additional keys to be appended to the structured log at any point in time
16
+
* GraalVM support
16
17
17
18
18
19
## Getting started
@@ -219,7 +220,7 @@ You can leverage the standard configuration files (_log4j2.xml_ or _logback.xml_
219
220
=== "log4j2.xml"
220
221
221
222
With log4j2, we leverage the [`JsonTemplateLayout`](https://logging.apache.org/log4j/2.x/manual/json-template-layout.html){target="_blank"}
222
-
to provide structured logging. A default template is provided in powertools ([_LambdaJsonLayout.json_](https://github.com/aws-powertools/powertools-lambda-java/tree/v2/powertools-logging/powertools-logging-log4j/src/main/resources/LambdaJsonLayout.json){target="_blank"}):
223
+
to provide structured logging. A default template is provided in powertools ([_LambdaJsonLayout.json_](https://github.com/aws-powertools/powertools-lambda-java/blob/4444b4bce8eb1cc19880d1c1ef07188d97de9126/powertools-logging/powertools-logging-log4j/src/main/resources/LambdaJsonLayout.json){target="_blank"}):
223
224
224
225
```xml hl_lines="5"
225
226
<?xml version="1.0" encoding="UTF-8"?>
@@ -277,7 +278,7 @@ If the level is set to any other value, we set it to the default value (`INFO`).
277
278
<!-- markdownlint-disable MD013 -->
278
279
With [AWS Lambda Advanced Logging Controls (ALC)](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-advanced){target="_blank"}, you can enforce a minimum log level that Lambda will accept from your application code.
279
280
280
-
When enabled, you should keep Powertools and ALC log level in sync to avoid data loss.
281
+
When enabled, you should keep your own log level and ALC log level in sync to avoid data loss.
281
282
282
283
Here's a sequence diagram to demonstrate how ALC will drop both `INFO` and `DEBUG` logs emitted from `Logger`, when ALC log level is stricter than `Logger`.
283
284
<!-- markdownlint-enable MD013 -->
@@ -308,7 +309,7 @@ We prioritise log level settings in this order:
308
309
2. `POWERTOOLS_LOG_LEVEL` environment variable
309
310
3. level defined in the `log4j2.xml` or `logback.xml` files
310
311
311
-
If you set Powertools level lower than ALC, we will emit a warning informing you that your messages will be discarded by Lambda.
312
+
If you set `POWERTOOLS_LOG_LEVEL` lower than ALC, we will emit a warning informing you that your messages will be discarded by Lambda.
312
313
313
314
> **NOTE**
314
315
>
@@ -738,7 +739,7 @@ When debugging in non-production environments, you can instruct the `@Logging` a
738
739
```
739
740
740
741
???+ note
741
-
If you use this on a RequestStreamHandler, Powertools must duplicate input streams in order to log them.
742
+
If you use this on a RequestStreamHandler, the SDK must duplicate input streams in order to log them.
742
743
743
744
## Logging handler response
744
745
@@ -973,7 +974,7 @@ You can also customize how [exceptions are logged](https://logging.apache.org/lo
973
974
See the [JSON Layout template documentation](https://logging.apache.org/log4j/2.x/manual/json-template-layout.html){target="_blank"} for more details.
974
975
975
976
### Logback configuration
976
-
Logback configuration is done in _logback.xml_ and the Powertools [`LambdaJsonEncoder`]():
977
+
Logback configuration is done in _logback.xml_ and the `LambdaJsonEncoder`:
0 commit comments