powertools-lambda-typescript icon indicating copy to clipboard operation
powertools-lambda-typescript copied to clipboard

Bug (all) : Unexpected PowerTools behaviours when leveraging the default SAM TypeScript template with SAM ESBuild support enabled

Open DomSearle opened this issue 3 years ago • 3 comments

Summary

When using the SAM "Hello World Example TypeScript TS" template with ESBuild support enabled various PowerTools anomalies are observed.

Configuration

aws-lambda-powertools ^1.0.2 middy/core": ^3.1.1 sam cli 1.53.0 nodejs14.x

Bug description

Various documented PowerTools expected behaviours are not operating as expected when leveraging the default SAM TypeScript template ". ESBuild beta support has been enabled.

Logger Example : Powertools logger does not log the expected additional Lambda context information when configured according to the documentation.

Example of log keys generated

{
  "level": "INFO",
  "message": "Example INFO log missing  context",
  "service": "PowerToolsLoggerExample",
  "timestamp": "2022-08-11T09:43:16.307Z",
  "xray_trace_id": "1-62f4cf33-4e8360c401b2c85f2521113c"
}

Expected log keys generated

{
    "cold_start": true,
    "function_arn": "arn:aws:lambda:eu-west-1:123456789012:function:shopping-cart-api-lambda-prod-eu-west-1",
    "function_memory_size": 128,
    "function_request_id": "c6af9ac6-7b61-11e6-9a41-93e812345678",
    "function_name": "shopping-cart-api-lambda-prod-eu-west-1",
    "level": "INFO",
    "message": "This is an INFO log with some context",
    "service": "serverlessAirline",
    "timestamp": "2021-12-12T21:21:08.921Z",
    "xray_trace_id": "abcdef123456abcdef123456abcdef123456"
}

Steps to Reproduce

  1. Build a new SAM project leveraging the default TypeScript template "Hello World Example TypeScript"
  2. Enable es2020 support in SAM template.yaml
 Metadata: # Manage esbuild properties
      BuildMethod: esbuild
      BuildProperties:
        Minify: true
        Target: "es2020"
        Sourcemap: true
  1. Configure PowerTools logger as per documentation and generate a log. Observe the missing context information.

DomSearle avatar Aug 11 '22 14:08 DomSearle

HI @DomSearle,

thanks for reporting the issue. I will look into this and get back to you as soon as I have reproduced it.

bpauwels avatar Aug 11 '22 14:08 bpauwels

Thanks. I have been working internally with Andrea Amorosi on this and he has a copy of my code repo if helpful.

DomSearle avatar Aug 11 '22 15:08 DomSearle

Thank you @DomSearle, yes, I have already talked with Benedikt and shared your repo with them as well all the other details shared in the Slack thread.

dreamorosi avatar Aug 11 '22 15:08 dreamorosi

As already discussed in private, @DomSearle, please check that the Handler defined in template.yaml matches the actual handler exported in your function code. Issue can be closed!

bpauwels avatar Aug 15 '22 15:08 bpauwels

Thanks @bpauwels for your assistance in resolving my local configuration issue. Closing as not a bug.

DomSearle avatar Aug 15 '22 15:08 DomSearle

⚠️ COMMENT VISIBILITY WARNING ⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Aug 15 '22 15:08 github-actions[bot]

@bpauwels can you share the resolution steps/details in this issue?

Maybe it'll be helpful to others in the future.

dreamorosi avatar Aug 15 '22 15:08 dreamorosi

For posterity: no resolution steps are needed as this was due to a small misnaming in the IaC config.

saragerion avatar Aug 16 '22 11:08 saragerion