Sentry Python
npx @buildinternet/releases get sentry-pythonnpx @buildinternet/releases get sentry-pythonSupport for Amazon Bedrock's Converse and ConverseStream APIs
The Boto3 integration is enabled automatically when boto3 is installed. To configure it explicitly:
import sentry_sdk
from sentry_sdk.integrations.boto3 import Boto3Integration
sentry_sdk.init(
dsn="...",
traces_sample_rate=1.0,
integrations=[
Boto3Integration(),
]
)
gen_ai.response.time_to_first_chunk by @alexander-alderman-webb in #8255gen_ai.response.finish_reasons for streamed responses by @alexander-alderman-webb in #8252gen_ai.output.messages for streamed responses by @alexander-alderman-webb in #8251gen_ai.response.finish_reasons for non-streaming responses by @alexander-alderman-webb in #8250gen_ai.output.messages for non-streaming responses by @alexander-alderman-webb in #8249gen_ai.input.messages attribute by @alexander-alderman-webb in #8242gen_ai.system_instructions attribute by @alexander-alderman-webb in #8239gen_ai.tool.definitions attribute by @alexander-alderman-webb in #8233inferenceConfig parameters by @alexander-alderman-webb in #8232gen_ai.request.model attribute by @alexander-alderman-webb in #8231--only and --skip by @sentrivana in #8240sentry_apply_entry by @sentry-junior in #8253_iterator property by @alexander-alderman-webb in #8163baggage header alone if it has existin… by @pabloDeputter in #8116server.address by @alexander-alderman-webb in #8171get_file_hash() and get_last_updated() helpers by @sentry-junior in #8173sphinx and remove packaging upper bound by @alexander-alderman-webb in #8183AGENTS.md by @sentrivana in #8077user_agent.original for inbound filters by @sentrivana in #7794sentry.is_localhost for inbound filters by @sentrivana in #7781ServiceExtension class by @pabloDeputter in #7536user_agent.original attr for inbound filters by @sentrivana in #7793sentry.is_localhost for inbound filters by @sentrivana in #7780sentry.is_localhost for inbound filters by @sentrivana in #7785user_agent.original attr for inbound filters by @sentrivana in #7795sentry.is_localhost for inbound filters by @sentrivana in #7783sentry.is_localhost for inbound filters by @sentrivana in #7787StreamingBody span correctly by @pabloDeputter in #7540None from capture_checkin when nothing is sent by @HardMax71 in #7868model_dump() instead of deprecated dict() by @intertermux-code in #7862anyio dependency by @alexander-alderman-webb in #7724starlette>=1.7 by @alexander-alderman-webb in #7789httpx2-pytest for huggingface_hub>=2 by @alexander-alderman-webb in #7790_calculate_*_token_usage() by @alexander-alderman-webb in #7875ai.monitoring.record_token_usage() by @alexander-alderman-webb in #7918send_default_pii by @sentrivana in #7694New integration: TypeSafe (#4733) by @alexander-alderman-webb
Add the TypeSafe integration to your sentry_sdk.init call:
import sentry_sdk
from sentry_sdk.integrations.typesafe import TypeSafeIntegration
sentry_sdk.init(
dsn="...",
traces_sample_rate=1.0,
integrations=[
TypeSafeIntegration(),
]
)
gen_ai.output.messages by @alexander-alderman-webb in #7720gen_ai.input.messages by @alexander-alderman-webb in #7718gen_ai.response.model by @alexander-alderman-webb in #7717system_one() patches by @alexander-alderman-webb in #7716data_collection in changelog by @sentrivana in #7565.gitignore to lambda handlers by @pabloDeputter in #7638LITELLM_LOCAL_MODEL_COST_MAP=true by @alexander-alderman-webb in #7630OTLPSpanExporter._headers removal by @alexander-alderman-webb in #7722sentry_init fixture by @sentrivana in #7577New integration: Mistral AI (#4733) by @alexander-alderman-webb
Add the Mistral integration to your sentry_sdk.init call:
import sentry_sdk
from sentry_sdk.integrations.mistral import MistralIntegration
sentry_sdk.init(
dsn="...",
traces_sample_rate=1.0,
integrations=[
MistralIntegration(),
]
)
New option: A fine-grained way to configure what data should be sent from the SDK.
Offers much more flexibility than send_default_pii, allowing you to specify what
data should be collected. If data_collection is defined, it takes precedence over
send_default_pii.
See https://docs.sentry.io/platforms/python/configuration/options/#data_collection for the available configuration options.
import sentry_sdk
sentry_sdk.init(
data_collection={
"user_info": False,
"gen_ai": {"inputs": False, "outputs": False},
"graphql": {"document": False, "variables": False},
"database_query_data": False,
"queues": False,
"http_bodies": [],
"cookies": {
"mode": "denylist",
"terms": ["forwarded", "-ip", "remote-", "via", "-user"],
},
"http_headers": {
"request": {
"mode": "denylist",
"terms": ["forwarded", "-ip", "remote-", "via", "-user"],
},
},
"url_query_params": {
"mode": "denylist",
"terms": ["forwarded", "-ip", "remote-", "via", "-user"],
},
}
)
gen_ai.output.messages by @alexander-alderman-webb in #7549gen_ai.input.messages by @alexander-alderman-webb in #7548gen_ai.system_instructions by @alexander-alderman-webb in #7547Chat.complete and Chat.complete_async patches by @alexander-alderman-webb in #7528data_collection from _experiments o top-level by @ericapisani in #7560getsentry/testing-ai-sdk-integrations by @alexander-alderman-webb in #7526db.result in breadcrumb with sensitive data opt-in by @alexander-alderman-webb in #7432None candidates by @alexander-alderman-webb in #7519functions_to_trace work when streaming spans by @sentrivana in #7430disabled_integrations type by @sentrivana in #7506ApproxDict by @alexander-alderman-webb in #7434_set_model_data() tests by @alexander-alderman-webb in #7453_set_agent_data() tests by @alexander-alderman-webb in #7450maxWireVersion by @alexander-alderman-webb in #7473http.route attribute by @alexander-alderman-webb in #7428stream_gen_ai_spans and the streaming trace lifecycle by @alexander-alderman-webb in #7405http.route attribute by @alexander-alderman-webb in #7341http.route attribute by @alexander-alderman-webb in #7343http.route attribute by @alexander-alderman-webb in #7340http.route attribute by @alexander-alderman-webb in #7322http.route attribute by @alexander-alderman-webb in #7344http.route attribute by @alexander-alderman-webb in #7347http.route attribute by @alexander-alderman-webb in #7348http.route attribute by @alexander-alderman-webb in #7338None arguments in tool and prompt handlers by @alexander-alderman-webb in #7387input_text parts for the Responses API by @alexander-alderman-webb in #7333Response.output is a list before iterating by @alexander-alderman-webb in #7238url transaction source for host routing by @mjq in #7266isinstance to determine tool type by @alexander-alderman-webb in #7412openai version when incompatible by @alexander-alderman-webb in #7236hooks.on.model_request by @alexander-alderman-webb in #7327StreamedSpan in type annotations by @alexander-alderman-webb in #7373_extract_handler_data_from_args() by @alexander-alderman-webb in #7386openai-agents to uv typing group by @alexander-alderman-webb in #7415aiohttp to uv typing group by @alexander-alderman-webb in #7395httpx test suite from httpx2 by @ZaafirRizwan in #7398test_langchain_embeddings_error_handling() by @alexander-alderman-webb in #7389tiktoken to uv typing group by @alexander-alderman-webb in #7394openai to uv typing group by @alexander-alderman-webb in #7334anthropic to uv typing group by @alexander-alderman-webb in #7324google-genai to uv typing group by @alexander-alderman-webb in #7323getsentry/codecov-action by @alexander-alderman-webb in #7241httpx dependency to tests relying on get_model_response() by @alexander-alderman-webb in #7235.get by @ericapisani in #7239enable_logs(logs) Don't stop sending auto-collected logs when enable_logs=True by @sentrivana in #7237
If you have enable_logs set to True, our logging integrations for the standard library logging module as well as Loguru will auto-collect logs and send them to Sentry as Sentry logs by default, preserving old behavior. Turning automatic collection off for a specific integration can still be achieved using the capture_sentry_logs integration option.
import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_sdk.integrations.loguru import LoguruIntegration
sentry_sdk.init(
enable_logs=True,
integrations=[
LoggingIntegration(capture_sentry_logs=True),
LoguruIntegration(capture_sentry_logs=False),
],
)
Please note that the enable_logs option is deprecated and will be removed in the next major release. The sentry_sdk.logger.X API now works regardless of it, and auto-collection can be opted into via the capture_sentry_logs integration-level options, which are False by default, unless you have enable_logs=True. We've added this compatibility layer to make the transition to a enable_logs-free world easier.
failed_request_status_codes by @mgaligniana in #7140gen_ai.response.tool_calls on outputs, not inputs by @ericapisani in #7207gen_ai.response.tool_calls on outputs, not inputs by @ericapisani in #7210gen_ai.tool.definitions attribute when data collection is enabled by @ericapisani in #7204gen_ai.response.tool_calls on outputs, not inputs by @ericapisani in #7208gen_ai.response.tool_calls on outputs, not inputs by @ericapisani in #7205gen_ai.response.tool_calls on outputs, not inputs by @ericapisani in #7209We're making enable_logs and enable_metrics no-op with this release (#7177), and they'll be dropped in the next major.
Previously, enable_logs also controlled automatic logs collection from the logging and Loguru integrations. These integrations now get an integration-level capture_sentry_logs boolean option to allow for more control over the auto-collection. These options are False by default, i.e., nothing is auto-collected without your explicit opt-in.
If you had enable_logs set to True:
sentry_sdk.logger.X API, no action necessary, the API will just work.LoggingIntegration or LoguruIntegration, the auto-collection will be turned off in this release. You can switch auto-collection on explicitly with:import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_sdk.integrations.loguru import LoguruIntegration
sentry_sdk.init(
integrations=[
LoggingIntegration(capture_sentry_logs=True),
LoguruIntegration(capture_sentry_logs=True),
],
)
If you had enable_logs set to False:
sentry_sdk.logger.X API, you'll need to remove the calls entirely or define a before_send_log callback to filter out unwanted logs.If you has enable_metrics set to False:
before_send_metric or remove the calls to the API.We recognize this is a disruptive change for some folks and want to make it clear this is a one-off. We're removing the options because they were an unnecessary hurdle that one had to jump through to be able to use logs and metrics, and it was confusing why the logging API would not just work on its own. On the other hand, we wanted to give you more fine-grained control over automatic collection.
NoOpStreamedSpan by @alexander-alderman-webb in #7163NoOpStreamedSpan in set_transaction_name() by @alexander-alderman-webb in #7164NoOpStreamedSpan by @alexander-alderman-webb in #7162