Sentry Python
npx @buildinternet/releases get sentry-pythonnpx @buildinternet/releases get sentry-pythonNew 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 #7162gen_ai.tool.definitions for the Responses API by @alexander-alderman-webb in #6951gen_ai.tool.definitions for the Chat Completions API by @alexander-alderman-webb in #6950gen_ai.request.reasoning.level to OpenAI spans by @pabloDeputter in #6892before_send_span to top-level option by @sentrivana in #6885set_conversation_id API work by @sentrivana in #6866set_attributes API by @sentrivana in #6897gen_ai.tool.definitions attribute by @alexander-alderman-webb in #6956gen_ai.output.messages including ThinkingPart by @alexander-alderman-webb in #7037run_single_turn_streamed reference by @alexander-alderman-webb in #7032capture_items with args by @sentrivana in #6867sentry-trace should take precedence over baggage by @sentrivana in #6863url.full span attribute by @sentrivana in #6861fastmcp>=4 by @alexander-alderman-webb in #6923RootModel instances by @alexander-alderman-webb in #6909try...except with skipif by @alexander-alderman-webb in #6922mcp.tool.result.is_error by @alexander-alderman-webb in #6915mcp_types package by @alexander-alderman-webb in #6763_set_span_output_data() by @alexander-alderman-webb in #6762_get_span_config() by @alexander-alderman-webb in #6761_prepare_handler_data() by @alexander-alderman-webb in #6758gen_ai.response.model on Invoke Agent spans by @alexander-alderman-webb in #7028gen_ai.response.tool_calls by @alexander-alderman-webb in #6973gen_ai.request.available_tools on Invoke Agent spans by @alexander-alderman-webb in #6955gen_ai.request.available_tools on Execute Tool spans by @alexander-alderman-webb in #6954iscoroutinefunction shim in patch_views() by @alexander-alderman-webb in #7024asyncio.iscoroutinefunction by @alexander-alderman-webb in #7023on_agent_finish() hook by @alexander-alderman-webb in #7059FunctionModel for testing output data transformations by @alexander-alderman-webb in #7036MAX_DATABAG_BREADTH by @Malkiz223 in #6783litellm<=1.96 for generating test suites by @alexander-alderman-webb in #7147test-lambda-locally by @alexander-alderman-webb in #7069pydantic-ai-slim to uv typing group by @alexander-alderman-webb in #7025langchain-base to uv typing group by @alexander-alderman-webb in #7016ai_track() by @alexander-alderman-webb in #7005functions_to_trace tests by @alexander-alderman-webb in #6933mcp<2 for fastmcp<0.3 by @alexander-alderman-webb in #6925huey>=3.3.0 by @alexander-alderman-webb in #6913httpx dependency to mcp and fastmcp tests by @alexander-alderman-webb in #6905nullcontext to sentry_sdk.utils by @sentrivana in #6805messaging.destination.name on consumer spans by @alexander-alderman-webb in #6779messaging.destination.name on producer spans by @alexander-alderman-webb in #6778messaging.destination.name on consumer spans by @alexander-alderman-webb in #6767messaging.destination.name on consumer spans by @alexander-alderman-webb in #6776messaging.destination.name on consumer spans by @alexander-alderman-webb in #6774ValueError in async middleware process_* hooks by @r0ro in #6698cache_write_tokens field by @alexander-alderman-webb in #6804pydantic to the typing group by @alexander-alderman-webb in #6730python_multipart to the typing group by @alexander-alderman-webb in #6729changelog-preview by @alexander-alderman-webb in #6723requirements-testing.txt with a uv dependency group by @alexander-alderman-webb in #6693The SDK now extracts all gen_ai spans out of a transaction and sends them as v2 envelope items by default. This prevents gen_ai spans from being dropped when the transaction payload exceeds size limits. Because they are no longer constrained by transaction size limits, AI message data is also no longer truncated. To keep the previous behavior, set stream_gen_ai_spans=False.
Self-hosted Sentry users should opt out with stream_gen_ai_spans=False, since streamed gen_ai spans may not be ingested by their Sentry instance.