Share on Twitter
Share on Facebook
Share on HackerNews
Share on LinkedIn

Python, JavaScript, .NET, and Rust: Sentry’s Unified SDK Updates

Since you’re reading this blog, you’re likely aware of the most critical part of using Sentry: our client SDKs. We shared previously that we were updating Sentry’s SDKs, and now we’re on the verge of those updates becoming the default.

This affects a few of our most popular platforms: Python and JavaScript, plus we also threw .NET and Rust into the mix for good measure.

If you’re already using Sentry, there is no immediate need to upgrade to the new SDKs as we will continue to support the existing ones. We still highly recommend giving the new ones a try, as they’ll receive all the nice new features we have in the pipeline.

What’s new with Sentry SDKs?

The big idea behind this update is to provide a unified experience across all platforms. In other words, if you know how to use the SDK on the server, you’ll know how to use them on the client.

Beyond that, we wanted to make them more flexible. The SDKs have some very powerful hooks that let you get more out of Sentry, and now you’ll only need to worry with a single way to bind data like tags, users, or contexts, and it’ll work the same everywhere.

You just call configureScope, which gives you a scope object you can reconfigure. The scope is local to your current HTTP request, task, or thread. Any event sent later within the flow of execution will send this data along:

Sentry.configureScope(scope =>; {

  scope.setTag("page_locale", "de-at");

  scope.setUser({"email": "john.doe@example.com"});

  scope.setExtra("character_name": "Mighty Fighter");

});

When an exception is raised, that data will be sent along.

try {

  aFunction();

} catch (error) {

  Sentry.captureException(error);

}

And now the same for Python:

with sentry_sdk.configure_scope() as scope:

    scope.set_tag("page_locale", "de-at")

    scope.user = {"email": "john.doe@example.com"}

    scope.set_extra("character_name": "Mighty Fighter")

When an exception is raised, that data will be sent along.

try:

    a_function();

except Exception as error:

    sentry_sdk.capture_exception(error)

Powerful Hints and Hooks

One of the most powerful features in the new SDKs is the hint and callback system. Instead of countless options, there are two callbacks(before-breadcrumb and before-send). These functions are invoked with the breadcrumb/event and an additional hint object which holds the source information. These callbacks can be used to modify strip data, discard entire breadcrumbs and events, and with the help of the hints, add additional information if needed.

Here, for instance, is an example that adds the aria-label into a breadcrumb if available:

Sentry.init({

  beforeBreadcrumb(breadcrumb, hint) {

    if (breadcrumb.category === 'ui.click') {

      const { target } = hint.event;

      if (target.ariaLabel) {

        breadcrumb.message = target.ariaLabel;

      }

    }

    return breadcrumb;

  },

});

Or how about customizing the grouping based on an exception type in before-send?

def before_send(event, hint):

    if 'exc_info' in hint:

        if isinstance(hint['exc_info'][1], DatabaseUnavailable):

            event['fingerprint'] = ['database-unavailable']

    return event

sentry_sdk.init(before_send=before_send)

How do I get the new SDKs?

The docs now guide you to the new platforms for SDKs that are already following the new unified API. For most users updating the imports and changing some calls and configuration should be the only thing that is necessary. 

What’s next?

The SDKs are live now, but that’s just the start. We’re going to be updating the documentation with examples of what you can do with the new integrations and what’s planned for the future. Please don’t hesitate to talk to us and let us know what you think.

To learn more, please join the Sentry forum where you’ll find:

  • Sub-forums specific to Python, .NET, and JavaScript
  • Opportunities to engage in discussion with our SDK team

We’re very excited about our new SDKs, and we’re looking forward to your feedback!

Your code is broken. Let's Fix it.
Get Started

More from the Sentry blog

ChangelogCodecovDashboardsDiscoverDogfooding ChroniclesEcosystemError MonitoringEventsGuest PostsMobileOpen SourcePerformance MonitoringRelease HealthResourceSDK UpdatesSentry
© 2024 • Sentry is a registered Trademark
of Functional Software, Inc.