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

Instrumentations are enabled twice on bootstrap #2410

Closed
kkruk-sumo opened this issue Aug 12, 2021 · 5 comments
Closed

Instrumentations are enabled twice on bootstrap #2410

kkruk-sumo opened this issue Aug 12, 2021 · 5 comments
Labels
bug Something isn't working never-stale priority:p3 Bugs which cause problems in user apps not related to correctness (performance, memory use, etc)

Comments

@kkruk-sumo
Copy link
Contributor

What version of OpenTelemetry are you using?

"@opentelemetry/api": "^1.0.2",
"@opentelemetry/instrumentation": "^0.24.0",
"@opentelemetry/instrumentation-document-load": "^0.24.0",
"@opentelemetry/web": "^0.24.0",

What version of Node are you using?

12.7.0

Please provide the code you used to setup the OpenTelemetry SDK

import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { DocumentLoadInstrumentation } from '@opentelemetry/instrumentation-document-load';
import { WebTracerProvider } from '@opentelemetry/web';

const provider = new WebTracerProvider({});

registerInstrumentations({
  tracerProvider: provider,
  instrumentations: [
    new DocumentLoadInstrumentation(),
  ],
});

Then bundled using webpack@^5.50.0.

What did you do?

I run the provided code in Firefox and set breakpoints on enable and disable methods of DocumentLoadInstrumentation.

What did you expect to see?

The DocumentLoadInstrumentation.prototype.enable being called only once.

What did you see instead?

The DocumentLoadInstrumentation.prototype.enable was called twice with no calls on disable.

Additional context

It looks that all instrumentations are enabling twice on bootstrap firstly by InstrumentationBase and secondly by registerInstrumentations.

@kkruk-sumo kkruk-sumo added the bug Something isn't working label Aug 12, 2021
@kkruk-sumo kkruk-sumo changed the title Instrumentations are enabling twice on bootstrap Instrumentations are enabled twice on bootstrap Aug 17, 2021
@legendecas
Copy link
Member

legendecas commented Aug 20, 2021

The problem also prevents derived instrumentation class from defining their own fields, like:

export class SomeInstrumentation extends InstrumentationBase {
  someField: SomeType;
  constructor(someField: SomeType) {
    super(info.name, info.version);
    this.someField = someField;
  }

  enable() {
    // this.someField is not initialized yet.
  }
}

The Instrumentation.enable should be called after the derived class constructor is finished.

@legendecas
Copy link
Member

Currently, the documentation of instrumentation all show two approaches to enable instrumentation:

  1. call instrumentation.enable manually, (https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation#usage-in-web)
  2. use autoLoader: registerInstrumentations({ instrumentations: [new Instrumentation()] }), (https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation#node---auto-loader, https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation-http#usage)

IIUC, it is still left there for compatibility. Maybe it is time to remove the invocation in the InstrumentationBase constructor and the option InstrumentationConfig.enable now.

@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Nov 15, 2021
@github-actions
Copy link

github-actions bot commented Dec 6, 2021

This issue was closed because it has been stale for 14 days with no activity.

@github-actions github-actions bot closed this as completed Dec 6, 2021
@legendecas legendecas reopened this Dec 6, 2021
@legendecas legendecas removed the stale label Dec 6, 2021
@dyladan dyladan added the priority:p3 Bugs which cause problems in user apps not related to correctness (performance, memory use, etc) label Jul 13, 2022
@t2t2
Copy link
Contributor

t2t2 commented Jul 13, 2022

Was brought up in sig today, already fixed in #2610 (10 Nov 2021)

separate question about how good current logic is (as in when enable should be called, during instrumentation instance init or during registerInstrumentation call):

instrumentation config: {enabled: true} {enabled: false}
during new Instrumentation() enable called -
during registerInstrumentation - enable called

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working never-stale priority:p3 Bugs which cause problems in user apps not related to correctness (performance, memory use, etc)
Projects
None yet
Development

No branches or pull requests

5 participants