You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A long form description of this issue is available in #1056. This is an issue that affects all three Powertools utilities because they all share similar implementation for the decorators.
When using Powertools in with a Class and when decorating a method, the decorated method does not have access to the correct value of this and so it's not able to call other methods nor read attributes from its same class.
This is due to the fact that the decorator implementation uses an () => () arrow function instead of a regular function () {} one. This mixes the value of this which then causes the wrong value to be passed.
Additionally there's a missing detail in the documentation of the Class instrumentation that prevents compounds the issue described above.
Expected Behavior
Decorated methods have access to the correct value of this and is able to call methods or access attributes/properties.
The text was updated successfully, but these errors were encountered:
dreamorosi
added
bug
Something isn't working
logger
This item relates to the Logger Utility
triage
This item has not been triaged by a maintainer, please wait
labels
Aug 13, 2022
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
changed the title
Bug (logger): decorated class methods cannot access this
Bug: decorated class methods cannot access this in Logger
Nov 14, 2022
Bug description
A long form description of this issue is available in #1056. This is an issue that affects all three Powertools utilities because they all share similar implementation for the decorators.
When using Powertools in with a Class and when decorating a method, the decorated method does not have access to the correct value of
this
and so it's not able to call other methods nor read attributes from its same class.This is due to the fact that the decorator implementation uses an
() => ()
arrow function instead of a regularfunction () {}
one. This mixes the value ofthis
which then causes the wrong value to be passed.Additionally there's a missing detail in the documentation of the Class instrumentation that prevents compounds the issue described above.
Expected Behavior
Decorated methods have access to the correct value of
this
and is able to call methods or access attributes/properties.Current Behavior
See "Steps to Reproduce" section.
Possible Solution
Apply the same changes done to Tracer in #1055
Steps to Reproduce
The value logged from
![image](https://user-images.githubusercontent.com/7353869/184510410-9b846fb9-c727-4878-b120-266449ca9a9b.png)
console.log(this.getGreeting());
should beHello World
but instead isHello undefined
:Environment
Related issues, RFCs
#1056
The text was updated successfully, but these errors were encountered: