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

fix(tracer): captureMethod detects proper method name when used with external decorators #1109

Merged

Conversation

dreamorosi
Copy link
Contributor

Description of your changes

In #1093 it has been reported that the tracer.captureMethod decorator was not properly detecting the name of the decorated class method, causing the name of the segment and the corresponding metadata entry to have an empty name.

I.e.

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 "### "
/**
 * Metadata entry on the segment would be
 * {
 *   "default": {
 *     " response": "foo" <- key should have been `doSomething response`
 *   }
 * }
 *
 */

@misterjoshua, who opened the initial issue, also suggested a potential fix which was used in this PR.

This PR also adds an unit test case to demonstrate the fix.

How to verify this change

See new unit test case that was added in this PR.

Related issues, RFCs

Issue number: #1093

PR status

Is this ready for review?: YES
Is it a breaking change?: NO

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding changes to the examples
  • My changes generate no new warnings
  • The code coverage hasn't decreased
  • I have added tests that prove my change is effective and works
  • New and existing unit tests pass locally and in Github Actions
  • Any dependent changes have been merged and published in downstream module
  • The PR title follows the conventional commit semantics

Breaking change checklist

N/A


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@dreamorosi dreamorosi added the blocked This item's progress is blocked by external dependency or reason label Oct 3, 2022
@dreamorosi dreamorosi self-assigned this Oct 3, 2022
@dreamorosi dreamorosi linked an issue Oct 3, 2022 that may be closed by this pull request
@dreamorosi dreamorosi marked this pull request as ready for review October 3, 2022 17:44
@dreamorosi dreamorosi removed the blocked This item's progress is blocked by external dependency or reason label Oct 3, 2022
@dreamorosi dreamorosi requested a review from ijemmy October 3, 2022 17:44
@github-actions github-actions bot added the bug Something isn't working label Oct 3, 2022
@dreamorosi dreamorosi added the tracer This item relates to the Tracer Utility label Oct 3, 2022
Copy link
Contributor

@misterjoshua misterjoshua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for this.

@saragerion saragerion merged commit a574406 into main Oct 4, 2022
@saragerion saragerion deleted the 1093-bug-tracer-empty-segment-name-when-chaining-decorators branch October 4, 2022 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracer This item relates to the Tracer Utility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: empty segment name when chaining decorators
4 participants