aws-powertools / powertools-lambda-typescript

Powertools is a developer toolkit to implement Serverless best practices and increase developer velocity.
https://docs.powertools.aws.dev/lambda/typescript/latest/
MIT No Attribution
1.55k stars 134 forks source link

Feature request: HTTP request/response annotations #1179

Open revmischa opened 1 year ago

revmischa commented 1 year ago

Use case

I have a nextjs CDK construct with a simple APIGW lambda wrapper around nextjs. I want to annotate my traces with HTTP request and response metadata, e.g. "URL" and "method" and "status code"

I would like to use it here: https://github.com/jetbridge/cdk-nextjs/blob/main/assets/lambda/NextJsHandler.ts#L45

I'd like to see the status code, path, method, etc in xray: image

Solution/User Experience

Perhaps something like traceRequestResponseCycle in https://docs.aws.amazon.com/xray-sdk-for-nodejs/latest/reference/AWSXRay.html

Alternative solutions

Discussed on discord: https://discord.com/channels/1006478942305263677/1006527385409179678/1042309163818168380

Acknowledgment

dreamorosi commented 1 year ago

Hi @revmischa thank you for taking the time to open a feature request.

As I have briefly mentioned on Discord: at the moment we don't use any of the middleware features from aws-xray-sdk so I'm unsure on how it will behave with Tracer. With that said, a first cursory look at traceRequestResponseCycle's implementation suggests that the utility provides some syntactic sugar around segment manipulation/annotation, which bodes well for Powertools compatibility.

Before considering the feature and putting it into the backlog, I would like some investigation to take place to make a small PoC and understand the impact and compatibility of this feature with Powertools.

Like with all features, contributions are more than welcome, and in case this is left to the maintainers, having 👍 on the feature request will help increasing its priority in our backlog.

If anyone is interested in picking up this issue, please leave a comment below to express your interest and agree on next steps. The maintainers will be happy to support you with clearing doubts or questions on the scope and codebase.

revmischa commented 1 year ago

For my purposes a simpler version of this would be to let me manually set the HTTP path, method, status code directly on the segment. But I have no idea how to do this and couldn't find any documentation on how to manually set those attributes.

kennethwkz-mm commented 1 year ago

this is https://www.npmjs.com/package/aws-xray-sdk-express feature, this is very useful when we are tracing some ip address or api URL in a easy way

dreamorosi commented 1 year ago

FYI @revmischa, I have been looking at the aws-sdk-for-nodejs implementation to see if I could find a way to make it work for Tracer without changes but didn't have much luck.

I'll keep looking, also using the example that was just posted above.

github-actions[bot] commented 1 year ago

This issue has not received a response in 2 weeks. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

revmischa commented 1 year ago

Please keep open

github-actions[bot] commented 1 year ago

This issue has not received a response in 2 weeks. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.