Skip to content

Commit 1d5726d

Browse files
merge
2 parents 5b0485d + bb891ea commit 1d5726d

13 files changed

Lines changed: 24 additions & 1508 deletions

‎MIGRATION_GUIDE.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
2626
- In the AWS Lambda and GCP integrations, the message of the warning the SDK optionally emits if a function is about to time out has changed.
2727
- We changed the way we emit warnings. Deprecations will from now on be always emitted using `warnings.warn()`, while all other warnings will be emitted using `logger.warning()`.
2828
- `sentry_sdk.init()` can no longer be used as a context manager.
29+
- The `@trace` decorator doesn't accept a `template` parameter anymore.
2930

3031
### Logging
3132

@@ -113,6 +114,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
113114
- Dropped support for Litestar below 2.0.
114115
- Dropped support for PySpark below 3.0.
115116
- Dropped support for redis-py below 4.2.
117+
- Dropped support for Pydantic AI below 1.76.
116118
- Removed the RedisIntegration `max_data_size` option.
117119
- Removed the possibility to supply a specific client to the LaunchDarklyIntegration.
118120
- The `enable_tracing` option was removed. Use `traces_sample_rate=1.0` instead.
@@ -150,6 +152,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
150152
- The SDK won't set any tags on its own anymore.
151153
- The `update_current_span` API was removed.
152154
- `SanicIntegration` no longer accepts `unsampled_statuses`.
155+
- The `trace_ignore_status_codes` option was removed.
153156

154157

155158
## Deprecated

‎sentry_sdk/ai/monitoring.py‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from contextvars import ContextVar
21
from typing import TYPE_CHECKING
32

43
from sentry_sdk.ai.utils import _set_span_data_attribute
@@ -11,18 +10,6 @@
1110

1211
F = TypeVar("F", bound=Union[Callable[..., Any], Callable[..., Awaitable[Any]]])
1312

14-
_ai_pipeline_name: "ContextVar[Optional[str]]" = ContextVar(
15-
"ai_pipeline_name", default=None
16-
)
17-
18-
19-
def set_ai_pipeline_name(name: "Optional[str]") -> None:
20-
_ai_pipeline_name.set(name)
21-
22-
23-
def get_ai_pipeline_name() -> "Optional[str]":
24-
return _ai_pipeline_name.get()
25-
2613

2714
def record_token_usage(
2815
span: "Union[Span, StreamedSpan]",
@@ -33,11 +20,6 @@ def record_token_usage(
3320
output_tokens_reasoning: "Optional[int]" = None,
3421
total_tokens: "Optional[int]" = None,
3522
) -> None:
36-
# TODO: move pipeline name elsewhere
37-
ai_pipeline_name = get_ai_pipeline_name()
38-
if ai_pipeline_name:
39-
_set_span_data_attribute(span, SPANDATA.GEN_AI_PIPELINE_NAME, ai_pipeline_name)
40-
4123
if input_tokens is not None:
4224
_set_span_data_attribute(span, SPANDATA.GEN_AI_USAGE_INPUT_TOKENS, input_tokens)
4325

‎sentry_sdk/client.py‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,6 @@ def _get_options(*args: "Optional[str]", **kwargs: "Any") -> "Dict[str, Any]":
364364
env_to_bool(os.environ.get("SENTRY_KEEP_ALIVE"), strict=True) or False
365365
)
366366

