Repository navigation
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
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
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
Projects
- StatusShow more project fieldsNo status
Activity
linear commentedon Nov 26, 2025
JS-1224
Lms24 commentedon Nov 27, 2025
Hey @raymondhechen thanks for writing in! Can you share a bit more around your usage of Sentry?
withServerTrace?withServerTracelooks like you want the span within to be the local root span (not sure though of course) of the trace. Are you disabling auto instrumentation?What you've shown so far already gives us some hints. An increase in
tracesSampleRatecould explain a memory increase very well, given that the SDK might record a lot of spans. But it's too early to say if it is actually about spans or just data getting applied more often.raymondhechen commentedon Nov 28, 2025
Thanks for the response @Lms24! Here's how we init the SDK:
We use
withServerTrace()by just wrapping any function we want to measure the performance of. For example:We really just use
withServerTrace()as a helper function to wrapSentry.startSpan()to start a span within a parent span or an express route/handler trace. I assumed it may be a memory leak issue because memory usage just keeps growing, and reducing trace sampling rate without changing anything else resulted in at least slower growth. Let me know if specific examples of ourwithServerTrace()could be helpful, although we really just wrap all kinds of async functions with it.7 remaining items
JPeer264 commentedon Dec 2, 2025
Ok thanks for the update that gives me a somewhat direction on where it could go. I'll try to find some time and check where it could leak.
Also to confirm, all spans which are created are sent to Sentry right?
raymondhechen commentedon Dec 3, 2025
@JPeer264 The only setting we have that may affect whether all spans are sent to Sentry (I assume) is
tracesSampleRate. I'm not aware of any other flag.However, we have noticed that in the Sentry dashboard, many of our
expresshandler traces don't actually show all the spans that could be attributed to the trace for an endpoint. Basically, we have one webhook endpoint that automatically times out15s(by the client that sends the request to our server). If the execution duration for that endpoint is greater than that, then we see spans getting omitted from the full trace. Unsure if related and also not a behavior we honestly expect because we still have more async execution that happens after the requesting client prematurely closes the request at 15s.JPeer264 commentedon Dec 3, 2025
Ok if you cancel the request after 15s proactively then I think it is alright that some events are not being sent (however, maybe a graceful cancel with a
flushat the end wouldn't harm). Thanks for the hints - I'll try to investigate on this a littlefix(core): Use WeakRef for Span-Scope circular references (#21242)
github-actions commentedon Jun 2, 2026
A PR closing this issue has just been released 🚀
This issue was referenced by PR #21242, which was included in the 10.56.0 release.
chore(deps): pin the Sentry SDK to 10.56.0 to pick up the span/scope …