refactor(instrumentation): unify enable/disable lifecycle and default to disabled#278
Draft
overbalance wants to merge 10 commits into
Draft
Conversation
…install side effects
…oss disable/enable
…lone construction
martinkuba
reviewed
May 14, 2026
| // via a `browser` condition, and the public `@opentelemetry/instrumentation` | ||
| // types point at the Node variant (with its own `_enabled` field, `_modules`, | ||
| // etc.) which doesn't match what the bundler actually loads at runtime. | ||
| import { InstrumentationBase as CoreInstrumentationBase } from '@opentelemetry/instrumentation/build/esm/platform/browser/instrumentation.js'; |
Contributor
There was a problem hiding this comment.
Is this true? There are browser-specific exports
https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation/package.json#L19-L23
Contributor
Author
There was a problem hiding this comment.
Yes, it means the actual exports key. TS doesn't follow the browser key to dig out types
martinkuba
reviewed
May 14, 2026
| */ | ||
| export abstract class InstrumentationBase< | ||
| ConfigType extends InstrumentationConfig = InstrumentationConfig, | ||
| > extends CoreInstrumentationBase<ConfigType> { |
Contributor
There was a problem hiding this comment.
I wonder if we could get rid of this core dependency altogether. (Maybe a separate PR)
martinkuba
reviewed
May 14, 2026
| ) { | ||
| super(instrumentationName, instrumentationVersion, { | ||
| ...config, | ||
| enabled: false, |
Contributor
There was a problem hiding this comment.
Why disabled by default?
…server cannot quarantine the rest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which problem is this PR solving?
Each browser instrumentation in this package implemented its own enable/disable bookkeeping. Several used a `declare` field to dodge a class-field-initializer race against the upstream `InstrumentationBase` constructor (which calls `enable()` before subclass fields are populated). State lived in three places at once (`_isEnabled`, `_active`, `_config.enabled`), defaults differed across instrumentations, there was no public `isEnabled()`, and `setConfig` could surprise-enable a disabled instrumentation by omitting the `enabled` key. There was also no shared error-handling story: a throw from a subclass `enable()` or `disable()` could leave an instance silently half-applied with no diagnostic.
Short description of the changes
Test coverage added
Type of change
Note on behavior: instrumentations constructed standalone (without `registerInstrumentations`) used to default to enabled and now default to disabled. `registerInstrumentations` still auto-enables (via its own `!getConfig().enabled` check), so the supported public usage in the README is unchanged. The Lifecycle section in the package README documents the standalone-construction path and the `_canEnable()` veto behavior.
How Has This Been Tested?
Checklist: