From a55c85f42c379f97cc92dc494e4ad1a1e4a6dae8 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Wed, 14 Oct 2026 21:40:25 +0000 Subject: [PATCH 1/6] feat(docs): Apply new quick start template to Python quick start guides Co-Authored-By: Shannon Anahata --- docs/platforms/python/index.mdx | 123 +++++++-------- .../python/integrations/celery/index.mdx | 143 +++++++++--------- .../python/integrations/django/index.mdx | 113 ++++++++------ .../python/integrations/fastapi/index.mdx | 118 ++++++++++----- .../python/integrations/flask/index.mdx | 119 ++++++++++----- .../python/integrations/starlette/index.mdx | 120 ++++++++++----- 6 files changed, 449 insertions(+), 287 deletions(-) diff --git a/docs/platforms/python/index.mdx b/docs/platforms/python/index.mdx index 2c896974d26f6..16d8931a105bf 100644 --- a/docs/platforms/python/index.mdx +++ b/docs/platforms/python/index.mdx @@ -1,6 +1,6 @@ --- title: Python -description: Learn how to set up Sentry in your Python app, capture your first errors and traces, and view them in Sentry. +description: Learn how to set up Sentry in your Python app, capture your first events and traces, and view them in Sentry. caseStyle: snake_case supportLevel: production sdk: sentry.python @@ -28,11 +28,8 @@ This guide focuses on plain Python. If you're working with Django, FastAPI, Star ## Configure -Choose the features you want to configure, and this guide will show you how: - - +**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). Standard-library `logging` and Loguru records require configuring their logging integrations. +This guide also enables **Tracing** and **Profiling**. @@ -46,41 +43,34 @@ Configuration should happen as **early as possible** in your application's lifec Import and initialize the SDK in your app's entry point: +The snippet also turns on: + +- Tracing: via `traces_sample_rate` +- Profiling: via `profile_session_sample_rate` and `profile_lifecycle` + +Don't need a feature? Remove its options from the snippet. + ```python import sentry_sdk -# ___PRODUCT_OPTION_START___ metrics -from sentry_sdk import metrics -# ___PRODUCT_OPTION_END___ metrics - sentry_sdk.init( dsn="___PUBLIC_DSN___", - # Add request headers and IP for users, - # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info + # Send request headers and user IP address. send_default_pii=True, - # ___PRODUCT_OPTION_START___ performance - # Set traces_sample_rate to 1.0 to capture 100% - # of transactions for tracing. - # see https://docs.sentry.io/platforms/python/configuration/options/#traces_sample_rate for more info + # Enables Tracing. + # Set to 1.0 to capture 100% of spans for tracing. + # We recommend reducing this value in production. traces_sample_rate=1.0, - # ___PRODUCT_OPTION_END___ performance - # ___PRODUCT_OPTION_START___ profiling - # Enables continuous profiling. - # To collect profiles for all profile sessions, - # set `profile_session_sample_rate` to 1.0. - # see https://docs.sentry.io/platforms/python/configuration/options/#profile_session_sample_rate for more info + # Enables Profiling. + # Set to 1.0 to profile 100% of sessions. profile_session_sample_rate=1.0, - - # Profiles will be automatically collected while - # there is an active span. - # see https://docs.sentry.io/platforms/python/configuration/options/#profile_lifecycle for more info + # Profiles are collected while at least one span is active. profile_lifecycle="trace", - # ___PRODUCT_OPTION_END___ profiling ) ``` @@ -100,11 +90,6 @@ In async programs, we recommend to initialize the Sentry SDK inside an `async` f ```python import asyncio import sentry_sdk -# ___PRODUCT_OPTION_START___ metrics -from sentry_sdk import metrics -# ___PRODUCT_OPTION_END___ metrics - - async def main(): sentry_sdk.init( ... # same as above @@ -117,7 +102,6 @@ asyncio.run(main()) - ### Instrumenting Your App The Sentry SDK automatically enables integrations for many popular libraries, so operations like HTTP requests or database queries made with supported libraries will be captured as spans automatically. @@ -145,52 +129,77 @@ def some_function(): - +## Send Logs -## Verify Your Setup + + + -Let's test your setup and confirm that data reaches your Sentry project. +Use `sentry_sdk.logger` to send structured logs at different levels. You can include searchable attributes with each message. + +To capture records from Python's standard-library `logging` module or Loguru, configure `capture_sentry_logs=True` on the corresponding integration. See the standard logging and Loguru integration guides. - +See Set Up Logs for all available logging methods and formatting options. -### Issues + + + +```python +import sentry_sdk + +sentry_sdk.logger.info("Order processed {order_id}", order_id="order-123") +sentry_sdk.logger.warning("Rate limit reached", attributes={"endpoint": "/api/orders"}) +``` + + + + + +## Send Application Metrics -To verify that Sentry captures errors and creates issues in your Sentry project, add this intentional error to your application: +Use `sentry_sdk.metrics` to send counters, gauges, and distributions from your app. Metrics are enabled by default after you initialize the SDK. + +See Set Up Metrics for all available metric types and configuration options. -```py +```python import sentry_sdk -division_by_zero = 1 / 0 +sentry_sdk.metrics.count("checkout.failed", 1) +sentry_sdk.metrics.gauge("active_connections", 42) +sentry_sdk.metrics.distribution("api_latency", 187, unit="millisecond") ``` - - - - - +## Verify Your Setup - +Let's test your setup and confirm that data reaches your Sentry project. - + + + - +Add an intentional error to your application to confirm that Sentry captures it: - + + - +```python +1 / 0 +``` - + + + ### View Captured Data in Sentry @@ -200,15 +209,11 @@ Now, head over to your project on [Sentry.io](https://sentry.io) to view the col ## Next Steps -At this point, you should have integrated Sentry into your Python application and should already be sending data to your Sentry project. - -Now's a good time to customize your setup and look into more advanced topics. -Our next recommended steps for you are: +At this point, you should have integrated Sentry into your Python application. Here's what to explore next: - Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup -- Continue to customize your configuration -- Learn more about manually capturing errors or messages -- Dive straight into the API with our [API docs](https://getsentry.github.io/sentry-python/) +- Set up Agent Tracing to monitor your AI systems +- Learn how to manually capture errors diff --git a/docs/platforms/python/integrations/celery/index.mdx b/docs/platforms/python/integrations/celery/index.mdx index 8e48fa449ab45..99ac3e44b186b 100644 --- a/docs/platforms/python/integrations/celery/index.mdx +++ b/docs/platforms/python/integrations/celery/index.mdx @@ -1,6 +1,6 @@ --- title: Celery -description: "Learn how to set up Sentry in your Celery app, capture your first errors and traces, and view them in Sentry." +description: "Learn how to set up Sentry in your Celery app, capture your first events and traces, and view them in Sentry." --- @@ -22,11 +22,8 @@ You need: ## Configure -Choose the features you want to configure, and this guide will show you how: - - +**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). Standard-library `logging` and Loguru records require configuring their logging integrations. +This guide also enables **Tracing** and **Profiling**. @@ -34,6 +31,13 @@ Choose the features you want to configure, and this guide will show you how: Configuration should happen as **early as possible** in your application's lifecycle. +The init snippets also turn on: + +- Tracing: via `traces_sample_rate` +- Profiling: via `profile_session_sample_rate` and `profile_lifecycle` + +Don't need a feature? Remove its options from the snippets. + If you have the `celery` package in your dependencies, the Celery integration will be enabled automatically when you initialize the Sentry SDK. @@ -51,9 +55,6 @@ When using Celery without Django, you'll need to initialize the Sentry SDK in bo ```python {filename:tasks.py} from celery import Celery, signals import sentry_sdk -# ___PRODUCT_OPTION_START___ metrics -from sentry_sdk import metrics -# ___PRODUCT_OPTION_END___ metrics # Initializing Celery app = Celery("tasks", broker="...") @@ -64,21 +65,16 @@ def init_sentry(**_kwargs): sentry_sdk.init( dsn="___PUBLIC_DSN___", # Add request headers and IP for users, - # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info send_default_pii=True, - # ___PRODUCT_OPTION_START___ performance - # Set traces_sample_rate to 1.0 to capture 100% - # of transactions for tracing. + # Enables Tracing. + # Set to 1.0 to capture 100% of spans for tracing. + # We recommend reducing this value in production. traces_sample_rate=1.0, - # ___PRODUCT_OPTION_END___ performance - # ___PRODUCT_OPTION_START___ profiling - # To collect profiles for all profile sessions, - # set `profile_session_sample_rate` to 1.0. + # Enables Profiling. + # Set to 1.0 to profile 100% of sessions. profile_session_sample_rate=1.0, - # Profiles will be automatically collected while - # there is an active span. + # Profiles are collected while at least one span is active. profile_lifecycle="trace", - # ___PRODUCT_OPTION_END___ profiling ) # Task definitions go here @@ -94,30 +90,22 @@ The [`celeryd_init`](https://docs.celeryq.dev/en/stable/userguide/signals.html?# ```python {filename:main.py} from tasks import add import sentry_sdk -# ___PRODUCT_OPTION_START___ metrics -from sentry_sdk import metrics -# ___PRODUCT_OPTION_END___ metrics def main(): # Initializing Sentry SDK in our process sentry_sdk.init( dsn="___PUBLIC_DSN___", # Add data like request headers and IP for users, if applicable; - # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info send_default_pii=True, - # ___PRODUCT_OPTION_START___ performance - # Set traces_sample_rate to 1.0 to capture 100% - # of transactions for tracing. + # Enables Tracing. + # Set to 1.0 to capture 100% of spans for tracing. + # We recommend reducing this value in production. traces_sample_rate=1.0, - # ___PRODUCT_OPTION_END___ performance - # ___PRODUCT_OPTION_START___ profiling - # To collect profiles for all profile sessions, - # set `profile_session_sample_rate` to 1.0. + # Enables Profiling. + # Set to 1.0 to profile 100% of sessions. profile_session_sample_rate=1.0, - # Profiles will be automatically collected while - # there is an active span. + # Profiles are collected while at least one span is active. profile_lifecycle="trace", - # ___PRODUCT_OPTION_END___ profiling ) # Enqueueing a task to be processed by Celery @@ -141,7 +129,6 @@ Sentry automatically captures errors and exceptions raised in your Celery tasks To learn how to manually report issues, see Capturing Errors. - ### Instrumenting Your App The Sentry SDK automatically creates spans for your Celery tasks, and propagates the trace from the code that enqueues a task to the worker that runs it. @@ -211,63 +198,79 @@ The fix for the custom headers propagation issue was introduced to the Celery pr - - -## Verify Your Setup - -Let's test your setup and confirm that data reaches your Sentry project. - -### Issues +## Send Logs -To verify that Sentry captures errors and creates issues in your Sentry project, add this intentional error to your application: +Use `sentry_sdk.logger` to send structured logs at different levels. You can include searchable attributes with each message. + +To capture records from Python's standard-library `logging` module or Loguru, configure `capture_sentry_logs=True` on the corresponding integration. See the standard logging and Loguru integration guides. + +See Set Up Logs for all available logging methods and formatting options. -```python {filename:tasks.py} -from celery import Celery, signals +```python import sentry_sdk -app = Celery("tasks", broker="...") - -@signals.celeryd_init.connect -def init_sentry(**_kwargs): - sentry_sdk.init(...) # same as above - -@app.task -def debug_sentry(): - 1/0 +sentry_sdk.logger.info("Order processed {order_id}", order_id="order-123") +sentry_sdk.logger.warning("Rate limit reached", attributes={"endpoint": "/api/orders"}) ``` -Trigger the error by calling `debug_sentry.delay()`. +## Send Application Metrics -To confirm that your SDK is initialized on worker start, pass `debug=True` to `sentry_sdk.init()`. This will add extra output to your Celery logs when the SDK is initialized. If you see the output during worker startup, and not just after a task has started, then it's working correctly. + + + - +Use `sentry_sdk.metrics` to send counters, gauges, and distributions from your app. Metrics are enabled by default after you initialize the SDK. - +See Set Up Metrics for all available metric types and configuration options. - + + - +```python +import sentry_sdk + +sentry_sdk.metrics.count("checkout.failed", 1) +sentry_sdk.metrics.gauge("active_connections", 42) +sentry_sdk.metrics.distribution("api_latency", 187, unit="millisecond") +``` + + + + - +## Verify Your Setup + +Let's test your setup and confirm that data reaches your Sentry project. + + + + - +Add a task that raises an exception, then call `debug_sentry.delay()` from a running Celery worker: - + + - +```python +@app.task +def debug_sentry(): + 1 / 0 +``` - + + + ### View Captured Data in Sentry @@ -310,12 +313,8 @@ If this is set to `False`: - errors in Celery tasks won't be matched to the triggering function. - your Celery tasks will start a new trace and won't be connected to the trace in the calling function. - - See [Distributed Traces](#distributed-traces) to learn how to get more fine-grained control over distributed tracing in Celery tasks. - - @@ -338,7 +337,11 @@ See Celery Beat Auto Discovery

+At this point, you should have integrated Sentry into your Celery application. Here's what to explore next: + +- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup +- Set up Agent Tracing to monitor your AI systems +- Learn how to manually capture errors diff --git a/docs/platforms/python/integrations/django/index.mdx b/docs/platforms/python/integrations/django/index.mdx index 14e20a608cba7..0b79a5f01c0d0 100644 --- a/docs/platforms/python/integrations/django/index.mdx +++ b/docs/platforms/python/integrations/django/index.mdx @@ -2,7 +2,7 @@ title: Django caseStyle: snake_case supportLevel: production -description: "Learn how to set up Sentry in your Django app, capture your first errors and traces, and view them in Sentry." +description: "Learn how to set up Sentry in your Django app, capture your first events and traces, and view them in Sentry." --- @@ -30,11 +30,8 @@ If you're using Python 3.7, Django applications with `channels` 2.0 will be corr ## Configure -Choose the features you want to configure, and this guide will show you how: - - +**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). Standard-library `logging` and Loguru records require configuring their logging integrations. +This guide also enables **Tracing** and **Profiling**. @@ -48,33 +45,32 @@ Configuration should happen as **early as possible** in your application's lifec To configure the Sentry SDK, initialize it in your `settings.py` file: +The snippet also turns on: + +- Tracing: via `traces_sample_rate` +- Profiling: via `profile_session_sample_rate` and `profile_lifecycle` + +Don't need a feature? Remove its options from the snippet. + ```python {filename:settings.py} import sentry_sdk -# ___PRODUCT_OPTION_START___ metrics -from sentry_sdk import metrics -# ___PRODUCT_OPTION_END___ metrics sentry_sdk.init( dsn="___PUBLIC_DSN___", # Add data like request headers and IP for users; - # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info send_default_pii=True, - # ___PRODUCT_OPTION_START___ performance - # Set traces_sample_rate to 1.0 to capture 100% - # of transactions for tracing. + # Enables Tracing. + # Set to 1.0 to capture 100% of spans for tracing. + # We recommend reducing this value in production. traces_sample_rate=1.0, - # ___PRODUCT_OPTION_END___ performance - # ___PRODUCT_OPTION_START___ profiling - # To collect profiles for all profile sessions, - # set `profile_session_sample_rate` to 1.0. + # Enables Profiling. + # Set to 1.0 to profile 100% of sessions. profile_session_sample_rate=1.0, - # Profiles will be automatically collected while - # there is an active span. + # Profiles are collected while at least one span is active. profile_lifecycle="trace", - # ___PRODUCT_OPTION_END___ profiling ) ``` @@ -95,7 +91,6 @@ You can also expect the following for your Django project: To learn how to manually report issues, see Capturing Errors. - ### Instrumenting Your App @@ -110,58 +105,82 @@ The Sentry SDK automatically monitors the following parts of your Django project You can also manually capture performance data – see Custom Instrumentation to learn more. - +## Send Logs -## Verify Your Setup + + + -Let's test your setup and confirm that data reaches your Sentry project. +Use `sentry_sdk.logger` to send structured logs at different levels. You can include searchable attributes with each message. + +To capture records from Python's standard-library `logging` module or Loguru, configure `capture_sentry_logs=True` on the corresponding integration. See the standard logging and Loguru integration guides. + +See Set Up Logs for all available logging methods and formatting options. - + + + +```python +import sentry_sdk + +sentry_sdk.logger.info("Order processed {order_id}", order_id="order-123") +sentry_sdk.logger.warning("Rate limit reached", attributes={"endpoint": "/api/orders"}) +``` + + + + -### Issues +## Send Application Metrics -To verify that Sentry captures errors and creates issues in your Sentry project, add this intentional error to your application: +Use `sentry_sdk.metrics` to send counters, gauges, and distributions from your app. Metrics are enabled by default after you initialize the SDK. + +See Set Up Metrics for all available metric types and configuration options. ```python -from django.urls import path - -def trigger_error(request): - division_by_zero = 1 / 0 +import sentry_sdk -urlpatterns = [ - path('sentry-debug/', trigger_error), - # ... -] +sentry_sdk.metrics.count("checkout.failed", 1) +sentry_sdk.metrics.gauge("active_connections", 42) +sentry_sdk.metrics.distribution("api_latency", 187, unit="millisecond") ``` - +## Verify Your Setup - +Let's test your setup and confirm that data reaches your Sentry project. - + + + - +Add a view that raises an exception and route it in your Django application: - + + - +```python +from django.urls import path - +def trigger_error(request): + 1 / 0 - +urlpatterns = [path("sentry-debug/", trigger_error)] +``` - + + + ### View Captured Data in Sentry @@ -269,7 +288,11 @@ The default is `{*range(500, 600)}`, meaning that all 5xx status codes are repor ## Next Steps - +At this point, you should have integrated Sentry into your Django application. Here's what to explore next: + +- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup +- Set up Agent Tracing to monitor your AI systems +- Learn how to manually capture errors diff --git a/docs/platforms/python/integrations/fastapi/index.mdx b/docs/platforms/python/integrations/fastapi/index.mdx index 299ae9ebe47e9..feb8da0880cf5 100644 --- a/docs/platforms/python/integrations/fastapi/index.mdx +++ b/docs/platforms/python/integrations/fastapi/index.mdx @@ -1,6 +1,6 @@ --- title: FastAPI -description: Learn how to set up Sentry in your FastAPI app, capture your first errors and traces, and view them in Sentry. +description: Learn how to set up Sentry in your FastAPI app, capture your first events and traces, and view them in Sentry. og_image: /og-images/platforms-python-integrations-fastapi.png --- @@ -23,11 +23,8 @@ You need: ## Configure -Choose the features you want to configure, and this guide will show you how: - - +**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). Standard-library `logging` and Loguru records require configuring their logging integrations. +This guide also enables **Tracing** and **Profiling**. @@ -47,13 +44,35 @@ If you have the `fastapi` package in your dependencies, the Sentry FastAPI integ Import and initialize the SDK in your app's entry point: +The snippet also turns on: + +- Tracing: via `traces_sample_rate` +- Profiling: via `profile_session_sample_rate` and `profile_lifecycle` + +Don't need a feature? Remove its options from the snippet. + - +```python +import sentry_sdk + +sentry_sdk.init( + dsn="___PUBLIC_DSN___", + send_default_pii=True, + + # Enables Tracing. + # Set to 1.0 to capture 100% of spans for tracing. + # We recommend reducing this value in production. + traces_sample_rate=1.0, + + # Enables Profiling. + # Set to 1.0 to profile 100% of sessions. + profile_session_sample_rate=1.0, + # Profiles are collected while at least one span is active. + profile_lifecycle="trace", +) +``` @@ -72,8 +91,6 @@ You can also expect the following for your FastAPI project: To learn how to manually report issues, see Capturing Errors. - - ### Instrumenting Your App The Sentry SDK automatically monitors the following parts of your FastAPI project: @@ -85,56 +102,79 @@ The Sentry SDK automatically monitors the following parts of your FastAPI projec You can also manually capture performance data – see Custom Instrumentation to learn more. - +## Send Logs -## Verify Your Setup + + + -Let's test your setup and confirm that data reaches your Sentry project. +Use `sentry_sdk.logger` to send structured logs at different levels. You can include searchable attributes with each message. + +To capture records from Python's standard-library `logging` module or Loguru, configure `capture_sentry_logs=True` on the corresponding integration. See the standard logging and Loguru integration guides. + +See Set Up Logs for all available logging methods and formatting options. + + + + +```python +import sentry_sdk + +sentry_sdk.logger.info("Order processed {order_id}", order_id="order-123") +sentry_sdk.logger.warning("Rate limit reached", attributes={"endpoint": "/api/orders"}) +``` + + + + -### Issues +## Send Application Metrics -To verify that Sentry captures errors and creates issues in your Sentry project, add this intentional error to your application: +Use `sentry_sdk.metrics` to send counters, gauges, and distributions from your app. Metrics are enabled by default after you initialize the SDK. + +See Set Up Metrics for all available metric types and configuration options. ```python -from fastapi import FastAPI +import sentry_sdk -sentry_sdk.init(...) # same as above - -app = FastAPI() - -@app.get("/sentry-debug") -async def trigger_error(): - division_by_zero = 1 / 0 +sentry_sdk.metrics.count("checkout.failed", 1) +sentry_sdk.metrics.gauge("active_connections", 42) +sentry_sdk.metrics.distribution("api_latency", 187, unit="millisecond") ``` - - - - - +## Verify Your Setup - +Let's test your setup and confirm that data reaches your Sentry project. - + + + - +Add this route to your FastAPI app, then request `/sentry-debug`: - + + - +```python +@app.get("/sentry-debug") +async def trigger_error(): + 1 / 0 +``` - + + + ### View Captured Data in Sentry @@ -260,7 +300,11 @@ Note that `OPTIONS` and `HEAD` are excluded by default. ## Next Steps - +At this point, you should have integrated Sentry into your FastAPI application. Here's what to explore next: + +- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup +- Set up Agent Tracing to monitor your AI systems +- Learn how to manually capture errors diff --git a/docs/platforms/python/integrations/flask/index.mdx b/docs/platforms/python/integrations/flask/index.mdx index 403f562684b8f..af49c3ed36668 100644 --- a/docs/platforms/python/integrations/flask/index.mdx +++ b/docs/platforms/python/integrations/flask/index.mdx @@ -1,6 +1,6 @@ --- title: Flask -description: "Learn how to set up Sentry in your Flask app, capture your first errors and traces, and view them in Sentry." +description: "Learn how to set up Sentry in your Flask app, capture your first events and traces, and view them in Sentry." --- @@ -22,11 +22,8 @@ You need: ## Configure -Choose the features you want to configure, and this guide will show you how: - - +**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). Standard-library `logging` and Loguru records require configuring their logging integrations. +This guide also enables **Tracing** and **Profiling**. @@ -47,13 +44,35 @@ The SDK hooks into Flask's signals, not anything on the app object. Import and initialize the SDK in your app's entry point: +The snippet also turns on: + +- Tracing: via `traces_sample_rate` +- Profiling: via `profile_session_sample_rate` and `profile_lifecycle` + +Don't need a feature? Remove its options from the snippet. + - +```python +import sentry_sdk + +sentry_sdk.init( + dsn="___PUBLIC_DSN___", + send_default_pii=True, + + # Enables Tracing. + # Set to 1.0 to capture 100% of spans for tracing. + # We recommend reducing this value in production. + traces_sample_rate=1.0, + + # Enables Profiling. + # Set to 1.0 to profile 100% of sessions. + profile_session_sample_rate=1.0, + # Profiles are collected while at least one span is active. + profile_lifecycle="trace", +) +``` @@ -70,65 +89,81 @@ You can also expect the following for your Flask app: - Request data will be attached to all events: HTTP method, URL, headers, form data, JSON payloads. Sentry excludes raw bodies and multipart file uploads. - Logs emitted by any `app.logger` or _any_ logger will be recorded by the [Logging](/platforms/python/integrations/logging/) integration (this integration is enabled by default). - - - +## Send Logs -## Verify Your Setup + + + -Let's test your setup and confirm that data reaches your Sentry project. +Use `sentry_sdk.logger` to send structured logs at different levels. You can include searchable attributes with each message. + +To capture records from Python's standard-library `logging` module or Loguru, configure `capture_sentry_logs=True` on the corresponding integration. See the standard logging and Loguru integration guides. + +See Set Up Logs for all available logging methods and formatting options. + + + + +```python +import sentry_sdk - +sentry_sdk.logger.info("Order processed {order_id}", order_id="order-123") +sentry_sdk.logger.warning("Rate limit reached", attributes={"endpoint": "/api/orders"}) +``` + + + + -### Issues +## Send Application Metrics -To verify that Sentry captures errors and creates issues in your Sentry project, add this intentional error to your application: +Use `sentry_sdk.metrics` to send counters, gauges, and distributions from your app. Metrics are enabled by default after you initialize the SDK. + +See Set Up Metrics for all available metric types and configuration options. - ```python import sentry_sdk -from flask import Flask - -sentry_sdk.init(...) # same as above - -app = Flask(__name__) -@app.route("/") -def hello_world(): - 1 / 0 # raises an error - return "

