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

Using Sentry with VS Code extension causes CPU and Memory Overload #14840

Open
3 tasks done
hdkshingala opened this issue Dec 27, 2024 · 2 comments
Open
3 tasks done

Using Sentry with VS Code extension causes CPU and Memory Overload #14840

hdkshingala opened this issue Dec 27, 2024 · 2 comments
Labels
Package: node Issues related to the Sentry Node SDK

Comments

@hdkshingala
Copy link

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

8.45.0

Framework Version

Node 20.18.1

Link to Sentry event

No response

Reproduction Example/SDK Setup

import {
  EventHint,
  NodeClient,
  Scope,
  defaultStackParser,
  getDefaultIntegrations,
  makeNodeTransport,
} from "@sentry/node";
import { Env } from "./config";
import { NodeEnv } from "./consts";

const TraycerScope: Scope = new Scope();

export function initSentry() {
  // filter integrations that use the global variable
  const integrations = getDefaultIntegrations({}).filter(
    (defaultIntegration) => {
      return ![
        "OnUnhandledRejection",
        "OnUncaughtException",
        "CaptureConsole",
      ].includes(defaultIntegration.name);
    },
  );

  const client = new NodeClient({
    dsn: "DSN",
    integrations: integrations,

    beforeSend(event) {
      for (const ex of event?.exception?.values ?? []) {
        for (const frame of ex.stacktrace?.frames ?? []) {
          if (frame.filename?.includes(Env.extensionName)) {
            return event;
          }
        }
      }
      return null;
    },
    tracesSampleRate: 0.2,
    profilesSampleRate: 1.0,
    sampleRate: 1.0,
    attachStacktrace: true,
    environment: Env.nodeEnv,
    includeLocalVariables: true,
    serverName: "traycer-vscode",
    transport: makeNodeTransport,
    stackParser: defaultStackParser,
  });
  TraycerScope.setTag("extention", Env.extensionName);
  TraycerScope.setClient(client);
  client.init();
}

export function captureException(
  ex: unknown,
  hint?: EventHint | undefined,
): unknown {
  if (Env.nodeEnv === NodeEnv.Production) {
    TraycerScope.captureException(ex, hint);
  }

  return ex;
}

export function setScopeTag(key: string, value: string) {
  TraycerScope.setTag(key, value);
}

export async function close() {
  await TraycerScope.getClient()?.close(2000);
}

Steps to Reproduce

  1. Build VS Code extension having Sentry configured using esbuild
  2. Install the extension
  3. Observe the CPU usage

Expected Result

It should work normally without any additional memory / cpu load.

Actual Result

When the extension (having sentry) is installed in VS Code, it blocks the event loop in the Extension Host, causing high CPU and memory usage that ultimately results in an Extension Host crash.

  • A CPU profile indicates that the package require-in-the-middle (brought in by @opentelemetry/instrumentation under @sentry/node) is loaded as soon as the extension activates.
  • This package seems to block the event loop, rendering the Extension Host unresponsive.
  • After removing Sentry from the extension’s dependencies, the Extension Host resumed normal performance without CPU or memory overload.

CPU-20241224T083236.459Z.cpuprofile.txt

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 27, 2024
@github-actions github-actions bot added the Package: node Issues related to the Sentry Node SDK label Dec 27, 2024
@andreiborza
Copy link
Member

hi @hdkshingala,

I'm not well versed wth VSCode extensions, but in our docs we use @sentry/browser to set up Sentry for shared environments.

Is there a reason you're using @sentry/node?

The browser package does not use opentelemetry under the hood so you shouldn't experience these issues.

@hdkshingala
Copy link
Author

@andreiborza Thanks for sharing the information. We will try @sentry/browser. I think we used @sentry/node initially as we were using it for metrics which was not supported with browser SDK maybe.

Also, I feel the issue which we faced could happen in a non vs code extension based application as well because we could see it blocking the CPU for a long period.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: node Issues related to the Sentry Node SDK
Projects
Status: No status
Development

No branches or pull requests

3 participants