Skip to content

Bug: empty segment name when chaining decorators #1093

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

Closed
misterjoshua opened this issue Sep 19, 2022 · 2 comments · Fixed by #1109
Closed

Bug: empty segment name when chaining decorators #1093

misterjoshua opened this issue Sep 19, 2022 · 2 comments · Fixed by #1109
Assignees
Labels
bug Something isn't working completed This item is complete and has been merged/shipped tracer This item relates to the Tracer Utility

Comments

@misterjoshua
Copy link
Contributor

misterjoshua commented Sep 19, 2022

Bug description

I wanted to capture all the retries of a method that uses a decorator to implement async retries. #1084 (comment) However, when the tracer tries to determine the segment name, it doesn't find the name of the original method.

Expected Behavior

I expected the segment name to use the original method name.

Current Behavior

It uses the name of the other decorator's anonymous function instead of the original method's function. An anonymous function's name is empty, so the segment name is empty.

Possible Solution

Use String(_propertyKey) instead of originalMethod.name here: https://github.com/awslabs/aws-lambda-powertools-typescript/blob/06fbaae4db3825557aa84d40372a53422e42840d/packages/tracer/src/Tracer.ts#L437

Steps to Reproduce

const tracer = new Tracer();

function passThrough() {
  // A decorator that calls the original method.
  return (_target: unknown, _propertyKey: string, descriptor: PropertyDescriptor) => {
    const originalMethod = descriptor.value!;
    descriptor.value = function (...args: unknown[]) {
      return originalMethod.apply(this, [...args]);
    };
  };
}

class MyClass {
  @tracer.captureMethod()
  @passThrough()
  async doSomething(): Promise<string> {
    return 'foo';
  }
}

const myClass = new MyClass();
await myClass.doSomething();

// Segment name will be "### "

Environment

  • Powertools version used: 1.2.1
  • Packaging format (Layers, npm): npm
  • AWS Lambda function runtime: node 16
  • Debugging logs:

Related issues, RFCs

None

@misterjoshua misterjoshua added bug Something isn't working triage This item has not been triaged by a maintainer, please wait labels Sep 19, 2022
@dreamorosi
Copy link
Contributor

Hi @misterjoshua, thanks a lot for opening this issue!

I was able to reproduce the behaviour described and I agree that things could be improved.

I'm waiting for the current PRs to be reviewed/merged before proposing a fix.

@dreamorosi dreamorosi self-assigned this Sep 27, 2022
@dreamorosi dreamorosi added tracer This item relates to the Tracer Utility and removed triage This item has not been triaged by a maintainer, please wait labels Sep 27, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Oct 4, 2022

⚠️ 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 github-actions bot added the pending-release This item has been merged and will be released soon label Oct 4, 2022
@dreamorosi dreamorosi removed the pending-release This item has been merged and will be released soon label Oct 27, 2022
@dreamorosi dreamorosi added the completed This item is complete and has been merged/shipped label Nov 14, 2022
@dreamorosi dreamorosi changed the title Bug (Tracer): empty segment name when chaining decorators Bug: empty segment name when chaining decorators 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 tracer This item relates to the Tracer Utility
Projects
None yet
2 participants