-
Notifications
You must be signed in to change notification settings - Fork 806
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
Invalid types in Node SDK? #5062
Comments
Also the boxes to fill in the package.json etc seem uneditable in the form? |
Hm, maybe my browser just bugged out |
@robcresswell does this also happen on a clean reinstall of the dependencies? (removed package-lock.json and node_modules). Would you mind showing us the npm ls output so we can further investigate? 🤔 |
FWIW, I was not able to reproduce as follows:
{
"name": "asdf.20241016t084622",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/exporter-trace-otlp-grpc": "^0.53.0",
"@opentelemetry/instrumentation-fastify": "^0.40.0",
"@opentelemetry/instrumentation-grpc": "^0.53.0",
"@opentelemetry/instrumentation-http": "^0.53.0",
"@opentelemetry/instrumentation-pg": "^0.45.0",
"@opentelemetry/resources": "^1.26.0",
"@opentelemetry/sdk-node": "^0.53.0",
"@opentelemetry/sdk-trace-node": "^1.26.0",
"@opentelemetry/semantic-conventions": "^1.27.0"
}
}
import {NodeSDK} from '@opentelemetry/sdk-node';
import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
import {Resource} from '@opentelemetry/resources'
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { FastifyInstrumentation } from '@opentelemetry/instrumentation-fastify';
import { PgInstrumentation } from '@opentelemetry/instrumentation-pg';
export function register() {
const sdk = new NodeSDK({
resource: new Resource({
'service.name': 'service',
}),
instrumentations: [
new HttpInstrumentation(),
new FastifyInstrumentation(),
new PgInstrumentation(),
],
spanProcessors: [new SimpleSpanProcessor(new OTLPTraceExporter())],
});
sdk.start();
}
register(); % npm install
...
% npm ls
[email protected] /Users/trentm/tmp/asdf.20241016T084622
├── @opentelemetry/[email protected]
├── @opentelemetry/[email protected]
├── @opentelemetry/[email protected]
├── @opentelemetry/[email protected]
├── @opentelemetry/[email protected]
├── @opentelemetry/[email protected]
├── @opentelemetry/[email protected]
├── @opentelemetry/[email protected]
├── @opentelemetry/[email protected]
└── @opentelemetry/[email protected]
% node reg-issue-5062.mjs
% |
I'm unable to recreate this now unfortunately, though I did try clearing node_modules, cache etc at the time. I'm not sure whats shifted in the past week, but it all seems happy now. |
Okay, I've managed to recreate this.
{
"name": "repro",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/exporter-trace-otlp-grpc": "^0.54.0",
"@opentelemetry/instrumentation-fastify": "^0.40.0",
"@opentelemetry/instrumentation-grpc": "^0.53.0",
"@opentelemetry/instrumentation-http": "^0.54.0",
"@opentelemetry/instrumentation-pg": "^0.46.0",
"@opentelemetry/resources": "^1.27.0",
"@opentelemetry/sdk-node": "^0.53.0",
"@opentelemetry/sdk-trace-node": "^1.27.0",
"@opentelemetry/semantic-conventions": "^1.27.0"
}
}
{
"compilerOptions": {
"outDir": "./dist",
"target": "ES2022",
"lib": ["ES2023"],
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
},
"include": ["index.ts"],
}
import { NodeSDK } from '@opentelemetry/sdk-node';
import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
import { Resource } from '@opentelemetry/resources'
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { FastifyInstrumentation } from '@opentelemetry/instrumentation-fastify';
import { PgInstrumentation } from '@opentelemetry/instrumentation-pg';
export function register() {
const sdk = new NodeSDK({
resource: new Resource({
'service.name': 'service',
}),
instrumentations: [
new HttpInstrumentation(),
new FastifyInstrumentation(),
new PgInstrumentation(),
],
spanProcessors: [new SimpleSpanProcessor(new OTLPTraceExporter())],
});
sdk.start();
}
register(); |
The TS error mentions that the npm ls @opentelemetry/sdk-trace-base
[email protected] /Users/david/Documents/issues/otel/5062-core
├─┬ @opentelemetry/[email protected]
│ ├─┬ @opentelemetry/[email protected]
│ │ └── @opentelemetry/[email protected] deduped
│ └── @opentelemetry/[email protected]
├─┬ @opentelemetry/[email protected]
│ ├─┬ @opentelemetry/[email protected]
│ │ └─┬ @opentelemetry/[email protected]
│ │ └── @opentelemetry/[email protected]
│ ├─┬ @opentelemetry/[email protected]
│ │ └─┬ @opentelemetry/[email protected]
│ │ └── @opentelemetry/[email protected]
│ ├─┬ @opentelemetry/[email protected]
│ │ ├─┬ @opentelemetry/[email protected]
│ │ │ └── @opentelemetry/[email protected] deduped
│ │ └── @opentelemetry/[email protected]
│ ├─┬ @opentelemetry/[email protected]
│ │ ├─┬ @opentelemetry/[email protected]
│ │ │ └── @opentelemetry/[email protected] deduped
│ │ └── @opentelemetry/[email protected] deduped
│ ├─┬ @opentelemetry/[email protected]
│ │ ├─┬ @opentelemetry/[email protected]
│ │ │ └── @opentelemetry/[email protected] deduped
│ │ └── @opentelemetry/[email protected]
│ ├─┬ @opentelemetry/[email protected]
│ │ ├─┬ @opentelemetry/[email protected]
│ │ │ └── @opentelemetry/[email protected] deduped
│ │ └── @opentelemetry/[email protected]
│ ├─┬ @opentelemetry/[email protected]
│ │ └── @opentelemetry/[email protected]
│ ├── @opentelemetry/[email protected]
│ └─┬ @opentelemetry/[email protected]
│ └── @opentelemetry/[email protected] deduped
└─┬ @opentelemetry/[email protected]
└── @opentelemetry/[email protected] deduped We see that
is not optimal but I think it shouldn't be an issue. A quick workaround would be to remove I'll continue the investigation a bit more to see if there is a way to make it work. |
Apparently TS doesn't like identical type declarations from different places if they contain private properties. I've created a repository which reproduces the issue. In the first commit the same error is raised by TS. The second commit makes the error go away. As per my previous comment this happens because there are 2 versions of
TS resolves the import to the package installed at the top (1.27.0) but SDK constructor expects the one installed within its dependencies. Both type declarations are in different paths and, although they are compatible, the error appears.
I guess the majority of users just want to setup the instrumentation so I think this not a workaround but the solution to their problem. But for other uses that might be annoying. If for some reason I need to install Should we allow users to have different versions installed? 🤔 @open-telemetry/javascript-maintainers thoughts? |
Usually that's not supported (yet). That's actually one of the big things that we're trying to solve with SDK 2.0 by (ideally) not exporting any classes directly, but using interfaces instead (that's one of the reasons for #3597, my proposal at #4932). Interfaces don't have that problem as we cant declare private properties on them. So even if they come from different package versions IF we adhere to semver and only add optional properties. |
What happened?
Steps to Reproduce
I've got a fairly straightforward setup, I hope:
which gives me the following type error:
OpenTelemetry Setup Code
No response
package.json
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/exporter-trace-otlp-grpc": "^0.53.0",
"@opentelemetry/instrumentation-fastify": "^0.40.0",
"@opentelemetry/instrumentation-grpc": "^0.53.0",
"@opentelemetry/instrumentation-http": "^0.53.0",
"@opentelemetry/instrumentation-pg": "^0.45.0",
"@opentelemetry/resources": "^1.26.0",
"@opentelemetry/sdk-node": "^0.53.0",
"@opentelemetry/sdk-trace-node": "^1.26.0",
"@opentelemetry/semantic-conventions": "^1.27.0",
Relevant log output
No response
The text was updated successfully, but these errors were encountered: