A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.sentry.io/platforms/python/integrations/fastapi/ below:

FastAPI | Sentry for Python

The FastAPI integration adds support for the FastAPI Framework .

Install

Install sentry-sdk from PyPI with the fastapi extra:

Copied

pip install "sentry-sdk[fastapi]"
Configure

If you have the fastapi package in your dependencies, the FastAPI integration will be enabled automatically when you initialize the Sentry SDK.

Error Monitoring Logs Tracing Profiling

Copied

import sentry_sdk

sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    
    
    send_default_pii=True,
    
    
    
    traces_sample_rate=1.0,
    
    
    
    
    profile_session_sample_rate=1.0,
    
    
    profile_lifecycle="trace",
    
    

    
    _experiments={
        "enable_logs": True,
    },
    
)
Verify

Copied

from fastapi import FastAPI

sentry_sdk.init(...)  

app = FastAPI()

@app.get("/sentry-debug")
async def trigger_error():
    division_by_zero = 1 / 0

When you point your browser to http://localhost:8000/sentry-debug a transaction will be created in the Performance section of sentry.io . Additionally, an error event will be sent to sentry.io and will be connected to the transaction.

It takes a couple of moments for the data to appear in sentry.io .

Behaviour Issue Reporting

The following information about your FastAPI project will be available to you on Sentry.io:

Monitor Performance

The following parts of your FastAPI project are monitored:

The parameter traces_sample_rate needs to be set when initializing the Sentry SDK for performance measurements to be recorded.

Options

By adding FastApiIntegration to your sentry_sdk.init() call explicitly, you can set options for FastApiIntegration to change its behavior. Because FastAPI is based on the Starlette framework, both integrations, StarletteIntegration and FastApiIntegration, must be instantiated.

Copied

from sentry_sdk.integrations.starlette import StarletteIntegration
from sentry_sdk.integrations.fastapi import FastApiIntegration

sentry_sdk.init(
    
    integrations=[
        StarletteIntegration(
            transaction_style="endpoint",
            failed_request_status_codes={403, *range(500, 599)},
            http_methods_to_capture=("GET",),
        ),
        FastApiIntegration(
            transaction_style="endpoint",
            failed_request_status_codes={403, *range(500, 599)},
            http_methods_to_capture=("GET",),
        ),
    ]
)

You can pass the following keyword arguments to StarletteIntegration() and FastApiIntegration():

Supported Versions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4