Summary
In this release, we improve the experience with Metrics simplifying flushing metrics with a custom configuration. Additionally, we keep raising the performance bar by extending SnapStart priming to the Kafka utility.
📜 Announcement: You can now find our documentation on the official AWS documentation domain at docs.aws.amazon.com/powertools/java.
⭐️⭐️⭐️⭐️ Thanks to @humanzz, @kjswaruph, @kylez-ithaka, and @ConnorKirk for their contributions to this release!
📊 Metrics utility: New flushMetrics API
You can now flush multiple metrics at once with flushMetrics. This method gives you full control over dimensions, namespaces, and metadata before sending metrics, simplifying metrics handling for complex scenarios. In previous versions, you needed to use flushSingleMetric to emit one metric with its own setup, which limited flexibility and performance in multi-metric scenarios and required more manual management.
As before, the following inheritance rules apply for values not overwritten within the Consumer:
- Namespace copied if not overwritten
- Default dimensions copied if not overwritten
- Regular dimensions not copied
- Metadata copied
The following example shows how to emit multiple metrics in a single flush with custom dimensions, namespace, and metadata:
public class App implements RequestHandler<Object, Object> {
private static final Metrics metrics = MetricsFactory.getMetricsInstance();
@Override
@FlushMetrics(namespace = "ServerlessAirline", service = "payment")
public Object handleRequest(Object input, Context context) {
metrics.flushMetrics((customMetrics) -> {
customMetrics.addMetric("CustomMetric1", 1, MetricUnit.COUNT);
customMetrics.addMetric("CustomMetric2", 2, MetricUnit.COUNT);
// To optionally set a different namespace
customMetrics.setNamespace("CustomNamespace");
// To optionally set different default dimensions
customMetrics.setDefaultDimensions(DimensionSet.of("CustomDefaultDimension", "value"));
// To optionally append additional dimensions to (inherited) default dimensions
customMetrics.addDimension(DimensionSet.of("CustomDimension", "value"));
// To optionally add additional metadata (visible in logs only)
customMetrics.addMetadata("CustomMetadata", "value"));
});
}
}Note: While flushSingleMetric is maintained for backwards compatibility, flushMetrics is now the recommended way to emit metrics with a custom configuration.
⚡ Lambda SnapStart Priming
SnapStart reduces Lambda cold start times by taking a snapshot of your initialized function and reusing it for subsequent invocations. We can run custom code before the snapshot is taken to initialize code that would otherwise be initialized at runtime. This process is referred to as "priming", and this is achieved using Java runtime hooks from the open source CRaC (Coordinated Restore at Checkpoint) project.
This release automatically primes the Kafka utility without any code modifications needed.
🧑💻 Want to contribute? Learn more about implementing priming techniques in our Priming documentation for contributors. We're actively working on extending SnapStart priming support across all utilities and are looking for contributors to help with this effort. Check out our project issues to see how you can get involved!
Changes
- chore(ci): bump version to 2.5.0 (#2220) by @github-actions[bot]
- chore(ci): Move tag step before changelog generation. (#2219) by @phipag
- chore(ci): Fix sha256 formatting in git-chglog docker image reference (#2218) by @phipag
- chore: bump org.codehaus.mojo:exec-maven-plugin from 3.5.1 to 3.6.2 (#2208) by @dependabot[bot]
- chore(ci): fix changelog generation (#2207) by @sthulb
- chore(tests): Fix flaky unit tests when truncating files (#2211) by @phipag
- chore: bump github/codeql-action from 4.30.8 to 4.30.9 (#2209) by @dependabot[bot]
- chore: bump sam/build-java21 from
1d40149toe12c501in /powertools-e2e-tests/src/test/resources/docker (#2201) by @dependabot[bot] - chore: bump org.sonatype.central:central-publishing-maven-plugin from 0.8.0 to 0.9.0 (#2196) by @dependabot[bot]
- chore: bump aws.sdk.version from 2.35.7 to 2.35.8 (#2197) by @dependabot[bot]
- chore: bump com.google.protobuf:protobuf-java from 4.32.1 to 4.33.0 (#2198) by @dependabot[bot]
- chore: Update contributing.md (#2203) by @ConnorKirk
- feat: add CRaC priming support to powertools-kafka module (#2145) by @kjswaruph
- chore: bump aws.sdk.version from 2.35.6 to 2.35.7 (#2190) by @dependabot[bot]
- chore: bump com.networknt:json-schema-validator from 1.5.8 to 1.5.9 (#2189) by @dependabot[bot]
- chore: bump sam/build-java21 from
fd3b445to1d40149in /powertools-e2e-tests/src/test/resources/docker (#2195) by @dependabot[bot] - chore: bump squidfunk/mkdocs-material from
00f9276tof5c556ain /docs (#2194) by @dependabot[bot] - chore: bump com.github.spotbugs:spotbugs-maven-plugin from 4.9.4.2 to 4.9.7.0 (#2192) by @dependabot[bot]
- chore: bump software.amazon.awscdk:aws-cdk-lib from 2.214.0 to 2.220.0 (#2191) by @dependabot[bot]
- chore: bump io.github.ascopes:protobuf-maven-plugin from 3.10.0 to 3.10.2 (#2193) by @dependabot[bot]
- chore: bump aws.xray.recorder.version from 2.19.0 to 2.20.0 (#2185) by @dependabot[bot]
- improv: Make trace id access more robust. (#2188) by @phipag
- chore(deps): Use mockito 5.20.0 (#2181) by @phipag
- chore: bump org.apache.maven.plugins:maven-javadoc-plugin from 3.11.3 to 3.12.0 (#2186) by @dependabot[bot]
- chore: bump org.assertj:assertj-core from 3.27.4 to 3.27.6 (#2184) by @dependabot[bot]
- chore: bump aws.sdk.version from 2.34.9 to 2.35.6 (#2183) by @dependabot[bot]
- chore: bump actions/dependency-review-action from 4.8.0 to 4.8.1 (#2180) by @dependabot[bot]
- chore: bump github/codeql-action from 3.30.5 to 4.30.8 (#2179) by @dependabot[bot]
- chore: bump aws-actions/configure-aws-credentials from 5.0.0 to 5.1.0 (#2177) by @dependabot[bot]
- chore: bump com.google.protobuf:protobuf-java from 4.32.0 to 4.32.1 (#2175) by @dependabot[bot]
- chore: bump aws.sdk.version from 2.34.5 to 2.34.9 (#2174) by @dependabot[bot]
- chore: bump org.apache.commons:commons-lang3 from 3.18.0 to 3.19.0 (#2172) by @dependabot[bot]
- chore: bump org.apache.maven.plugins:maven-artifact-plugin from 3.6.0 to 3.6.1 (#2171) by @dependabot[bot]
- chore: Add User-Agent execution interceptors (#2166) by @phipag
- chore: bump graalvm/setup-graalvm from 1.3.6 to 1.4.1 (#2168) by @dependabot[bot]
- chore: bump ossf/scorecard-action from 2.4.2 to 2.4.3 (#2165) by @dependabot[bot]
- chore: bump squidfunk/mkdocs-material from
86d21dato00f9276in /docs (#2164) by @dependabot[bot] - chore: bump log4j.version from 2.25.1 to 2.25.2 (#2160) by @dependabot[bot]
- chore: bump org.apache.maven.plugins:maven-failsafe-plugin from 3.5.3 to 3.5.4 (#2159) by @dependabot[bot]
- chore: bump actions/dependency-review-action from 4.7.3 to 4.8.0 (#2158) by @dependabot[bot]
- chore: bump github/codeql-action from 3.30.1 to 3.30.5 (#2157) by @dependabot[bot]
- chore: bump io.github.ascopes:protobuf-maven-plugin from 3.9.0 to 3.10.0 (#2155) by @dependabot[bot]
- chore: bump com.amazonaws:aws-lambda-java-runtime-interface-client from 2.8.3 to 2.8.6 (#2149) by @dependabot[bot]
- chore: bump aws.sdk.version from 2.33.2 to 2.34.5 (#2156) by @dependabot[bot]
- feat(metrics): introduce Metrics.flushMetrics (#2154) by @humanzz
- docs(logger): fix logging environment variables names (#2161) by @kylez-ithaka
- chore: bump org.codehaus.mojo:versions-maven-plugin from 2.18.0 to 2.19.1 (#2148) by @dependabot[bot]
- chore: bump squidfunk/mkdocs-material from
209b62dto86d21dain /docs (#2144) by @dependabot[bot] - chore: bump tj-actions/changed-files from 46.0.5 to 47.0.0 (#2143) by @dependabot[bot]
- chore: bump sam/build-java21 from
853ac90tofd3b445in /powertools-e2e-tests/src/test/resources/docker (#2141) by @dependabot[bot] - chore: bump com.amazonaws:aws-lambda-java-core from 1.3.0 to 1.4.0 (#2135) by @dependabot[bot]
- chore: bump org.apache.kafka:kafka-clients from 4.0.0 to 4.1.0 (#2134) by @dependabot[bot]
- chore: bump aws.sdk.version from 2.33.2 to 2.33.5 (#2132) by @dependabot[bot]
- chore(ci): bump version to 2.4.0 (#2139) by @github-actions[bot]
📜 Documentation updates
- chore(docs): Add AWS docs meta tags (#2170) by @phipag
- chore(docs): Migrate docs JS to AWS Docs (#2169) by @phipag
This release was made possible by the following contributors:
@ConnorKirk, @humanzz, @kjswaruph, @kylez-ithaka, @phipag, @sthulb