feat!: set compilation target to es2022 for all packages but api and semantic-conventions#5456
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5456 +/- ##
==========================================
- Coverage 94.97% 94.95% -0.03%
==========================================
Files 309 309
Lines 7958 7924 -34
Branches 1692 1606 -86
==========================================
- Hits 7558 7524 -34
Misses 400 400 |
…ntelemetry-js into es2022-no-top-level-await
There was a problem hiding this comment.
I'd expect this to break compilation of these two packages:
experimental/backwards-compatibility/node14/tsconfig.json
2: "extends": "../../../tsconfig.base.es5.json",
experimental/backwards-compatibility/node16/tsconfig.json
2: "extends": "../../../tsconfig.base.es5.json",
These are run via npm run test:backcompat ... which I don't be we run automatically anywhere.\
I opened #5460 for this.
These tests are broken and haven't run in ~2y. I don't think this PR needs to worry about this.
There was a problem hiding this comment.
update HTTP instrumentation tests which were failing due to a missing meter provider
I don't see any test failure on "main". I'm not sure what the issue was here.
There was a problem hiding this comment.
Hmm, something seems to be wrong here. 🤔
For some reason, the Instrumentation's metrics instruments seem to be undefined without these changes, which should never be the case. Seems like a bug that surfaced from changing the compile settings.
There was a problem hiding this comment.
this._updateMetricInstruments() is called but does not define the properties on the HttpInstrumentation instance.
There was a problem hiding this comment.
once the base constructor returns, the properties are all undefined. 🤔
There was a problem hiding this comment.
I believe this is due to https://www.typescriptlang.org/tsconfig/#useDefineForClassFields and a simplest fix could be adding the declare modifier to derived instrumentation properties:
export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentationConfig> {
// add a `declare` modifier.
declare private _oldHttpServerDurationHistogram!: Histogram;
}There was a problem hiding this comment.
Confirmed that this diff:
diff --git a/experimental/packages/opentelemetry-instrumentation-http/src/http.ts b/experimental/packages/opentelemetry-instrumentation-http/src/http.ts
index 8f0263251..678e579e8 100644
--- a/experimental/packages/opentelemetry-instrumentation-http/src/http.ts
+++ b/experimental/packages/opentelemetry-instrumentation-http/src/http.ts
@@ -95,10 +95,10 @@ export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentation
/** keep track on spans not ended */
private readonly _spanNotEnded: WeakSet<Span> = new WeakSet<Span>();
private _headerCapture;
- private _oldHttpServerDurationHistogram!: Histogram;
- private _stableHttpServerDurationHistogram!: Histogram;
- private _oldHttpClientDurationHistogram!: Histogram;
- private _stableHttpClientDurationHistogram!: Histogram;
+ declare private _oldHttpServerDurationHistogram: Histogram;
+ declare private _stableHttpServerDurationHistogram: Histogram;
+ declare private _oldHttpClientDurationHistogram: Histogram;
+ declare private _stableHttpClientDurationHistogram: Histogram;and the instr-http tests pass again.
The diff in the generated JS is:
% diff -u build.predeclare/src/http.js build/src/http.js
--- build.predeclare/src/http.js 2025-02-20 13:57:51
+++ build/src/http.js 2025-02-20 13:59:33
@@ -31,10 +31,6 @@
/** keep track on spans not ended */
_spanNotEnded = new WeakSet();
_headerCapture;
- _oldHttpServerDurationHistogram;
- _stableHttpServerDurationHistogram;
- _oldHttpClientDurationHistogram;
- _stableHttpClientDurationHistogram;
_semconvStability = 2 /* SemconvStability.OLD */;
constructor(config = {}) {
super('@opentelemetry/instrumentation-http', version_1.VERSION, config);
Pretty subtle :)
The best full write-up of what is going on is: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier
(linked to from @legendecas' link above). Thanks for the pointer.
commit db71061
There was a problem hiding this comment.
For my feeble memory, the issue is basically this:
class Base {
constructor() {
this._doSomething();
}
_doSomething() {
}
}
class Derived extends Base {
aVar;
constructor() {
super()
}
_doSomething() {
this.aVar = 42;
}
}
var d = new Derived();
console.log('d.aVar:', d.aVar); // get undefined; Using TS class fields before JS had them, this would get 42.…ntelemetry-js into es2022-no-top-level-await
|
It occurred to me that we should also be limiting |
I'll update the |
|
…'api' package This is because the 'api-logs' package will eventually be merged with 'api'. - engines.node: `>=8.0.0` - install `@types/node@8` to avoid the `/// <reference lib=es2020 />` from a more modern types/node package installed in the workspace
…used by tsc compilation)
… match 'api' package
…d semantic-conventions (open-telemetry#5456) Co-authored-by: Trent Mick <trentm@gmail.com>
These changes follow what was done in opentelemetry-js.git. Ref: open-telemetry/opentelemetry-js#5456 Ref: open-telemetry/opentelemetry-js#5145 Ref: open-telemetry/opentelemetry-js#5347
UserInteractionInstrumentation > when zone.js is available > should handle unpatch This was another case of change in semantics of class fields between the old TS way and the new JS way. See where we hit this the core repo: open-telemetry/opentelemetry-js#5456 (comment)
…d semantic-conventions (open-telemetry#5456) Co-authored-by: Trent Mick <trentm@gmail.com>
Which problem is this PR solving?
Sets the compilation target to es2022 to comply with
the guidelinesthe related issue. A cpuple of packages have been kept to targetes2017for compatibility reasons #5393 (comment)Fixes #5393
Closes: #5462
Short description of the changes
es2022es5target for compilation@opentelemetry/apiand@opentelemtry/semantic-conventionstoes2017for backwards compatibilityType of change
Please delete options that are not relevant.
How Has This Been Tested?
@opentelemetry/apiand@opentelemtry/semantic-conventionsif using a feature of es2018 o higher target.Checklist: