Skip to content

Releases: aws-powertools/powertools-lambda-typescript

v1.4.0

27 Oct 13:04
Compare
Choose a tag to compare

Summary

This release introduces a new feature in Tracer that allows customers to access the AWS X-Ray Root Trace ID. The release also includes a bug fix for Metrics where an issue prevented dimensions and metadata to be cleared on metrics publish. Finally, it also includes some updates to the docs, one of which introduces an example of how to use the Powertools layer with Pulumi.

Tracer

The Tracer utility now has a new public method called getRootXrayTraceId() (docs). With this method you can access the root trace id and use it in your responses or downstream processing as correlation id.

carbon-2

Thank you @misterjoshua for suggesting the feature and helping review the PR.

Metrics

Prior to this release a bug in the Metrics utility prevented metadata and dimensions of metrics to leak between function executions. This was due to a faulty logic that didn't clear properly the two objects when metrics were published. Thanks to @shdq the bug has been fixed and unit tests around the behavior were added. Congrats @shdq for your first PR merged 🎉

Docs

Finally, thanks to @pierskarsenbarg's first contribution to this repo (💯) , the documentation now has an example of how to use the Powertools layer with Pulumi!

carbon

Changes

🌟New features and non-breaking changes

  • feat(all): moved EnvService to commons + exposed getXrayTraceId in tracer (#1123) by @dreamorosi

📜 Documentation updates

🐛 Bug and hot fixes

  • fix(metrics): metadata and dimensions not cleared on publish (#1129) by @shdq

🔧 Maintenance

This release was made possible by the following contributors:

@dreamorosi, @pierskarsenbarg and @shdq

v1.3.0

17 Oct 16:00
Compare
Choose a tag to compare

Summary

This release adds public AWS Lambda Layers, a new feature for Tracer, and bug fixes on all utilities.

AWS Lambda Layers

You can now use AWS Lambda Powertools for TypeScript by adding just a few lines to your configs and using our public AWS Lambda Layers.

Lambda Layer is a .zip file archive that can contain additional code, pre-packaged dependencies, data, or configuration files. Layers promote code sharing and separation of responsibilities so that you can iterate faster on writing business logic.

You can include Lambda Powertools Lambda Layer using AWS Lambda Console, or your preferred deployment framework. Lambda Layers also allow us to understand who uses this library in a non-intrusive way. This helps us justify and gain future investments for other Lambda Powertools languages.

When using AWS SAM or Serverless Framework:

carbon-6

With CDK:

carbon-7

New Features

Tracer

When using the captureMethod decorator on your class method you can now specify a custom name for the subsegment that Tracer generates for you.

You can do so by passing a newly added subSegmentName parameter to the decorator. This is useful for those cases in which the decorated method has an long or non-meaningful name but also in cases in which you want to nest method calls and represent this nesting in the segment names by using different levels of ###/####.

carbon-5

Bug Fixes

Metrics

The Metrics utility has two parameters captureColdStartMetric and throwOnEmptyMetrics that allow respectively to create a cold start metric for those invocations that had an initialization phase, and to throw an error before flushing metrics to ensure that at least one metric is emitted.

Prior to this release there was a bug that caused the parameters to be misinterpreted when passed to the logMetrics middleware. This release ensures that the parameters are parsed correctly and adds additional tests to verify and maintain the behavior.

Logger

The indectLambdaContext decorator allows you to enrich your structured logs with key Lambda context information. The appendKeys method instead allows you to append additional keys and values to logs while within the function handler's scope.

Prior to this release there was a bug that caused some of these additional keys and values to be cleared too soon due to the decorator not awaiting for the decorated method to return. This release fixes the issue and adds tests to prevent future regressions.

Tracer

The captureMethod decorator allows you to trace Class methods and create segments for its operations.

Prior to this release, when using captureMethod with certain 3rd party decorators the name of the decorated method was not detected correctly causing the segment name and its annotation to be mislabeled. This release changes the logic around name detection to ensure names are properly annotated.

Changes

  • Chore(tracer): unit tests to verify decorators await decorated class methods (#1108) by @dreamorosi
  • Fix: standardized and consistent linting strategy across Lerna targets (#1105) by @saragerion

🌟New features and non-breaking changes

📜 Documentation updates

  • docs: update layer version in docs (#1120) by @dreamorosi
  • doc(layer): bump layer version to 2 to match the one built for latest version (1.2.1) (#1113) by @flochaz

🐛 Bug and hot fixes

  • fix(all): update version command to use lint-fix (#1119) by @dreamorosi
  • fix(tracer): captureMethod detects proper method name when used with external decorators (#1109) by @dreamorosi
  • fix(metrics): captureColdStartMetric and throwOnEmptyMetrics when set to false was interpreted as true (#1090) by @flochaz
  • fix(logger): wait for decorated method return before clearing out state (#1087) by @dreamorosi
  • fix(build): remove leftover code in action that labels issues on merge (#1078) by @dreamorosi

🔧 Maintenance

  • fix(all): update version command to use lint-fix (#1119) by @dreamorosi
  • chore(layer): fix bundling and e2e tests by manually setting hash of asset (#1116) by @flochaz
  • chore(build): fix ts-node version for layer-publisher (#1112) by @flochaz
  • build(deps): bump vm2 from 3.9.9 to 3.9.11 (#1094) by @dependabot
  • improv(build): allow to specify PR number when running e2e tests (#1079) by @dreamorosi
  • fix(build): remove leftover code in action that labels issues on merge (#1078) by @dreamorosi
  • chore(build): update make-release.yml to remove redundant publish step (#1075) by @dreamorosi

This release was made possible by the following contributors:

@dreamorosi, @flochaz, @jeffrey-baker-vg and @saragerion

v1.2.1

25 Aug 08:06
Compare
Choose a tag to compare

Summary

We are thrilled to share that we have a new home on Discord!
We hope that this new chapter will allow us to connect and learn from each other, as well as shape together the feature of Powertools.

Join us here: https://discord.gg/B8zZKbbyET

Thanks @sthuber90 for opening the PR to update our docs and adding the new link.

Changes

📜 Documentation updates

This release was made possible by the following contributors:

@sthuber90

v1.2.0

23 Aug 15:24
Compare
Choose a tag to compare

Summary

In this patch release we are updating the Metrics utility to support 3x more dimensions (up to 30) per metric, as well as adding a new way to suppress response capture to Tracer.

Metrics

A few weeks ago Amazon CloudWatch increased metric throughput. This release takes advantage of the new metric dimension to increase our validation limit to 30.

Thank you @sthuber90 for taking this feature and congrats for your first PR in this repo 🎉

Tracer

By default, when using the Tracer as a middleware or as a decorator, the utility captures the response returned by a method or Lambda handler and adds it as metadata on the current segment. This allows you to gain insights about the execution and the results in the context of your traces.

In some instances, for example if the response is too big (> 64 kB), or if it contains sensitive informations, you might want to disable this behavior.

With this release you can use the captureResponse: false option in both tracer.captureLambdaHandler() and tracer.captureMethod() decorators, or use the same option in the Middy captureLambdaHander middleware to instruct Tracer not to serialize function responses as metadata.

carbon

Once again, thank you @misterjoshua for proposing and implementing this behavior 🙌

🌟New features and non-breaking changes

  • feat(metrics): increase maximum dimensions to 29 (#1072) by @sthuber90
  • feat(tracer): allow disabling result capture for decorators and middleware (#1065) by @misterjoshua

🐛 Bug and hot fixes

  • fix(docs): docs published with incorrect version number + api docs missing after release (#1066) by @dreamorosi

This release was made possible by the following contributors:

@dreamorosi, @misterjoshua and @sthuber90

v1.1.1

18 Aug 14:45
Compare
Choose a tag to compare

Summary

This patch release addresses an issue with Lambda handlers written as a class and that uses the Powertools utilities to decorate some of its methods. The defect prevented class members from accessing the class instance and calling other methods or reading attributes.

Thanks to @misterjoshua, we have modified the implementation of the decorator and also improved our documentation to make sure that classes implementing LambdaInterface can work properly. To learn more, check out this issue that contains a more detailed explanation.

import { Tracer } from '@aws-lambda-powertools/tracer';
import { LambdaInterface } from '@aws-lambda-powertools/commons';

const tracer = new Tracer({ serviceName: 'serverlessAirline' });

class Lambda implements LambdaInterface {
    @tracer.captureLambdaHandler()
    public async handler(_event: any, _context: any): Promise<void> {
        /* ... */
    }
}

const handlerClass = new Lambda();
export const handler = handlerClass.handler.bind(handlerClass); // <- Binding your handler method allows your handler to access `this`.

Finally, a big thank you to @misterjoshua who reported the bug, collaborated to the triaging, and submitted a PR proposing a fix 🎉

Changes

📜 Documentation updates

  • chore(tracer): remove redundant export in docs & examples (#1062) by @dreamorosi

🐛 Bug and hot fixes

🔧 Maintenance

  • chore(tracer): remove redundant export in docs & examples (#1062) by @dreamorosi

This release was made possible by the following contributors:

@dreamorosi and @misterjoshua

v1.1.0

12 Aug 12:15
Compare
Choose a tag to compare

Summary

This release contains two bug fixes that were reported by community members:

Over the past weeks the team has also been working on improving and strengthening the security of the CI/CD pipelines that allow to run unit and integration tests, as well as publishing the packages on NPM and the documentation.

Additionally, it contains some initial groundwork that will allow us to publish the libraries as Lambda layers - so stay tuned for news on this topic in the coming weeks!

Finally, a big thank you also to first-time contributors: @tsop14 and @ratscrew 🎉 Thank you for helping improving the library!

Changes

🌟New features and non-breaking changes

  • feat(build): publish lib as a Lambda Layer (#884) by @flochaz

📜 Documentation updates

🐛 Bug and hot fixes

🔧 Maintenance

  • feat(build): publish lib as a Lambda Layer (#884) by @flochaz
  • chore(build): broke up pr workflow & measure package size (#1031) by @dreamorosi
  • chore(ci): housekeeping scripts & workflows related to PRs (#1023) by @dreamorosi

This release was made possible by the following contributors:

@dreamorosi, @flochaz, @ratscrew, @saragerion and @tsop14

v1.0.2

19 Jul 14:49
Compare
Choose a tag to compare

Summary

This release introduces changes entirely related to our documentation and examples.

📚 Documentation improvements 📚

  • Clarified that people can use the library in both TypeScript and JavaScript code bases
  • Added references to the Serverless TypeScript Demo application
  • Added a single copy-paste-able command to install all three utilities at once
  • Added Call to Actions to contribute and help us drive our roadmap
  • Improved consistency with the messaging of the Launch blog post
  • Changed font size and removed the Table of Contents on the right side to improve readability in smaller screens
  • Improved UX when zooming in and scrolling through images
  • Added images in Logger, Tracer and Metrics to showcase outputs in CloudWatch (with ALT)
  • Changed order of examples to: Middy, Decorator, Manual instrumentation
  • Added license link

📚 Examples 📚

Examples in the repository have been updated to use version 1.x 🚀

Changes

📜 Documentation updates

🔧 Maintenance

This release was made possible by the following contributors:

@dreamorosi, @github-actions[bot] and @saragerion

v.1.0.1

19 Jul 14:50
Compare
Choose a tag to compare

Note: Version bump for all packages.

v1.0.0

15 Jul 11:01
Compare
Choose a tag to compare

Changes

With this release, we move from release candidate to General Availability 🎉🎉🎉!

This means APIs for the core utilities Tracer, Logger, and Metrics are now stable and they are ready to be used in AWS Lambda functions written in JavaScript and TypeScript running in production.

Quick links: 📜Documentation | NPM | Feature request | Bug Report

Tracer

🤩 Key features 🤩

  • Auto capture cold start and service name as annotations, and responses or full exceptions as metadata
  • Auto-disable when not running in AWS Lambda environment
  • Automatically trace HTTP(s) clients and generate segments for each request
  • Support tracing functions via decorators, middleware, and manual instrumentation
  • Support tracing AWS SDK v2 and v3 via AWS X-Ray SDK for Node.js
import { Tracer, captureLambdaHandler } from '@aws-lambda-powertools/tracer';
// Using Middy for the first time? Learn more at https://middy.js.org
import middy from '@middy/core';


const tracer = new Tracer();

const lambdaHandler = async (_event: any, _context: any): Promise<void> => {
    /* ... */
};

// Wrap the handler with middy
export const handler = middy(lambdaHandler)
    // Use the middleware by passing the Tracer instance as a parameter
    .use(captureLambdaHandler(tracer));

Logger

🤩 Key features 🤩

  • Capture key fields from Lambda context, cold start and structure logging output as JSON
  • Log Lambda event when instructed (disabled by default)
  • Log sampling prints all the logs for a percentage of invocations (disabled by default)
  • Append additional keys to structured log at any point in time
import { Logger, injectLambdaContext } from '@aws-lambda-powertools/logger';
// Using Middy for the first time? Learn more at https://middy.js.org
import middy from '@middy/core';

const logger = new Logger();

const lambdaHandler = async (_event: any, _context: any): Promise<void> => {
    logger.info('This is an INFO log with some context');
};

// Wrap the handler with middy
export const handler = middy(lambdaHandler)
    .use(injectLambdaContext(logger));

Metrics

🤩 Key features 🤩

  • Aggregate up to 100 metrics using a single CloudWatch EMF object (large JSON blob)
  • Validate against common metric definitions mistakes (metric unit, values, max dimensions, max metrics, etc)
  • Metrics are created asynchronously by CloudWatch service, no custom stacks needed
  • Context manager to create a one off metric with a different dimension
import { Metrics, MetricUnits, logMetrics } from '@aws-lambda-powertools/metrics';
import middy from '@middy/core';

const metrics = new Metrics({ namespace: 'myApplication' });

const lambdaHandler = async (_event: any, _context: any): Promise<void> => {
    metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
};

// Wrap the handler with middy
export const handler = middy(lambdaHandler)
    .use(logMetrics(metrics));

Samples and Starters

https://github.com/awslabs/aws-lambda-powertools-typescript/tree/main/examples
https://github.com/aws-samples/serverless-typescript-demo

🌟Special thank you

We'd like to extend our gratitude to the following people who helped with contributions, feedbacks, and their opinions while we were in developer preview:
@heitorlessa, @AWSDB, @SH4DY, @okoskine, @goverdhan07, @JavierMendozaGomez, @bahrmichael, @alan-churley, @alex-m-aws, @kozub, @roman-boiko, @willfarrell, @lmammino

v0.12.0-rc.1

14 Jul 17:03
Compare
Choose a tag to compare
v0.12.0-rc.1 Pre-release
Pre-release

Summary

In this release candidate version we have made some updates to the documentation to clarify the settings needed for the Tracer utility to work as well as fixing some bugs in both Tracer and Logger that emerged during the testing phase that we have been running in the past weeks.

Changes

🌟New features and non-breaking changes

  • feat(tracer): auto disable when running inside amplify mock (#1010) by @dreamorosi

📜 Documentation updates

🐛 Bug and hot fixes

  • fix(tracer): capture method throws errors correctly (#1016) by @dreamorosi
  • fix(logger): POWERTOOLS_LOGGER_LOG_EVENT precedence is respected (#1015) by @dreamorosi

🔧 Maintenance

This release was made possible by the following contributors:

@dreamorosi, @saragerion