Skip to content

Memory leak with high tracesSampleRate #18339

@raymondhechen

Description

@raymondhechen

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node - express

SDK Version

10.27.0

Framework Version

Express 5.1.0

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

Set tracesSampleRate to 1 and observe memory usage, likely with a lot of Sentry.startSpan() usage.

Expected Result

Memory usage to not keep growing.

Actual Result

Image

Up until 10pm in the screenshot, we were using tracesSampleRate of 1. Then we switched it to 0.2. The dotted lines indicate new deployments (thus resetting memory). We've been having memory leak issues for several versions of @sentry/node now, but we didn't realize until yesterday that the biggest lever that changed this was the tracesSampleRate. The chart unfortunately doesn't show additional memory leaks, but it's consistently been there at high growth rates until now. If there any ideas on why this is happening and how Sentry is affecting this, would be greatly appreciated, as we can see memory usage still growing but just far slower now.

Additional Context

We wrap Sentry methods in our helper functions in case this affects anything:

import * as Sentry from '@sentry/node'

interface ServerSpanArgs {
  name: string // human-readable name
  op?: string // semantic operation
  attributes?: Record<string, string | number | boolean | undefined>
}

export const withServerTrace = async <T>(
  { name, op = 'service', attributes }: ServerSpanArgs,
  fn: (span: Sentry.Span) => Promise<T> | T
): Promise<T> => {
  return Sentry.startSpan({ name, op, attributes }, async (span) => {
    try {
      return await fn(span)
    } catch (err) {
      span.setStatus({ code: 2, message: 'internal_error' })
      Sentry.captureException(err)
      throw err
    }
  })
}

export const captureServerException = (
  error: unknown,
  extra?: Record<string, unknown>
) => {
  Sentry.captureException(error, { extra })
}

Priority

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions