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

Node "Cannot read properties of undefined (reading 'then') #3697

Closed
maciej-wakula-opuscapita opened this issue Mar 22, 2023 · 3 comments
Closed
Labels
bug Something isn't working triage

Comments

@maciej-wakula-opuscapita

What happened?

Steps to Reproduce

I tried to run node -r ./tracing.js index.js.
The sdk.start().then(...) is failing - sdk.ts is returning void.
I am using plain JavaScript (not typescript).

Expected Result

sdk.start() should always return same object type: either a promise, a concrete object or undefined. If the returned object is an undefined then .then should not be called on it.

Actual Result

When using webpack - it seems to work for me most time. When using javascript - the returned argument is not a promise and has no .then

Additional Details

Test procedure

mkdir /tmp/dir && cd /tmp/dir
docker run --rm -v /tmp/dir:/home/node/dir -it node:18-alpine sh
cd /home/node/dir
npm init -y
npm i @opentelemetry/sdk-node @opentelemetry/exporter-trace-otlp-http @opentelemetry/instrumentation-fs
node -r ./tracing.js index.js

OpenTelemetry Setup Code

//tracing.js

'use strict'
const opentelemetry = require('@opentelemetry/sdk-node');
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
const { FsInstrumentation } = require('@opentelemetry/instrumentation-fs');
const traceExporter = new OTLPTraceExporter({ url: 'http://otel-collector:4318/v1/traces' });
const sdk = new opentelemetry.NodeSDK({
  traceExporter,
  instrumentations: [new FsInstrumentation()],
  autoDetectResources: true,
  resourceDetectors: [ // By default process information is also added
    opentelemetry.resources.envDetector,
  ],
});
sdk.start()
  .then(()=>console.log("Tracing initialized"))
  .catch((error)=>console.log("Error during initialization"));

package.json

{
  "name": "dir",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@opentelemetry/exporter-trace-otlp-http": "^0.36.1",
    "@opentelemetry/instrumentation-fs": "^0.7.1",
    "@opentelemetry/sdk-node": "^0.36.1"
  }
}

Relevant log output

/home/node/dir/tracing.js:16
  .then(()=>console.log("Tracing initialized"))
  ^

TypeError: Cannot read properties of undefined (reading 'then')
    at Object.<anonymous> (/home/node/dir/tracing.js:16:3)
    at Module._compile (node:internal/modules/cjs/loader:1226:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1280:10)
    at Module.load (node:internal/modules/cjs/loader:1089:32)
    at Module._load (node:internal/modules/cjs/loader:930:12)
    at Module.require (node:internal/modules/cjs/loader:1113:19)
    at Module._preloadModules (node:internal/modules/cjs/loader:1403:12)
    at loadPreloadModules (node:internal/process/pre_execution:621:5)
    at setupUserModules (node:internal/process/pre_execution:125:3)
    at prepareExecution (node:internal/process/pre_execution:116:5)
@maciej-wakula-opuscapita maciej-wakula-opuscapita added bug Something isn't working triage labels Mar 22, 2023
@Flarna
Copy link
Member

Flarna commented Mar 22, 2023

Likely caused by #3460 which was unfortunately not marked as breaking.

Please note that modules like @opentelemetry/sdk-node are still in experimental phase so breaking changes like this may happen.

There is a bold note about this in the readme.

@maciej-wakula-opuscapita
Copy link
Author

Since README.md is updated in #3460 - we can probably close this ticket.

@kzotoff
Copy link

kzotoff commented May 22, 2023

Also, this demo is needed to be updated
https://opentelemetry.io/blog/2022/instrument-nginx/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

3 participants