Hello, World!

" +sentry_sdk.metrics.count("checkout.failed", 1) +sentry_sdk.metrics.gauge("active_connections", 42) +sentry_sdk.metrics.distribution("api_latency", 187, unit="millisecond") ```
- - - - - +## Verify Your Setup - +Let's test your setup and confirm that data reaches your Sentry project. - + + + - +Add this route to your Flask app, then request `/sentry-debug`: - + + - +```python +@app.route("/sentry-debug") +def trigger_error(): + 1 / 0 +``` - + + + ### View Captured Data in Sentry @@ -199,7 +234,11 @@ Note that `OPTIONS` and `HEAD` are excluded by default. ## Next Steps - +At this point, you should have integrated Sentry into your Flask application. Here's what to explore next: + +- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup +- Set up Agent Tracing to monitor your AI systems +- Learn how to manually capture errors diff --git a/docs/platforms/python/integrations/starlette/index.mdx b/docs/platforms/python/integrations/starlette/index.mdx index 701f656eff319..7d49e56e16261 100644 --- a/docs/platforms/python/integrations/starlette/index.mdx +++ b/docs/platforms/python/integrations/starlette/index.mdx @@ -1,6 +1,6 @@ --- title: Starlette -description: "Learn how to set up Sentry in your Starlette app, capture your first errors and traces, and view them in Sentry." +description: "Learn how to set up Sentry in your Starlette app, capture your first events and traces, and view them in Sentry." --- @@ -22,11 +22,8 @@ You need: ## Configure -Choose the features you want to configure, and this guide will show you how: - - +**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). Standard-library `logging` and Loguru records require configuring their logging integrations. +This guide also enables **Tracing** and **Profiling**. @@ -46,13 +43,35 @@ If you have the `starlette` package in your dependencies, the Sentry Starlette i Import and initialize the SDK in your app's entry point: +The snippet also turns on: + +- Tracing: via `traces_sample_rate` +- Profiling: via `profile_session_sample_rate` and `profile_lifecycle` + +Don't need a feature? Remove its options from the snippet. + - +```python +import sentry_sdk + +sentry_sdk.init( + dsn="___PUBLIC_DSN___", + send_default_pii=True, + + # Enables Tracing. + # Set to 1.0 to capture 100% of spans for tracing. + # We recommend reducing this value in production. + traces_sample_rate=1.0, + + # Enables Profiling. + # Set to 1.0 to profile 100% of sessions. + profile_session_sample_rate=1.0, + # Profiles are collected while at least one span is active. + profile_lifecycle="trace", +) +``` @@ -71,58 +90,83 @@ You can also expect the following for your Starlette project: To learn how to manually report issues, see Capturing Errors. -## Verify Your Setup - -Let's test your setup and confirm that data reaches your Sentry project. - -### Issues +## Send Logs -To verify that Sentry captures errors and creates issues in your Sentry project, add this intentional error to your application: +Use `sentry_sdk.logger` to send structured logs at different levels. You can include searchable attributes with each message. + +To capture records from Python's standard-library `logging` module or Loguru, configure `capture_sentry_logs=True` on the corresponding integration. See the standard logging and Loguru integration guides. + +See Set Up Logs for all available logging methods and formatting options. ```python -from starlette.applications import Starlette -from starlette.routing import Route +import sentry_sdk -sentry_sdk.init(...) # same as above +sentry_sdk.logger.info("Order processed {order_id}", order_id="order-123") +sentry_sdk.logger.warning("Rate limit reached", attributes={"endpoint": "/api/orders"}) +``` -async def trigger_error(request): - division_by_zero = 1 / 0 + + + + +## Send Application Metrics -app = Starlette(routes=[ - Route("/sentry-debug", trigger_error), -]) + + + + +Use `sentry_sdk.metrics` to send counters, gauges, and distributions from your app. Metrics are enabled by default after you initialize the SDK. + +See Set Up Metrics for all available metric types and configuration options. + + + + +```python +import sentry_sdk + +sentry_sdk.metrics.count("checkout.failed", 1) +sentry_sdk.metrics.gauge("active_connections", 42) +sentry_sdk.metrics.distribution("api_latency", 187, unit="millisecond") ``` -Point your browser to [http://localhost:8000/sentry-debug](http://localhost:8000/sentry-debug) to trigger the error which will be sent to Sentry. - - +## Verify Your Setup - +Let's test your setup and confirm that data reaches your Sentry project. - + + + - +Add this route to your Starlette app, then request `/sentry-debug`: - + + - +```python +from starlette.applications import Starlette +from starlette.routing import Route - +async def trigger_error(request): + 1 / 0 - +app = Starlette(routes=[Route("/sentry-debug", trigger_error)]) +``` - + + + ### View Captured Data in Sentry @@ -222,7 +266,11 @@ Note that `OPTIONS` and `HEAD` are excluded by default. ## Next Steps - +At this point, you should have integrated Sentry into your Starlette application. Here's what to explore next: + +- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup +- Set up Agent Tracing to monitor your AI systems +- Learn how to manually capture errors From 2ad3e824e834937447ad6c882f76e46c460a9b27 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Wed, 14 Oct 2026 21:48:11 +0000 Subject: [PATCH 2/6] ref(docs): Tighten Python quick start Configure copy Co-Authored-By: Shannon Anahata --- docs/platforms/python/index.mdx | 2 +- docs/platforms/python/integrations/celery/index.mdx | 2 +- docs/platforms/python/integrations/django/index.mdx | 2 +- docs/platforms/python/integrations/fastapi/index.mdx | 2 +- docs/platforms/python/integrations/flask/index.mdx | 2 +- docs/platforms/python/integrations/starlette/index.mdx | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/platforms/python/index.mdx b/docs/platforms/python/index.mdx index 16d8931a105bf..120862248cf92 100644 --- a/docs/platforms/python/index.mdx +++ b/docs/platforms/python/index.mdx @@ -28,7 +28,7 @@ This guide focuses on plain Python. If you're working with Django, FastAPI, Star ## Configure -**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). Standard-library `logging` and Loguru records require configuring their logging integrations. +**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). This guide also enables **Tracing** and **Profiling**. diff --git a/docs/platforms/python/integrations/celery/index.mdx b/docs/platforms/python/integrations/celery/index.mdx index 99ac3e44b186b..ec7ac345d7cb7 100644 --- a/docs/platforms/python/integrations/celery/index.mdx +++ b/docs/platforms/python/integrations/celery/index.mdx @@ -22,7 +22,7 @@ You need: ## Configure -**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). Standard-library `logging` and Loguru records require configuring their logging integrations. +**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). This guide also enables **Tracing** and **Profiling**. diff --git a/docs/platforms/python/integrations/django/index.mdx b/docs/platforms/python/integrations/django/index.mdx index 0b79a5f01c0d0..9b9441bfe08d2 100644 --- a/docs/platforms/python/integrations/django/index.mdx +++ b/docs/platforms/python/integrations/django/index.mdx @@ -30,7 +30,7 @@ If you're using Python 3.7, Django applications with `channels` 2.0 will be corr ## Configure -**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). Standard-library `logging` and Loguru records require configuring their logging integrations. +**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). This guide also enables **Tracing** and **Profiling**. diff --git a/docs/platforms/python/integrations/fastapi/index.mdx b/docs/platforms/python/integrations/fastapi/index.mdx index feb8da0880cf5..75c955141815f 100644 --- a/docs/platforms/python/integrations/fastapi/index.mdx +++ b/docs/platforms/python/integrations/fastapi/index.mdx @@ -23,7 +23,7 @@ You need: ## Configure -**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). Standard-library `logging` and Loguru records require configuring their logging integrations. +**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). This guide also enables **Tracing** and **Profiling**. diff --git a/docs/platforms/python/integrations/flask/index.mdx b/docs/platforms/python/integrations/flask/index.mdx index af49c3ed36668..5c43b32a15f05 100644 --- a/docs/platforms/python/integrations/flask/index.mdx +++ b/docs/platforms/python/integrations/flask/index.mdx @@ -22,7 +22,7 @@ You need: ## Configure -**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). Standard-library `logging` and Loguru records require configuring their logging integrations. +**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). This guide also enables **Tracing** and **Profiling**. diff --git a/docs/platforms/python/integrations/starlette/index.mdx b/docs/platforms/python/integrations/starlette/index.mdx index 7d49e56e16261..f53bee9f22391 100644 --- a/docs/platforms/python/integrations/starlette/index.mdx +++ b/docs/platforms/python/integrations/starlette/index.mdx @@ -22,7 +22,7 @@ You need: ## Configure -**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). Standard-library `logging` and Loguru records require configuring their logging integrations. +**Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). This guide also enables **Tracing** and **Profiling**. From 84dd2175329ba607fad9e21d6a554db8aecd5a98 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Wed, 14 Oct 2026 21:55:41 +0000 Subject: [PATCH 3/6] fix(docs): Update Starlette HTTPException link to starlette.dev --- docs/platforms/python/integrations/starlette/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/python/integrations/starlette/index.mdx b/docs/platforms/python/integrations/starlette/index.mdx index f53bee9f22391..0e901973d6d79 100644 --- a/docs/platforms/python/integrations/starlette/index.mdx +++ b/docs/platforms/python/integrations/starlette/index.mdx @@ -234,7 +234,7 @@ In the code example, the transaction name will be: A `set` of integers that will determine which status codes should be reported to Sentry. -The `failed_request_status_codes` option determines whether [`HTTPException`](https://www.starlette.io/exceptions/#httpexception) exceptions should be +The `failed_request_status_codes` option determines whether [`HTTPException`](https://starlette.dev/exceptions/#httpexception) exceptions should be reported to Sentry. Unhandled exceptions that don't have a `status_code` attribute will always be reported to Sentry. Examples of valid `failed_request_status_codes`: From c735dcfb8db28b1ee8d34bf16bc9c9bc28afd9c0 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Thu, 15 Oct 2026 22:14:25 +0000 Subject: [PATCH 4/6] ref(docs): Remove SplitLayout wrappers from Python quick starts Co-Authored-By: Shannon Anahata --- docs/platforms/python/index.mdx | 66 ------------------- .../python/integrations/celery/index.mdx | 44 ------------- .../python/integrations/django/index.mdx | 44 ------------- .../python/integrations/fastapi/index.mdx | 55 ---------------- .../python/integrations/flask/index.mdx | 55 ---------------- .../python/integrations/starlette/index.mdx | 55 ---------------- 6 files changed, 319 deletions(-) diff --git a/docs/platforms/python/index.mdx b/docs/platforms/python/index.mdx index 120862248cf92..a4f841bac01ba 100644 --- a/docs/platforms/python/index.mdx +++ b/docs/platforms/python/index.mdx @@ -37,10 +37,6 @@ This guide also enables **Tracing** and **Profiling**. Configuration should happen as **early as possible** in your application's lifecycle. - - - - Import and initialize the SDK in your app's entry point: The snippet also turns on: @@ -50,9 +46,6 @@ The snippet also turns on: Don't need a feature? Remove its options from the snippet. - - - ```python import sentry_sdk sentry_sdk.init( @@ -74,19 +67,8 @@ sentry_sdk.init( ) ``` - - - - - - - - In async programs, we recommend to initialize the Sentry SDK inside an `async` function to ensure async code is instrumented properly. If possible, call `sentry_sdk.init()` at the beginning of the first `async` function you call: - - - ```python import asyncio import sentry_sdk @@ -98,25 +80,14 @@ async def main(): asyncio.run(main()) ``` - - - - ### Instrumenting Your App The Sentry SDK automatically enables integrations for many popular libraries, so operations like HTTP requests or database queries made with supported libraries will be captured as spans automatically. - - - - However, spans are only created within an existing transaction. If you're not using a supported framework that creates transactions automatically, you'll need to create them manually using `sentry_sdk.start_transaction()`. See Custom Instrumentation for more info. - - - ```python import sentry_sdk @@ -125,25 +96,14 @@ def some_function(): ... ``` - - - - ## Send Logs - - - - Use `sentry_sdk.logger` to send structured logs at different levels. You can include searchable attributes with each message. To capture records from Python's standard-library `logging` module or Loguru, configure `capture_sentry_logs=True` on the corresponding integration. See the standard logging and Loguru integration guides. See Set Up Logs for all available logging methods and formatting options. - - - ```python import sentry_sdk @@ -151,23 +111,12 @@ sentry_sdk.logger.info("Order processed {order_id}", order_id="order-123") sentry_sdk.logger.warning("Rate limit reached", attributes={"endpoint": "/api/orders"}) ``` - - - - ## Send Application Metrics - - - - Use `sentry_sdk.metrics` to send counters, gauges, and distributions from your app. Metrics are enabled by default after you initialize the SDK. See Set Up Metrics for all available metric types and configuration options. - - - ```python import sentry_sdk @@ -176,31 +125,16 @@ sentry_sdk.metrics.gauge("active_connections", 42) sentry_sdk.metrics.distribution("api_latency", 187, unit="millisecond") ``` - - - - ## Verify Your Setup Let's test your setup and confirm that data reaches your Sentry project. - - - - Add an intentional error to your application to confirm that Sentry captures it: - - - ```python 1 / 0 ``` - - - - ### View Captured Data in Sentry Now, head over to your project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear). diff --git a/docs/platforms/python/integrations/celery/index.mdx b/docs/platforms/python/integrations/celery/index.mdx index ec7ac345d7cb7..be968cbafb5d5 100644 --- a/docs/platforms/python/integrations/celery/index.mdx +++ b/docs/platforms/python/integrations/celery/index.mdx @@ -141,10 +141,6 @@ Distributed tracing extends the trace from the code running your Celery task to You can disable this globally with the `propagate_traces` option, documented in the [options](#options) below. If you set `propagate_traces` to `False`, all Celery tasks will start their own trace. - - - - If you want to have more fine-grained control over trace distribution, you can override the `propagate_traces` option by passing the `sentry-propagate-traces` header when starting the Celery task: @@ -153,9 +149,6 @@ The `CeleryIntegration` does not utilize the `traces_sample_rate` config option - - - ```python import sentry_sdk @@ -186,10 +179,6 @@ my_task_b.apply_async( # Note: overriding the tracing behaviour using `task_x.delay()` is not possible. ``` - - - - Sentry uses custom message headers for distributed tracing. For Celery versions 4.x, with [message protocol version 1](https://docs.celeryq.dev/en/stable/internals/protocol.html#version-1), this functionality is broken, and Celery fails to propagate custom headers to the worker. Protocol version 2, the default since Celery 4.0, is not affected. @@ -200,19 +189,12 @@ The fix for the custom headers propagation issue was introduced to the Celery pr ## Send Logs - - - - Use `sentry_sdk.logger` to send structured logs at different levels. You can include searchable attributes with each message. To capture records from Python's standard-library `logging` module or Loguru, configure `capture_sentry_logs=True` on the corresponding integration. See the standard logging and Loguru integration guides. See Set Up Logs for all available logging methods and formatting options. - - - ```python import sentry_sdk @@ -220,23 +202,12 @@ sentry_sdk.logger.info("Order processed {order_id}", order_id="order-123") sentry_sdk.logger.warning("Rate limit reached", attributes={"endpoint": "/api/orders"}) ``` - - - - ## Send Application Metrics - - - - Use `sentry_sdk.metrics` to send counters, gauges, and distributions from your app. Metrics are enabled by default after you initialize the SDK. See Set Up Metrics for all available metric types and configuration options. - - - ```python import sentry_sdk @@ -245,33 +216,18 @@ sentry_sdk.metrics.gauge("active_connections", 42) sentry_sdk.metrics.distribution("api_latency", 187, unit="millisecond") ``` - - - - ## Verify Your Setup Let's test your setup and confirm that data reaches your Sentry project. - - - - Add a task that raises an exception, then call `debug_sentry.delay()` from a running Celery worker: - - - ```python @app.task def debug_sentry(): 1 / 0 ``` - - - - ### View Captured Data in Sentry Now, head over to your project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear). diff --git a/docs/platforms/python/integrations/django/index.mdx b/docs/platforms/python/integrations/django/index.mdx index 9b9441bfe08d2..821d222f70ad4 100644 --- a/docs/platforms/python/integrations/django/index.mdx +++ b/docs/platforms/python/integrations/django/index.mdx @@ -39,10 +39,6 @@ This guide also enables **Tracing** and **Profiling**. Configuration should happen as **early as possible** in your application's lifecycle. - - - - To configure the Sentry SDK, initialize it in your `settings.py` file: The snippet also turns on: @@ -52,9 +48,6 @@ The snippet also turns on: Don't need a feature? Remove its options from the snippet. - - - ```python {filename:settings.py} import sentry_sdk @@ -74,10 +67,6 @@ sentry_sdk.init( ) ``` - - - - To further customize your setup, review the [Options section](#options) below. ### Capturing Errors @@ -107,19 +96,12 @@ You can also manually capture performance data – see standard logging and Loguru integration guides. See Set Up Logs for all available logging methods and formatting options. - - - ```python import sentry_sdk @@ -127,23 +109,12 @@ sentry_sdk.logger.info("Order processed {order_id}", order_id="order-123") sentry_sdk.logger.warning("Rate limit reached", attributes={"endpoint": "/api/orders"}) ``` - - - - ## Send Application Metrics - - - - Use `sentry_sdk.metrics` to send counters, gauges, and distributions from your app. Metrics are enabled by default after you initialize the SDK. See Set Up Metrics for all available metric types and configuration options. - - - ```python import sentry_sdk @@ -152,23 +123,12 @@ sentry_sdk.metrics.gauge("active_connections", 42) sentry_sdk.metrics.distribution("api_latency", 187, unit="millisecond") ``` - - - - ## Verify Your Setup Let's test your setup and confirm that data reaches your Sentry project. - - - - Add a view that raises an exception and route it in your Django application: - - - ```python from django.urls import path @@ -178,10 +138,6 @@ def trigger_error(request): urlpatterns = [path("sentry-debug/", trigger_error)] ``` - - - - ### View Captured Data in Sentry Now, head over to your project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear). diff --git a/docs/platforms/python/integrations/fastapi/index.mdx b/docs/platforms/python/integrations/fastapi/index.mdx index 75c955141815f..a7ba2be232508 100644 --- a/docs/platforms/python/integrations/fastapi/index.mdx +++ b/docs/platforms/python/integrations/fastapi/index.mdx @@ -38,10 +38,6 @@ If you have the `fastapi` package in your dependencies, the Sentry FastAPI integ - - - - Import and initialize the SDK in your app's entry point: The snippet also turns on: @@ -51,9 +47,6 @@ The snippet also turns on: Don't need a feature? Remove its options from the snippet. - - - ```python import sentry_sdk @@ -74,10 +67,6 @@ sentry_sdk.init( ) ``` - - - - To further customize your setup, review the [Options section](#options) below. ### Capturing Errors @@ -104,19 +93,12 @@ You can also manually capture performance data – see standard logging and Loguru integration guides. See Set Up Logs for all available logging methods and formatting options. - - - ```python import sentry_sdk @@ -124,23 +106,12 @@ sentry_sdk.logger.info("Order processed {order_id}", order_id="order-123") sentry_sdk.logger.warning("Rate limit reached", attributes={"endpoint": "/api/orders"}) ``` - - - - ## Send Application Metrics - - - - Use `sentry_sdk.metrics` to send counters, gauges, and distributions from your app. Metrics are enabled by default after you initialize the SDK. See Set Up Metrics for all available metric types and configuration options. - - - ```python import sentry_sdk @@ -149,33 +120,18 @@ sentry_sdk.metrics.gauge("active_connections", 42) sentry_sdk.metrics.distribution("api_latency", 187, unit="millisecond") ``` - - - - ## Verify Your Setup Let's test your setup and confirm that data reaches your Sentry project. - - - - Add this route to your FastAPI app, then request `/sentry-debug`: - - - ```python @app.get("/sentry-debug") async def trigger_error(): 1 / 0 ``` - - - - ### View Captured Data in Sentry Now, head over to your project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear). @@ -222,18 +178,11 @@ You can pass the following keyword arguments to `StarletteIntegration()` and `Fa How to name transactions that show up in Sentry tracing. The default is `"url"`. - - - - In the code example, the transaction name will be: - `"/catalog/product/{product_id}"` if you set `transaction_style="url"` - `"product_detail"` if you set `transaction_style="endpoint"` - - - ```python import sentry_sdk from sentry_sdk.integrations.starlette import StarletteIntegration @@ -258,10 +207,6 @@ In the code example, the transaction name will be: return {...} ``` - - - -
diff --git a/docs/platforms/python/integrations/flask/index.mdx b/docs/platforms/python/integrations/flask/index.mdx index 5c43b32a15f05..d3079cac0868a 100644 --- a/docs/platforms/python/integrations/flask/index.mdx +++ b/docs/platforms/python/integrations/flask/index.mdx @@ -38,10 +38,6 @@ The SDK hooks into Flask's signals, not anything on the app object. - - - - Import and initialize the SDK in your app's entry point: The snippet also turns on: @@ -51,9 +47,6 @@ The snippet also turns on: Don't need a feature? Remove its options from the snippet. - - - ```python import sentry_sdk @@ -74,10 +67,6 @@ sentry_sdk.init( ) ``` - - - - To further customize your setup, review the [Options section](#options) below. ### Capturing Errors @@ -93,19 +82,12 @@ You can also expect the following for your Flask app: ## Send Logs - - - - Use `sentry_sdk.logger` to send structured logs at different levels. You can include searchable attributes with each message. To capture records from Python's standard-library `logging` module or Loguru, configure `capture_sentry_logs=True` on the corresponding integration. See the standard logging and Loguru integration guides. See Set Up Logs for all available logging methods and formatting options. - - - ```python import sentry_sdk @@ -113,23 +95,12 @@ sentry_sdk.logger.info("Order processed {order_id}", order_id="order-123") sentry_sdk.logger.warning("Rate limit reached", attributes={"endpoint": "/api/orders"}) ``` - - - - ## Send Application Metrics - - - - Use `sentry_sdk.metrics` to send counters, gauges, and distributions from your app. Metrics are enabled by default after you initialize the SDK. See Set Up Metrics for all available metric types and configuration options. - - - ```python import sentry_sdk @@ -138,33 +109,18 @@ sentry_sdk.metrics.gauge("active_connections", 42) sentry_sdk.metrics.distribution("api_latency", 187, unit="millisecond") ``` - - - - ## Verify Your Setup Let's test your setup and confirm that data reaches your Sentry project. - - - - Add this route to your Flask app, then request `/sentry-debug`: - - - ```python @app.route("/sentry-debug") def trigger_error(): 1 / 0 ``` - - - - ### View Captured Data in Sentry Now, head over to your project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear). @@ -199,28 +155,17 @@ You can pass the following keyword arguments to `FlaskIntegration()`: How to name transactions that show up in Sentry tracing. The default is `"endpoint"`. - - - - In the code example, the transaction name will be: - `/myurl/` if you set `transaction_style="url"` - `myendpoint` if you set `transaction_style="endpoint"` - - - ```python @app.route("/myurl/") def myendpoint(): return "

Hello, World!

" ``` -
-
-
-
diff --git a/docs/platforms/python/integrations/starlette/index.mdx b/docs/platforms/python/integrations/starlette/index.mdx index 0e901973d6d79..a59df16d08cb5 100644 --- a/docs/platforms/python/integrations/starlette/index.mdx +++ b/docs/platforms/python/integrations/starlette/index.mdx @@ -37,10 +37,6 @@ If you have the `starlette` package in your dependencies, the Sentry Starlette i - - - - Import and initialize the SDK in your app's entry point: The snippet also turns on: @@ -50,9 +46,6 @@ The snippet also turns on: Don't need a feature? Remove its options from the snippet. - - - ```python import sentry_sdk @@ -73,10 +66,6 @@ sentry_sdk.init( ) ``` - - - - To further customize your setup, review the [Options section](#options) below. ### Capturing Errors @@ -92,19 +81,12 @@ To learn how to manually report issues, see Capturing ## Send Logs - - - - Use `sentry_sdk.logger` to send structured logs at different levels. You can include searchable attributes with each message. To capture records from Python's standard-library `logging` module or Loguru, configure `capture_sentry_logs=True` on the corresponding integration. See the standard logging and Loguru integration guides. See Set Up Logs for all available logging methods and formatting options. - - - ```python import sentry_sdk @@ -112,23 +94,12 @@ sentry_sdk.logger.info("Order processed {order_id}", order_id="order-123") sentry_sdk.logger.warning("Rate limit reached", attributes={"endpoint": "/api/orders"}) ``` - - - - ## Send Application Metrics - - - - Use `sentry_sdk.metrics` to send counters, gauges, and distributions from your app. Metrics are enabled by default after you initialize the SDK. See Set Up Metrics for all available metric types and configuration options. - - - ```python import sentry_sdk @@ -137,23 +108,12 @@ sentry_sdk.metrics.gauge("active_connections", 42) sentry_sdk.metrics.distribution("api_latency", 187, unit="millisecond") ``` - - - - ## Verify Your Setup Let's test your setup and confirm that data reaches your Sentry project. - - - - Add this route to your Starlette app, then request `/sentry-debug`: - - - ```python from starlette.applications import Starlette from starlette.routing import Route @@ -164,10 +124,6 @@ async def trigger_error(request): app = Starlette(routes=[Route("/sentry-debug", trigger_error)]) ``` - - - - ### View Captured Data in Sentry Now, head over to your project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear). @@ -203,18 +159,11 @@ You can pass the following keyword arguments to `StarletteIntegration()`: How to name transactions that show up in Sentry tracing. The default is `"url"`. - - - - In the code example, the transaction name will be: - `"/catalog/product/{product_id}"` if you set `transaction_style="url"`. - `"product_detail"` if you set `transaction_style="endpoint"` - - - ```python async def product_detail(request): return JSONResponse({...}) @@ -224,10 +173,6 @@ In the code example, the transaction name will be: ]) ``` - - - - From 0ed9aa917e8e84609fe3f1413dd149678ba03dbd Mon Sep 17 00:00:00 2001 From: Shannon Anahata Date: Mon, 26 Oct 2026 11:32:31 -0700 Subject: [PATCH 5/6] fix(docs): Align Python quick start with current SDK behavior - Replace deprecated send_default_pii with data_collection (matches master) - Add AsyncioIntegration to the async example; it isn't enabled by default - State sentry-sdk 2.70.0+ requirement and Python 3.6+ prerequisite - Verify step now sends a trace, log, and metric alongside the error - Clarify when profiles are collected and sent --- docs/platforms/python/index.mdx | 33 +++++++++++++++---- .../getting-started-prerequisites/python.mdx | 1 + 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/docs/platforms/python/index.mdx b/docs/platforms/python/index.mdx index a4f841bac01ba..871d81a8f54aa 100644 --- a/docs/platforms/python/index.mdx +++ b/docs/platforms/python/index.mdx @@ -26,6 +26,8 @@ This guide focuses on plain Python. If you're working with Django, FastAPI, Star +This guide requires `sentry-sdk` version 2.70.0 or later. If you already have the SDK installed, upgrade it with `pip install --upgrade sentry-sdk`. + ## Configure **Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). @@ -41,6 +43,7 @@ Import and initialize the SDK in your app's entry point: The snippet also turns on: +- Collection of user data, such as the user's IP address: via `data_collection` - Tracing: via `traces_sample_rate` - Profiling: via `profile_session_sample_rate` and `profile_lifecycle` @@ -51,8 +54,10 @@ import sentry_sdk sentry_sdk.init( dsn="___PUBLIC_DSN___", - # Send request headers and user IP address. - send_default_pii=True, + # Check https://docs.sentry.io/platforms/python/data-management/data-collected/ to configure what data is collected + data_collection={ + "user_info": True, + }, # Enables Tracing. # Set to 1.0 to capture 100% of spans for tracing. @@ -62,19 +67,22 @@ sentry_sdk.init( # Enables Profiling. # Set to 1.0 to profile 100% of sessions. profile_session_sample_rate=1.0, - # Profiles are collected while at least one span is active. + # Profiles are collected while a transaction is active. profile_lifecycle="trace", ) ``` -In async programs, we recommend to initialize the Sentry SDK inside an `async` function to ensure async code is instrumented properly. If possible, call `sentry_sdk.init()` at the beginning of the first `async` function you call: +In async programs, add the `AsyncioIntegration` to instrument your async code. This integration isn't enabled by default. Call `sentry_sdk.init()` at the beginning of the first `async` function you call: ```python import asyncio import sentry_sdk +from sentry_sdk.integrations.asyncio import AsyncioIntegration + async def main(): sentry_sdk.init( - ... # same as above + ..., # same options as above + integrations=[AsyncioIntegration()], ) asyncio.run(main()) @@ -129,12 +137,23 @@ sentry_sdk.metrics.distribution("api_latency", 187, unit="millisecond") Let's test your setup and confirm that data reaches your Sentry project. -Add an intentional error to your application to confirm that Sentry captures it: +Run this code after `sentry_sdk.init()` to send a test error, along with a trace, a log, and a metric: ```python -1 / 0 +import sentry_sdk + +with sentry_sdk.start_transaction(op="test", name="Verify Sentry setup"): + sentry_sdk.logger.info("Sentry verification log") + sentry_sdk.metrics.count("sentry.verification", 1) + 1 / 0 ``` + + +The SDK sends profiles after a transaction finishes, so a script that exits right away, like the one above, might not send a profile. Profiles appear for applications that keep running after their transactions complete. + + + ### View Captured Data in Sentry Now, head over to your project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear). diff --git a/platform-includes/getting-started-prerequisites/python.mdx b/platform-includes/getting-started-prerequisites/python.mdx index b22b687efb7bc..b32708902e4d4 100644 --- a/platform-includes/getting-started-prerequisites/python.mdx +++ b/platform-includes/getting-started-prerequisites/python.mdx @@ -4,3 +4,4 @@ You need: - A Sentry [account](https://sentry.io/signup/) and [project](/product/projects/) - Your application up and running +- Python `3.6` or above From 64bf080d2906b9b03ac23b0a1f7ca847318617eb Mon Sep 17 00:00:00 2001 From: Shannon Anahata Date: Mon, 26 Oct 2026 11:36:46 -0700 Subject: [PATCH 6/6] fix(docs): Align Python framework quick starts with current SDK behavior - Replace deprecated send_default_pii with data_collection in Flask, FastAPI, and Starlette init snippets (user_info), matching master - List data_collection in each guide's 'snippet also turns on' section - State sentry-sdk 2.70.0+ requirement under Install - Clarify that profiles are collected while a transaction is active --- docs/platforms/python/integrations/celery/index.mdx | 3 +++ docs/platforms/python/integrations/django/index.mdx | 3 +++ docs/platforms/python/integrations/fastapi/index.mdx | 11 +++++++++-- docs/platforms/python/integrations/flask/index.mdx | 11 +++++++++-- .../platforms/python/integrations/starlette/index.mdx | 11 +++++++++-- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/docs/platforms/python/integrations/celery/index.mdx b/docs/platforms/python/integrations/celery/index.mdx index d0267c99a8879..74f6d04882f84 100644 --- a/docs/platforms/python/integrations/celery/index.mdx +++ b/docs/platforms/python/integrations/celery/index.mdx @@ -24,6 +24,8 @@ You need: +This guide requires `sentry-sdk` version 2.70.0 or later. If you already have the SDK installed, upgrade it with `pip install --upgrade sentry-sdk`. + ## Configure **Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). @@ -37,6 +39,7 @@ Configuration should happen as **early as possible** in your application's lifec The init snippets also turn on: +- Collection of task arguments in error events: via `data_collection` - Tracing: via `traces_sample_rate` - Profiling: via `profile_session_sample_rate` and `profile_lifecycle` diff --git a/docs/platforms/python/integrations/django/index.mdx b/docs/platforms/python/integrations/django/index.mdx index 931ddf2d2a9ac..b848d8274af8e 100644 --- a/docs/platforms/python/integrations/django/index.mdx +++ b/docs/platforms/python/integrations/django/index.mdx @@ -26,6 +26,8 @@ You need: +This guide requires `sentry-sdk` version 2.70.0 or later. If you already have the SDK installed, upgrade it with `pip install --upgrade sentry-sdk`. + ## Configure **Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). @@ -41,6 +43,7 @@ To configure the Sentry SDK, initialize it in your `settings.py` file: The snippet also turns on: +- Collection of user data, such as the user's IP address: via `data_collection` - Tracing: via `traces_sample_rate` - Profiling: via `profile_session_sample_rate` and `profile_lifecycle` diff --git a/docs/platforms/python/integrations/fastapi/index.mdx b/docs/platforms/python/integrations/fastapi/index.mdx index 6e8f6033ef472..a8b591a8c6838 100644 --- a/docs/platforms/python/integrations/fastapi/index.mdx +++ b/docs/platforms/python/integrations/fastapi/index.mdx @@ -23,6 +23,8 @@ You need: +This guide requires `sentry-sdk` version 2.70.0 or later. If you already have the SDK installed, upgrade it with `pip install --upgrade sentry-sdk`. + ## Configure **Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). @@ -44,6 +46,7 @@ Import and initialize the SDK in your app's entry point: The snippet also turns on: +- Collection of user data, such as the user's IP address: via `data_collection` - Tracing: via `traces_sample_rate` - Profiling: via `profile_session_sample_rate` and `profile_lifecycle` @@ -54,7 +57,11 @@ import sentry_sdk sentry_sdk.init( dsn="___PUBLIC_DSN___", - send_default_pii=True, + + # Check https://docs.sentry.io/platforms/python/data-management/data-collected/ to configure what data is collected + data_collection={ + "user_info": True, + }, # Enables Tracing. # Set to 1.0 to capture 100% of spans for tracing. @@ -64,7 +71,7 @@ sentry_sdk.init( # Enables Profiling. # Set to 1.0 to profile 100% of sessions. profile_session_sample_rate=1.0, - # Profiles are collected while at least one span is active. + # Profiles are collected while a transaction is active. profile_lifecycle="trace", ) ``` diff --git a/docs/platforms/python/integrations/flask/index.mdx b/docs/platforms/python/integrations/flask/index.mdx index 4c36fc03d2922..cb6c15eb2d78c 100644 --- a/docs/platforms/python/integrations/flask/index.mdx +++ b/docs/platforms/python/integrations/flask/index.mdx @@ -24,6 +24,8 @@ You need: +This guide requires `sentry-sdk` version 2.70.0 or later. If you already have the SDK installed, upgrade it with `pip install --upgrade sentry-sdk`. + ## Configure **Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). @@ -46,6 +48,7 @@ Import and initialize the SDK in your app's entry point: The snippet also turns on: +- Collection of user data, such as the user's IP address: via `data_collection` - Tracing: via `traces_sample_rate` - Profiling: via `profile_session_sample_rate` and `profile_lifecycle` @@ -56,7 +59,11 @@ import sentry_sdk sentry_sdk.init( dsn="___PUBLIC_DSN___", - send_default_pii=True, + + # Check https://docs.sentry.io/platforms/python/data-management/data-collected/ to configure what data is collected + data_collection={ + "user_info": True, + }, # Enables Tracing. # Set to 1.0 to capture 100% of spans for tracing. @@ -66,7 +73,7 @@ sentry_sdk.init( # Enables Profiling. # Set to 1.0 to profile 100% of sessions. profile_session_sample_rate=1.0, - # Profiles are collected while at least one span is active. + # Profiles are collected while a transaction is active. profile_lifecycle="trace", ) ``` diff --git a/docs/platforms/python/integrations/starlette/index.mdx b/docs/platforms/python/integrations/starlette/index.mdx index 969641b6837d4..7e9607c586fb5 100644 --- a/docs/platforms/python/integrations/starlette/index.mdx +++ b/docs/platforms/python/integrations/starlette/index.mdx @@ -22,6 +22,8 @@ You need: +This guide requires `sentry-sdk` version 2.70.0 or later. If you already have the SDK installed, upgrade it with `pip install --upgrade sentry-sdk`. + ## Configure **Error Monitoring** starts working as soon as you call `sentry_sdk.init()`. **Logs** and **Application Metrics** need no extra configuration when using `sentry_sdk.logger` and `sentry_sdk.metrics`, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-). @@ -43,6 +45,7 @@ Import and initialize the SDK in your app's entry point: The snippet also turns on: +- Collection of user data, such as the user's IP address: via `data_collection` - Tracing: via `traces_sample_rate` - Profiling: via `profile_session_sample_rate` and `profile_lifecycle` @@ -53,7 +56,11 @@ import sentry_sdk sentry_sdk.init( dsn="___PUBLIC_DSN___", - send_default_pii=True, + + # Check https://docs.sentry.io/platforms/python/data-management/data-collected/ to configure what data is collected + data_collection={ + "user_info": True, + }, # Enables Tracing. # Set to 1.0 to capture 100% of spans for tracing. @@ -63,7 +70,7 @@ sentry_sdk.init( # Enables Profiling. # Set to 1.0 to profile 100% of sessions. profile_session_sample_rate=1.0, - # Profiles are collected while at least one span is active. + # Profiles are collected while a transaction is active. profile_lifecycle="trace", ) ```