Skip to content

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

@hdkshingala

Description

@hdkshingala

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Waiting for: Community

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions