Skip to content

v2.5.0

Latest

Choose a tag to compare

@github-actions github-actions released this 21 Oct 13:33
· 16 commits to refs/heads/main since this release
326f4b8

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

Docs

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

Lambda SnapStart AWS Docs

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

📜 Documentation updates

This release was made possible by the following contributors:

@ConnorKirk, @humanzz, @kjswaruph, @kylez-ithaka, @phipag, @sthulb