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

fix(node): Make log flushing logic more robust #15991

Merged
merged 2 commits into from
Apr 7, 2025
Merged

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Apr 7, 2025

resolves https://linear.app/getsentry/issue/LOGS-18

We got some user feedback that nodejs logging was too inconsistent. This PR improves that.

  1. Add a new flushLogs client hook that allows us to reset server weight tracking logic more consistently. This also fixes a bug where we didn't reset weight tracking when calling Sentry.flush.
  2. Add a process.on('beforeExit' listener to flush logs. Hooking onto beforeExit does not guarantee we flush all logs before exit, but it does increase the chances we do.
  3. Add an idle timeout that will flush logs after 5 seconds if no new logs are recorded. This should not leak memory because it is not an interval, but instead a timeout.

@AbhiPrasad AbhiPrasad requested a review from a team April 7, 2025 09:48
@AbhiPrasad AbhiPrasad self-assigned this Apr 7, 2025
@AbhiPrasad AbhiPrasad requested review from mydea and lforst and removed request for a team April 7, 2025 09:48
@@ -25,6 +25,9 @@ import { resolvedSyncPromise } from './utils-hoist/syncpromise';
import { _INTERNAL_flushLogsBuffer } from './logs/exports';
import { isPrimitive } from './utils-hoist';

// TODO: Make this configurable
const DEFAULT_LOG_FLUSH_INTERVAL = 5000;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also exists in the browser SDK.

I'm going to create another PR after this that unifies this as a logging option, and update the develop docs as well.

Copy link
Contributor

github-actions bot commented Apr 7, 2025

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 23.26 KB +0.04% +8 B 🔺
@sentry/browser - with treeshaking flags 23.1 KB +0.05% +10 B 🔺
@sentry/browser (incl. Tracing) 36.92 KB +0.03% +8 B 🔺
@sentry/browser (incl. Tracing, Replay) 74.12 KB +0.02% +9 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.49 KB +0.02% +8 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 78.78 KB +0.02% +10 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 90.58 KB +0.01% +6 B 🔺
@sentry/browser (incl. Feedback) 39.65 KB +0.02% +8 B 🔺
@sentry/browser (incl. sendFeedback) 27.88 KB +0.04% +9 B 🔺
@sentry/browser (incl. FeedbackAsync) 32.65 KB +0.03% +8 B 🔺
@sentry/react 25.07 KB +0.04% +9 B 🔺
@sentry/react (incl. Tracing) 38.85 KB +0.04% +12 B 🔺
@sentry/vue 27.48 KB +0.04% +9 B 🔺
@sentry/vue (incl. Tracing) 38.65 KB +0.03% +10 B 🔺
@sentry/svelte 23.29 KB +0.04% +8 B 🔺
CDN Bundle 24.51 KB +0.04% +9 B 🔺
CDN Bundle (incl. Tracing) 36.95 KB +0.03% +8 B 🔺
CDN Bundle (incl. Tracing, Replay) 71.99 KB +0.02% +9 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 77.16 KB +0.02% +8 B 🔺
CDN Bundle - uncompressed 71.47 KB +0.03% +20 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 109.23 KB +0.02% +20 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 220.52 KB +0.01% +20 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 233.05 KB +0.01% +20 B 🔺
@sentry/nextjs (client) 40.36 KB +0.15% +61 B 🔺
@sentry/sveltekit (client) 37.37 KB +0.04% +12 B 🔺
@sentry/node 142.99 KB +0.05% +69 B 🔺
@sentry/node - without tracing 96.19 KB +0.07% +62 B 🔺
@sentry/aws-serverless 120.54 KB +0.06% +64 B 🔺

View base workflow run

@AbhiPrasad AbhiPrasad merged commit 6a8a2c3 into develop Apr 7, 2025
151 of 152 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-node-sdk-flush branch April 7, 2025 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants