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

ES6 private members are unusable if class extends "InstrumentationBase" #3837

Closed
Lodin opened this issue May 25, 2023 · 3 comments
Closed

ES6 private members are unusable if class extends "InstrumentationBase" #3837

Lodin opened this issue May 25, 2023 · 3 comments
Labels
bug Something isn't working priority:p4 Bugs and spec inconsistencies which do not fall into a higher prioritization

Comments

@Lodin
Copy link

Lodin commented May 25, 2023

What happened?

I want to use ES6 private members in the class that extends InstrumentationBase. However, I cannot use them in the overridden enable method in the config because the super constructor calls it beforehand, and the call fails.

Steps to Reproduce

class Foo extends InstrumentationBase {
  constructor(config: InstrumentationConfig = {}) {
    super('foo', '0.1.0', config);
  }

  override enable() {
    this.#bar();
  }

  #bar() {
    console.log('bar');
  }
}

const foo = new Foo();

Expected Result

The bar string is printed in the console.

Actual Result

Fails with the error:

Uncaught TypeError: Receiver must be an instance of class Foo

OpenTelemetry Setup Code

No response

package.json

No response

Relevant log output

No response

@Lodin Lodin added bug Something isn't working triage labels May 25, 2023
@Flarna
Copy link
Member

Flarna commented May 26, 2023

This might be the same/similar as #1989

@dyladan dyladan self-assigned this May 31, 2023
@pichlermarc pichlermarc added priority:p4 Bugs and spec inconsistencies which do not fall into a higher prioritization up-for-grabs Good for taking. Extra help will be provided by maintainers and removed triage labels Jun 21, 2023
@MSNev
Copy link
Contributor

MSNev commented Jun 21, 2023

This is because the base class is calling the function (which is not a unique issue to TypeScript / JavaScript).

For this particular issue (overriding enable) you could call the super with the config configured to specify that it's not enabled, then call this.enable yourself, making sure that your override also calls the super.enable() in the process.

@Lodin
Copy link
Author

Lodin commented Jun 25, 2023

@MSNev, yeah, it looks like the best option. Thanks.

Please, feel free to close the ticket.

@pichlermarc pichlermarc removed the up-for-grabs Good for taking. Extra help will be provided by maintainers label Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority:p4 Bugs and spec inconsistencies which do not fall into a higher prioritization
Projects
None yet
Development

No branches or pull requests

5 participants