opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

InstrumentationBase calls init on partly initialized Instrumentations

Open Flarna opened this issue 3 years ago • 4 comments

What version of OpenTelemetry are you using?

0.17.0

What version of Node are you using?

14.16.0

What did you do?

see https://github.com/open-telemetry/opentelemetry-js-contrib/pull/354#discussion_r585913312

Implementing an Instrumentation which uses a private property in init().

What did you expect to see?

Instrumentation should work

What did you see instead?

init() was called before the private property was initialized.

Additional context

  • InstrumentationAbstract declares abstract init()
  • init() most be implemented in a concrete instrumentation class extending InstrumentationBase
  • constructor of InstrumentationBase calls this.init()

==> This result in calling init() of the concrete Instrumentation instance before the constructor has finished. The functions of this instrumentation are in place but the properties are not yet initialized resulting in undefined behavior.

Refs.: https://github.com/microsoft/TypeScript/issues/9209

Flarna avatar Mar 02 '21 21:03 Flarna

@Flarna I believe this has been fixed. Can you confirm if this is still a bug?

dyladan avatar Jul 20 '22 16:07 dyladan

I don't think it's fixed as abstract init is still called from base class constructor here

Flarna avatar Jul 21 '22 05:07 Flarna