James Abiagam
06/25/2025, 10:14 PMconst resource = new Resource({
^
TypeError: Resource is not a constructor
at Object.<anonymous>
I have also tried the pinned Github repo example and it still did not work. Can someone please help.Hien Le
06/26/2025, 1:33 AMresource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: '<service_name>',
}),
have you tried the sample near the top of the page?
resource: resourceFromAttributes({
// highlight-next-line
[SemanticResourceAttributes.SERVICE_NAME]: '<service_name>'
})
because in TypeScript that's just an interface that can't be directly instantiated, so I think one of the examples is stale and wasn't updated when this OTel refactor happened.
I didn't check the semvers of the packages, but the examples might be valid if they're version locked and you happened to install latest.James Abiagam
06/26/2025, 7:46 AMHien Le
06/26/2025, 4:34 PMimport * as opentelemetry from '@opentelemetry/sdk-node';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
import { resourceFromAttributes } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
const sdk = new opentelemetry.NodeSDK({
traceExporter: new OTLPTraceExporter({
// optional - default url is <http://localhost:4318/v1/traces>
url: '<https://ingest>.<region>.signoz.cloud:443/v1/traces', // url is optional and can be omitted
headers: {
"signoz-access-token": "<your-ingestion-key>"
} // an optional object containing custom headers to be sent with each request
}),
instrumentations: [getNodeAutoInstrumentations()],
resource: resourceFromAttributes({
// highlight-next-line
[SemanticResourceAttributes.SERVICE_NAME]: '<service_name>'
})
});
sdk.start();
Hien Le
06/26/2025, 4:36 PMnpm install --save @opentelemetry/api@^1.6.0
npm install --save @opentelemetry/sdk-node@^0.45.0
npm install --save @opentelemetry/auto-instrumentations-node@^0.39.4
npm install --save @opentelemetry/exporter-trace-otlp-http@^0.45.0
were those what you installed?James Abiagam
06/26/2025, 4:37 PMimport { resourceFromAttributes } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
James Abiagam
06/26/2025, 4:38 PMJames Abiagam
06/26/2025, 4:39 PMHien Le
06/26/2025, 4:42 PMsdk-node
so that's likely why they weren't explicitly listed.
https://www.npmjs.com/package/@opentelemetry/sdk-node?activeTab=dependenciesHien Le
06/26/2025, 4:50 PMnpm install --save @opentelemetry/api@^1.6.0
ends up installing
"@opentelemetry/api": "^1.9.0"
which are a year apart. You can try locking down to the exact/patch versions by switching ^
for ~
, e.g.:
npm install --save @opentelemetry/api@~1.6.0
npm install --save @opentelemetry/sdk-node@~0.45.0
npm install --save @opentelemetry/auto-instrumentations-node@~0.39.4
npm install --save @opentelemetry/exporter-trace-otlp-http@~0.45.0
Hien Le
06/26/2025, 4:51 PMJames Abiagam
06/26/2025, 10:47 PM