367-
if rv["trace_ignore_status_codes"] and has_span_streaming_enabled(rv):
368-
logger.warning(
369-
"The `trace_ignore_status_codes` parameter is ignored in span streaming mode.",
370-
)
371-
372367
if rv["ignore_spans"] and not has_span_streaming_enabled(rv):
373368
logger.warning(
374369
"The `ignore_spans` parameter only works when `trace_lifecycle` is set to `stream`.",

‎sentry_sdk/consts.py‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class CompressionAlgo(Enum):
2929

3030
if TYPE_CHECKING:
3131
from typing import (
32-
AbstractSet,
3332
Any,
3433
Callable,
3534
Dict,
@@ -94,16 +93,6 @@ class CompressionAlgo(Enum):
9493
]
9594

9695

97-
class SPANTEMPLATE(str, Enum):
98-
DEFAULT = "default"
99-
AI_AGENT = "ai_agent"
100-
AI_TOOL = "ai_tool"
101-
AI_CHAT = "ai_chat"
102-
103-
def __str__(self) -> str:
104-
return self.value
105-
106-
10796
class SPANNAME:
10897
DB_COMMIT = "COMMIT"
10998
DB_ROLLBACK = "ROLLBACK"
@@ -1344,7 +1333,6 @@ def __init__(
13441333
add_full_stack: bool = DEFAULT_ADD_FULL_STACK,
13451334
max_stack_frames: "Optional[int]" = DEFAULT_MAX_STACK_FRAMES,
13461335
before_send_log: "Optional[Callable[[Log, Hint], Optional[Log]]]" = None,
1347-
trace_ignore_status_codes: "AbstractSet[int]" = frozenset(),
13481336
before_send_metric: "Optional[Callable[[Metric, Hint], Optional[Metric]]]" = None,
13491337
before_send_span: "Optional[Callable[[SpanJSON, Hint], Optional[SpanJSON]]]" = None,
13501338
org_id: "Optional[str]" = None,
@@ -1725,16 +1713,6 @@ def __init__(
17251713
function will be retained. If the function returns None, the log will
17261714
not be sent to Sentry.
17271715
1728-
:param trace_ignore_status_codes: An optional property that disables tracing for
1729-
HTTP requests with certain status codes.
1730-
1731-
Requests are not traced if the status code is contained in the provided set.
1732-
1733-
If `trace_ignore_status_codes` is not provided, requests with any status code
1734-
may be traced.
1735-
1736-
This option has no effect in span streaming mode (`trace_lifecycle="stream"`).
1737-
17381716
:param strict_trace_continuation: If set to `True`, the SDK will only continue a trace if the `org_id` of the incoming trace found in the
17391717
`baggage` header matches the `org_id` of the current Sentry client and only if BOTH are present.
17401718

‎sentry_sdk/tracing.py‎

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import TYPE_CHECKING, cast
55

66
import sentry_sdk
7-
from sentry_sdk.consts import SPANDATA, SPANSTATUS, SPANTEMPLATE
7+
from sentry_sdk.consts import SPANDATA, SPANSTATUS
88
from sentry_sdk.profiler.continuous_profiler import get_profiler_id
99
from sentry_sdk.utils import (
1010
capture_internal_exceptions,
@@ -915,32 +915,6 @@ def finish(
915915

916916
super().finish(scope, end_timestamp)
917917

918-
status_code = self._data.get(SPANDATA.HTTP_STATUS_CODE)
919-
if (
920-
status_code is not None
921-
and status_code in client.options["trace_ignore_status_codes"]
922-
):
923-
logger.debug(
924-
"[Tracing] Discarding {transaction_description} because the HTTP status code {status_code} is matched by trace_ignore_status_codes: {trace_ignore_status_codes}".format(
925-
transaction_description=self._get_log_representation(),
926-
status_code=self._data[SPANDATA.HTTP_STATUS_CODE],
927-
trace_ignore_status_codes=client.options[
928-
"trace_ignore_status_codes"
929-
],
930-
)
931-
)
932-
if client.transport:
933-
client.transport.record_lost_event(
934-
"event_processor", data_category="transaction"
935-
)
936-
937-
num_spans = len(self._span_recorder.spans) + 1
938-
client.transport.record_lost_event(
939-
"event_processor", data_category="span", quantity=num_spans
940-
)
941-
942-
self.sampled = False
943-
944918
if not self.sampled:
945919
# At this point a `sampled = None` should have already been resolved
946920
# to a concrete decision.
@@ -1248,7 +1222,6 @@ def trace(
12481222
op: "Optional[str]" = None,
12491223
name: "Optional[str]" = None,
12501224
attributes: "Optional[dict[str, Any]]" = None,
1251-
template: "SPANTEMPLATE" = SPANTEMPLATE.DEFAULT,
12521225
) -> "Callable[[Callable[P, R]], Callable[P, R]]":
12531226
# Handles: @trace() and @trace(op="custom")
12541227
pass
@@ -1265,7 +1238,6 @@ def trace(
12651238
op: "Optional[str]" = None,
12661239
name: "Optional[str]" = None,
12671240
attributes: "Optional[dict[str, Any]]" = None,
1268-
template: "SPANTEMPLATE" = SPANTEMPLATE.DEFAULT,
12691241
) -> "Union[Callable[P, R], Callable[[Callable[P, R]], Callable[P, R]]]":
12701242
"""
12711243
Decorator to start a child span around a function call.
@@ -1295,21 +1267,14 @@ def trace(
12951267
attributes provide additional context about the span's execution.
12961268
:type attributes: dict[str, Any] or None
12971269
1298-
:param template: The type of span to create. This determines what kind of
1299-
span instrumentation and data collection will be applied. Use predefined
1300-
constants from :py:class:`sentry_sdk.consts.SPANTEMPLATE`.
1301-
The default is `SPANTEMPLATE.DEFAULT` which is the right choice for most
1302-
use cases.
1303-
:type template: :py:class:`sentry_sdk.consts.SPANTEMPLATE`
1304-
13051270
:returns: When used as ``@trace``, returns the decorated function. When used as
13061271
``@trace(...)`` with parameters, returns a decorator function.
13071272
:rtype: Callable or decorator function
13081273
13091274
Example::
13101275
13111276
import sentry_sdk
1312-
from sentry_sdk.consts import OP, SPANTEMPLATE
1277+
from sentry_sdk.consts import OP
13131278
13141279
# Simple usage with default values
13151280
@sentry_sdk.trace
@@ -1326,20 +1291,13 @@ def process_data():
13261291
def make_db_query(sql):
13271292
# Function implementation
13281293
pass
1329-
1330-
# With a custom template
1331-
@sentry_sdk.trace(template=SPANTEMPLATE.AI_TOOL)
1332-
def calculate_interest_rate(amount, rate, years):
1333-
# Function implementation
1334-
pass
13351294
"""
13361295
from sentry_sdk.tracing_utils import create_span_decorator
13371296

13381297
decorator = create_span_decorator(
13391298
op=op,
13401299
name=name,
13411300
attributes=attributes,
1342-
template=template,
13431301
)
13441302

13451303
if func:

0 commit comments

Comments
 (0)