getsentry / sentry-javascript-bundler-plugins

JavaScript Bundler Plugins for Sentry
https://sentry.io
BSD 3-Clause "New" or "Revised" License
141 stars 36 forks source link

`isOlderThan` is not a function #533

Closed jd-carroll closed 4 months ago

jd-carroll commented 6 months ago

Environment

    "@sentry/esbuild-plugin": "^2.16.1",

Actual Result

Still investigating, but my builds are all failing with:

  "message": "getHubFromCarrier(...).isOlderThan is not a function",
  "stack": [
    "TypeError: getHubFromCarrier(...).isOlderThan is not a function",
    "    at getGlobalHub (file:///home/runner/work/monorepo/monorepo/node_modules/@sentry/bundler-plugin-core/dist/esm/index.mjs:6631:33)",
    "    at getCurrentHub (file:///home/runner/work/monorepo/monorepo/node_modules/@sentry/bundler-plugin-core/dist/esm/index.mjs:6612:10)",
    "    at getClient (file:///home/runner/work/monorepo/monorepo/node_modules/@sentry/bundler-plugin-core/dist/esm/index.mjs:4967:10)",
    "    at hasTracingEnabled (file:///home/runner/work/monorepo/monorepo/node_modules/@sentry/bundler-plugin-core/dist/esm/index.mjs:6843:18)",
    "    at sampleTransaction (file:///home/runner/work/monorepo/monorepo/node_modules/@sentry/bundler-plugin-core/dist/esm/index.mjs:7938:8)",
    "    at Hub._startTransaction (file:///home/runner/work/monorepo/monorepo/node_modules/@sentry/bundler-plugin-core/dist/esm/index.mjs:8095:17)",
    "    at Hub._callExtensionMethod (file:///home/runner/work/monorepo/monorepo/node_modules/@sentry/bundler-plugin-core/dist/esm/index.mjs:6555:40)",
    "    at Hub.startTransaction (file:///home/runner/work/monorepo/monorepo/node_modules/@sentry/bundler-plugin-core/dist/esm/index.mjs:6423:25)",
    "    at _callee$ (file:///home/runner/work/monorepo/monorepo/node_modules/@sentry/bundler-plugin-core/dist/esm/index.mjs:14342:25)",
    "    at tryCatch (file:///home/runner/work/monorepo/monorepo/node_modules/@sentry/bundler-plugin-core/dist/esm/index.mjs:90:17)"
  ]
jd-carroll commented 6 months ago

I've been trying to wrap my head around this and cannot seem to be able to.

If I debug locally (I get the same error) and inspecting the registry object it looks like:

  __SENTRY__: {
    extensions: {
      startTransaction: [Function: _startTransaction],
      traceHeaders: [Function: traceHeaders]
    },
    defaultCurrentScope: ScopeClass {
      _notifyingListeners: false,
      _scopeListeners: [],
      _eventProcessors: [],
      _breadcrumbs: [],
      _attachments: [],
      _user: {},
      _tags: {},
      _extra: {},
      _contexts: {},
      _sdkProcessingMetadata: {},
      _propagationContext: [Object]
    },
    defaultIsolationScope: ScopeClass {
      _notifyingListeners: false,
      _scopeListeners: [],
      _eventProcessors: [],
      _breadcrumbs: [],
      _attachments: [],
      _user: {},
      _tags: {},
      _extra: {},
      _contexts: {},
      _sdkProcessingMetadata: {},
      _propagationContext: [Object]
    },
    hub: AsyncContextStack {
      _stack: [Array],
      _isolationScope: [ScopeClass]
    }
  },

I'm not sure where AsyncContextStack would be coming from, but that definitely looks wrong.

Let's go ahead and assume this is something I am doing wrong. Where would I even start?

jd-carroll commented 6 months ago

Just for tracking purposes, the AsyncContextStack is a Sentry construct. I'm no longer assuming that this is an issue with my code.

Additionally, the AsyncContextStack is created here: https://github.com/getsentry/sentry-javascript/blob/4420844943418a1bc23a6ccad70401d68a8c94a4/packages/core/src/asyncContext/stackStrategy.ts#L133-L148

lforst commented 6 months ago

Can you try setting telemetry: false? Thanks!

Lms24 commented 6 months ago

Hey @jd-carroll - this is most likely fixed by https://github.com/getsentry/sentry-javascript/pull/12160 which we're gonna release today.

jd-carroll commented 6 months ago

@lms24 awesome, thank you, I'll look for that in a bit!

@lforst I tried setting that but it still seems to be throwing the same error (but maybe less...?)

Additionally, I just noticed this in the error output:

        {
          "id": "import-is-undefined",
          "location": {
            "column": 44,
            "file": "lambdas/user-account-setup-handler/user-account-setup-handler.ts?sentryProxyModule=true",
            "length": 7,
            "line": 4,
            "lineText": "              export default OriginalModule.default;",
            "namespace": "",
            "suggestion": ""
          },
          "notes": [],
          "pluginName": "",
          "text": "Import \"default\" will always be undefined because there is no matching export in \"lambdas/user-account-setup-handler/user-account-setup-handler.ts\""
        }

I didn't think the Sentry bundler is actually changing the entry point for the lambda. If so, this is hugely concerning because none of my lambdas use "default" as the named entry point for AWS.

Can either of you help me understand what is happening there?

jd-carroll commented 6 months ago

As a side note, I just patched my local code and everything seems to be working. I also inspected the output and confirmed that my named exports still exist. The output contains the following:

// lambdas/user-account-details-handler/user-account-details-handler.ts?sentryProxyModule=true
var user_account_details_handler_default = void 0;
export {
  user_account_details_handler_default as default,
  handler
};
//# sourceMappingURL=lambda.mjs.map

Nothing is ever assigned to user_account_details_handler_default other than void 0. So my assumption would be it is something you look for in the uploaded sourcemaps to Sentry? Either way, no big deal, more so curious now... 😄

jd-carroll commented 6 months ago

@Lms24 It does not appear this was fixed in @sentry/core@8.3.0 (fyi)

Lms24 commented 6 months ago

Yup, sorry about that, we had to close the PR in favor of a better fix

getsantry[bot] commented 4 months ago

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