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

feat(node): Add logging public APIs to Node SDKs #15764

Merged
merged 3 commits into from
Mar 24, 2025

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Mar 20, 2025

ref #15526

Continuing off the work from #15763, this PR adds the logging public API to the Node SDK. It also adds a basic weight-based flushing strategy to the SDK that is in the server-runtime client.

The main file added was log.ts. In that file I've added logger methods for trace, debug, info, warn, error, fatal (the log severity levels) as well as an internal capture log helper all these methods call.

Usage:

import * as Sentry from "@sentry/node";

Sentry.init({
  dsn: "your-dsn-here",
  _experiments: {
    enableLogs: true  // This is required to use the logging features
  }
});

// Trace level (lowest severity)
Sentry.logger.trace("This is a trace message", { userId: 123 });

// Debug level
Sentry.logger.debug("This is a debug message", { component: "UserProfile" });

// Info level
Sentry.logger.info("User %s logged in successfully", [123]);

// Warning level
Sentry.logger.warn("API response was slow", { responseTime: 2500 });

// Error level
Sentry.logger.error("Failed to load user %s data", [123], { errorCode: 404 });

// Critical level
Sentry.logger.critical("Database connection failed", { dbHost: "primary-db" });

// Fatal level (highest severity)
Sentry.logger.fatal("Application is shutting down unexpectedly", { memory: "exhausted" });

@AbhiPrasad AbhiPrasad requested a review from a team March 20, 2025 21:52
@AbhiPrasad AbhiPrasad self-assigned this Mar 20, 2025
@AbhiPrasad AbhiPrasad requested review from lforst and s1gr1d and removed request for a team March 20, 2025 21:52
@AbhiPrasad AbhiPrasad mentioned this pull request Mar 20, 2025
7 tasks
@AbhiPrasad
Copy link
Member Author

Okay Q for the group. We export a logger namespace in both Node and Browser, but they contain two different sets of methods. How do we make the index.types.ts work in our metaframeworks for this?

Does typeof clientSdk.logger | typeof serverSdk.logger; work fine?

Copy link
Member

@s1gr1d s1gr1d left a comment

Choose a reason for hiding this comment

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

Looks good to me. I think the naming of ...Fmt is fitting as well 👍

Base automatically changed from abhi-browser-logging-methods to develop March 21, 2025 14:46
@AbhiPrasad
Copy link
Member Author

Just so everyone on the team is comfortable with the additional API, I'm going to walk through this PR on monday at planning.

@AbhiPrasad
Copy link
Member Author

After meeting with the team, we decided to unify the API.

You can either pass a message and attributes or a message template, params and attributes.

Sentry.logger.trace('Starting database connection', {
  database: 'users',
  connectionId: 'conn_123'
});
Sentry.logger.trace('Database connection %s established for %s',
  ['successful', 'users'],
  { connectionId: 'conn_123' }
);

@AbhiPrasad AbhiPrasad force-pushed the abhi-nodejs-logging-methods branch from d8fefc1 to 3447bb6 Compare March 24, 2025 16:26
Copy link
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.21 KB - -
@sentry/browser - with treeshaking flags 23.01 KB - -
@sentry/browser (incl. Tracing) 36.62 KB - -
@sentry/browser (incl. Tracing, Replay) 73.79 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.11 KB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 78.42 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 91 KB - -
@sentry/browser (incl. Feedback) 40.34 KB - -
@sentry/browser (incl. sendFeedback) 27.84 KB - -
@sentry/browser (incl. FeedbackAsync) 32.63 KB - -
@sentry/react 25 KB - -
@sentry/react (incl. Tracing) 38.51 KB - -
@sentry/vue 27.44 KB - -
@sentry/vue (incl. Tracing) 38.29 KB - -
@sentry/svelte 23.24 KB - -
CDN Bundle 24.43 KB - -
CDN Bundle (incl. Tracing) 36.63 KB - -
CDN Bundle (incl. Tracing, Replay) 71.61 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 76.82 KB - -
CDN Bundle - uncompressed 71.39 KB - -
CDN Bundle (incl. Tracing) - uncompressed 108.58 KB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 219.83 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 232.4 KB - -
@sentry/nextjs (client) 39.81 KB - -
@sentry/sveltekit (client) 37.03 KB - -
@sentry/node 142.85 KB +0.18% +254 B 🔺
@sentry/node - without tracing 96.24 KB +0.27% +258 B 🔺
@sentry/aws-serverless 120.59 KB +0.21% +252 B 🔺

View base workflow run

@AbhiPrasad AbhiPrasad merged commit 2ed6fc2 into develop Mar 24, 2025
152 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-nodejs-logging-methods branch March 24, 2025 17:21
@aldy505
Copy link

aldy505 commented Mar 25, 2025

Heya @AbhiPrasad, wondering when's the next release schedule that would bring this change?

@AbhiPrasad
Copy link
Member Author

@aldy505 My plan is that our experimental logs support for JavaScript goes out with the next release, 9.10.0. We plan to open it up for limited availability sometime next week for SaaS. Feel free to leave a comment in getsentry/sentry#86804 if you want to get signed up for that.

We won't mark it ready for self hosted until we have all the feature flags + infra stable. Currently there's still some more relay and snuba changes left before we're ready for that.

@aldy505
Copy link

aldy505 commented Mar 25, 2025

@aldy505 My plan is that our experimental logs support for JavaScript goes out with the next release, 9.10.0. We plan to open it up for limited availability sometime next week for SaaS. Feel free to leave a comment in getsentry/sentry#86804 if you want to get signed up for that.

We won't mark it ready for self hosted until we have all the feature flags + infra stable. Currently there's still some more relay and snuba changes left before we're ready for that.

I already have it running on self hosted :) Some folks that are using SH already uses Ourlogs.

@AbhiPrasad
Copy link
Member Author

I already have it running on self hosted :) Some folks that are using SH already uses Ourlogs.

oh awesome!

We'll start posting GH discussions for SDK setups + minimum required versions soon then, python and javascript first, but everything else will follow. If you want a specific SDK to be added sooner, please leave a comment in the GH discussion.

@aldy505
Copy link

aldy505 commented Mar 26, 2025

Yes, thank you! I have my own custom Go SDK, so I'll use that. You can refer here if you have any users that want to enable it on SH: getsentry/self-hosted#3560

@AbhiPrasad
Copy link
Member Author

@aldy505 published some WIP docs here for JS: #15916

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.

None yet

3 participants