Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: regression - not possible to log arbitrary objects #880

Closed
dreamorosi opened this issue May 16, 2022 · 2 comments · Fixed by #883
Closed

Bug: regression - not possible to log arbitrary objects #880

dreamorosi opened this issue May 16, 2022 · 2 comments · Fixed by #883
Labels
bug Something isn't working completed This item is complete and has been merged/shipped logger This item relates to the Logger Utility

Comments

@dreamorosi
Copy link
Contributor

dreamorosi commented May 16, 2022

Bug description

After the refactoring introduced in #614 the Logger utility only allows to log values that are of type Error or string.

As such it's not possible anymore to log an arbitrary object, which causes unneeded friction since the point of logger is to promote structured logging.

As a trivial example, I might want to log the event of my function:

logger.debug('Lambda invoked', {
  event: { event }
});

This causes compile errors when using TypeScript (see below for details).

Expected Behavior

  1. Types allow passing strings, Error, and arbitrary objects
  2. Logger parses/structures each type correctly (i.e. strings are appended to a key & not broken down like it used to happen here, Error objects are broken down correctly, other types of objects are appended)

Current Behavior

Argument of type '[{ details: { event: APIGatewayRequestAuthorizerEvent; }; }]' is not assignable to parameter of type 'LogItemExtraInput'.
  Type '[{ details: { event: APIGatewayRequestAuthorizerEvent; }; }]' is not assignable to type '[string | Error]'.
    Type '{ details: { event: APIGatewayRequestAuthorizerEvent; }; }' is not assignable to type 'string | Error'.
      Object literal may only specify known properties, and 'details' does not exist in type 'Error'.ts(2345)

Possible Solution

N/A

Steps to Reproduce

import { APIGatewayRequestAuthorizerEvent } from 'aws-lambda';
import { Logger } from '@aws-lambda-powertools/logger';

const logger = new Logger({ logLevel: 'DEBUG' });

export const handler = async (event:  APIGatewayRequestAuthorizerEvent) => {
  
  logger.debug('Lambda invoked', {
    details: { event }
  });

  return;
};

image

Environment

  • Powertools version used: v0.9.0
  • Packaging format (Layers, npm): npm
  • AWS Lambda function runtime: N/A
  • Debugging logs: N/A

Related issues, RFCs

#565
#614

@dreamorosi dreamorosi added bug Something isn't working triage This item has not been triaged by a maintainer, please wait labels May 16, 2022
@dreamorosi dreamorosi changed the title Bug (logger): short issue description Bug (logger): regression - not possible to log arbitrary objects May 16, 2022
@dreamorosi dreamorosi added the logger This item relates to the Logger Utility label May 16, 2022
@saragerion saragerion added this to the production-ready-release milestone May 16, 2022
@ghost
Copy link

ghost commented May 18, 2022

I'd like to take this one! @dreamorosi, please assign it to me.

@dreamorosi dreamorosi assigned ghost May 18, 2022
@dreamorosi dreamorosi removed the triage This item has not been triaged by a maintainer, please wait label May 18, 2022
@dreamorosi dreamorosi linked a pull request May 18, 2022 that will close this issue
13 tasks
@github-actions
Copy link
Contributor

⚠️ 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.

@dreamorosi dreamorosi changed the title Bug (logger): regression - not possible to log arbitrary objects Bug: regression - not possible to log arbitrary objects Nov 14, 2022
@dreamorosi dreamorosi added the completed This item is complete and has been merged/shipped label Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working completed This item is complete and has been merged/shipped logger This item relates to the Logger Utility
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants