Convert Figma logo to code with AI

getsentry logosentry-python

The official Python SDK for Sentry.io

2,007
541
2,007
181

Top Related Projects

Official Sentry SDKs for JavaScript

Quick Overview

Sentry-python is the official Python SDK for Sentry, an error tracking and performance monitoring platform. It allows developers to automatically report errors and exceptions in their Python applications, providing detailed information about the runtime environment and stack traces to aid in debugging and issue resolution.

Pros

  • Easy integration with various Python web frameworks and libraries
  • Comprehensive error tracking with detailed context and stack traces
  • Supports both synchronous and asynchronous code
  • Customizable event filtering and data scrubbing for privacy

Cons

  • Can introduce a slight performance overhead in some applications
  • Requires a Sentry account and project setup for full functionality
  • May require additional configuration for optimal use in complex environments
  • Limited built-in support for some less common Python frameworks

Code Examples

  1. Basic error capturing:
import sentry_sdk

sentry_sdk.init("https://examplePublicKey@o0.ingest.sentry.io/0")

def divide_by_zero():
    1 / 0

try:
    divide_by_zero()
except Exception as e:
    sentry_sdk.capture_exception(e)
  1. Capturing custom events:
import sentry_sdk

sentry_sdk.init("https://examplePublicKey@o0.ingest.sentry.io/0")

sentry_sdk.capture_message("A custom message", level="info")
  1. Adding custom context:
import sentry_sdk

sentry_sdk.init("https://examplePublicKey@o0.ingest.sentry.io/0")

with sentry_sdk.push_scope() as scope:
    scope.set_tag("user_id", "12345")
    scope.set_extra("order_id", "67890")
    sentry_sdk.capture_exception(Exception("Something went wrong"))

Getting Started

To get started with sentry-python:

  1. Install the SDK:

    pip install --upgrade sentry-sdk
    
  2. Initialize the SDK in your application:

    import sentry_sdk
    
    sentry_sdk.init(
        dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
        traces_sample_rate=1.0
    )
    
  3. Errors will now be automatically reported to your Sentry project. You can also manually capture exceptions or messages as shown in the code examples above.

Competitor Comparisons

Official Sentry SDKs for JavaScript

Pros of sentry-javascript

  • Broader ecosystem support, covering various JavaScript environments (browser, Node.js, React Native)
  • More extensive integration options with popular JavaScript frameworks and libraries
  • Larger community and more frequent updates due to JavaScript's widespread use

Cons of sentry-javascript

  • Potentially larger bundle size, which may impact performance in browser environments
  • More complex setup process due to the variety of JavaScript environments and frameworks
  • Steeper learning curve for developers new to error tracking in JavaScript applications

Code Comparison

sentry-javascript:

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

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  integrations: [new Sentry.BrowserTracing()],
  tracesSampleRate: 1.0,
});

sentry-python:

import sentry_sdk

sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    traces_sample_rate=1.0
)

Both SDKs offer similar initialization processes, but sentry-javascript provides more options for integrations and environment-specific configurations. The Python SDK has a simpler setup, which can be advantageous for smaller projects or those new to error tracking.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Sentry for Python

Bad software is everywhere, and we're tired of it. Sentry is on a mission to help developers write better software faster, so we can get back to enjoying technology. If you want to join us Check out our open positions.

Discord Twitter Follow PyPi page link -- version python Build Status


Official Sentry SDK for Python

Welcome to the official Python SDK for Sentry.

📦 Getting Started

Prerequisites

You need a Sentry account and project.

Installation

Getting Sentry into your project is straightforward. Just run this command in your terminal:

pip install --upgrade sentry-sdk

Basic Configuration

Here's a quick configuration example to get Sentry up and running:

import sentry_sdk

sentry_sdk.init(
    "https://12927b5f211046b575ee51fd8b1ac34f@o1.ingest.sentry.io/1",  # Your DSN here

    # Set traces_sample_rate to 1.0 to capture 100%
    # of traces for performance monitoring.
    traces_sample_rate=1.0,
)

With this configuration, Sentry will monitor for exceptions and performance issues.

Quick Usage Example

To generate some events that will show up in Sentry, you can log messages or capture errors:

import sentry_sdk
sentry_sdk.init(...)  # same as above

sentry_sdk.capture_message("Hello Sentry!")  # You'll see this in your Sentry dashboard.

raise ValueError("Oops, something went wrong!")  # This will create an error event in Sentry.

📚 Documentation

For more details on advanced usage, integrations, and customization, check out the full documentation on https://docs.sentry.io.

🧩 Integrations

Sentry integrates with a ton of popular Python libraries and frameworks, including FastAPI, Django, Celery, OpenAI and many, many more. Check out the full list of integrations to get the full picture.

🚧 Migrating Between Versions?

From 1.x to 2.x

If you're using the older 1.x version of the SDK, now's the time to upgrade to 2.x. It includes significant upgrades and new features. Check our migration guide for assistance.

From raven-python

Using the legacy raven-python client? It's now in maintenance mode, and we recommend migrating to the new SDK for an improved experience. Get all the details in our migration guide.

🙌 Want to Contribute?

We'd love your help in improving the Sentry SDK! Whether it's fixing bugs, adding features, writing new integrations, or enhancing documentation, every contribution is valuable.

For details on how to contribute, please read our contribution guide and explore the open issues.

🛟 Need Help?

If you encounter issues or need help setting up or configuring the SDK, don't hesitate to reach out to the Sentry Community on Discord. There is a ton of great people there ready to help!

🔗 Resources

Here are all resources to help you make the most of Sentry:

📃 License

The SDK is open-source and available under the MIT license. Check out the LICENSE file for more information.

😘 Contributors

Thanks to everyone who has helped improve the SDK!