getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.98k stars 1.57k forks source link

Sentry ESModules does not import @opentelemetry/semantic-conventions correctly #13981

Closed Jimmy89 closed 2 weeks ago

Jimmy89 commented 2 weeks ago

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/aws-serverless

SDK Version

8.34.0

Framework Version

NodeJS v20

Link to Sentry event

No response

Reproduction Example/SDK Setup

Import Sentry from any Sentry javascript package above 8.29.0

main.mjs:

import * as Sentry from "@sentry/aws-serverless";

Package.json dependencies:

    "@sentry/aws-serverless": "^8.34.0",
    "@sentry/node": "^8.34.0",
    "@sentry/profiling-node": "^8.34.0",

Run node main.mjs, get the error:

file:///PROJECT_LOCATION/node_modules/@sentry/node/build/esm/sdk/initOtel.js:6
import { ATTR_SERVICE_NAME, SEMRESATTRS_SERVICE_NAMESPACE, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';
         ^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'ATTR_SERVICE_NAME' not found. The requested module '@opentelemetry/semantic-conventions' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@opentelemetry/semantic-conventions';
const { ATTR_SERVICE_NAME, SEMRESATTRS_SERVICE_NAMESPACE, ATTR_SERVICE_VERSION } = pkg;

The @opentelemetry/semantic-conventions package does not support ESModules correctly (yet) and therefore the imports must be written like the error states as global import statements, where the variables can be destructered from.

If I manually resolve the error, I get the same error within other Sentry package files, so the codebase must be scanned on multiple references.

Steps to Reproduce

  1. Create a main.mjs file with the import Sentry statement: import * as Sentry from "@sentry/aws-serverless";
  2. Ensure that you installed the packages
  3. Run node main.mjs

Expected Result

No import errors coming from any Sentry package.

Actual Result

Cannot use Sentry Javascript packages in any way in ESModules project

chargome commented 2 weeks ago

Hey @Jimmy89, you can safely remove @sentry/node as this should already be included in @sentry/aws-serverless.

Following the steps you outlined I could not reproduce this issue. Are you running this locally on your machine?

Jimmy89 commented 2 weeks ago

@chargome Thank you for your quick answer. We got the issue at 8.30.0, after that our node_modules cache seems to have corrupted. A clean node_modules with the latest Sentry fixed the issue.

Also thanks for noting that the @sentry/node is not needed.