Skip to content

Commit c44e671

Browse files
committed
Merge branch 'potel-base' into srothh/complete-async-transport
2 parents 9f226cf + 01cc131 commit c44e671

File tree

31 files changed

+1458
-384
lines changed

31 files changed

+1458
-384
lines changed

CHANGELOG.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,48 @@ for your feedback. How was the migration? Is everything working as expected? Is
2020
[on GitHub](https://github.com/getsentry/sentry-python/discussions/3936) or
2121
[on Discord](https://discord.com/invite/Ww9hbqr).
2222

23+
## 2.34.1
24+
25+
### Various fixes & improvements
26+
27+
- Fix: Make sure Span data in AI instrumentations is always a primitive data type (#4643) by @antonpirker
28+
- Fix: Typo in CHANGELOG.md (#4640) by @jgillard
29+
30+
## 2.34.0
31+
32+
### Various fixes & improvements
33+
34+
- Considerably raise `DEFAULT_MAX_VALUE_LENGTH` (#4632) by @sentrivana
35+
36+
We have increased the string trimming limit considerably, allowing you to see more data
37+
without it being truncated. Note that this might, in rare cases, result in issue regrouping,
38+
for example if you're capturing message events with very long messages (longer than the
39+
default 1024 characters/bytes).
40+
41+
If you want to adjust the limit, you can set a
42+
[`max_value_length`](https://docs.sentry.io/platforms/python/configuration/options/#max_value_length)
43+
in your `sentry_sdk.init()`.
44+
45+
- `OpenAI` integration update (#4612) by @antonpirker
46+
47+
The `OpenAIIntegration` now supports [OpenAI Responses API](https://platform.openai.com/docs/api-reference/responses).
48+
49+
The data captured will also show up in the new [AI Agents Dashboard](https://docs.sentry.io/product/insights/agents/dashboard/).
50+
51+
This works out of the box, nothing to do on your side.
52+
53+
- Expose `set_transaction_name` (#4634) by @sl0thentr0py
54+
- Fix(Celery): Latency should be in milliseconds, not seconds (#4637) by @sentrivana
55+
- Fix(Django): Treat `django.template.context.BasicContext` as sequence in serializer (#4621) by @sl0thentr0py
56+
- Fix(Huggingface): Fix `huggingface_hub` CI tests. (#4619) by @antonpirker
57+
- Fix: Ignore deliberate thread exception warnings (#4611) by @sl0thentr0py
58+
- Fix: Socket tests to not use example.com (#4627) by @sl0thentr0py
59+
- Fix: Threading run patch (#4610) by @sl0thentr0py
60+
- Tests: Simplify celery double patching test (#4626) by @sl0thentr0py
61+
- Tests: Remove remote example.com calls (#4622) by @sl0thentr0py
62+
- Tests: tox.ini update (#4635) by @sentrivana
63+
- Tests: Update tox (#4609) by @sentrivana
64+
2365
## 2.33.2
2466

2567
### Various fixes & improvements

MIGRATION_GUIDE.md

Lines changed: 87 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,41 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
1010

1111
### Changed
1212

13+
#### General
14+
1315
- The SDK now supports Python 3.7 and higher.
14-
- The default of `traces_sample_rate` changed to `0`. Meaning: Incoming traces will be continued by default. For example, if your frontend sends a `sentry-trace/baggage` headers pair, your SDK will create Spans and send them to Sentry. (The default used to be `None` meaning by default no Spans where created, no matter what headers the frontend sent to your project.) See also: https://docs.sentry.io/platforms/python/configuration/options/#traces_sample_rate
1516
- Tag values on event dictionaries, which are passed to `before_send` and `before_send_transaction`, now are always `str` values. Previously, despite tag values being typed as `str`, they often had different values. Therefore, if you have configured any `before_send` and `before_send_transaction` functions which perform some logic based on tag values, you need to check and if needed update those functions to correctly handle `str` values.
17+
18+
#### Error Capturing
19+
20+
- We updated how we handle `ExceptionGroup`s. You will now get more data if `ExceptionGroup`s are appearing in chained exceptions. It could happen that after updating the SDK the grouping of issues change because of this. So eventually you will see the same exception in two Sentry issues (one from before the update, one from after the update).
21+
22+
#### Tracing
23+
24+
- The default of `traces_sample_rate` changed to `0`. Meaning: Incoming traces will be continued by default. For example, if your frontend sends a `sentry-trace/baggage` headers pair, your SDK will create Spans and send them to Sentry. (The default used to be `None` meaning by default no Spans where created, no matter what headers the frontend sent to your project.) See also: https://docs.sentry.io/platforms/python/configuration/options/#traces_sample_rate
1625
- `sentry_sdk.start_span` now only takes keyword arguments.
1726
- `sentry_sdk.start_transaction`/`sentry_sdk.start_span` no longer takes the following arguments: `span`, `parent_sampled`, `trace_id`, `span_id` or `parent_span_id`.
18-
- You can no longer change the sampled status of a span with `span.sampled = False` after starting it.
27+
- `sentry_sdk.continue_trace` no longer returns a `Transaction` and is now a context manager.
28+
- You can no longer change the sampled status of a span with `span.sampled = False` after starting it. The sampling decision needs to be either be made in the `traces_sampler`, or you need to pass an explicit `sampled` parameter to `start_span`.
1929
- The `Span()` constructor does not accept a `hub` parameter anymore.
20-
- The `sentry_sdk.Scope()` constructor no longer accepts a `client` parameter.
2130
- `Span.finish()` does not accept a `hub` parameter anymore.
22-
- `Span.finish()` no longer returns the `event_id` if the event is sent to sentry.
31+
- `Span.finish()` no longer returns the `event_id` if the event is sent to Sentry.
32+
- The `sampling_context` argument of `traces_sampler` now additionally contains all span attributes known at span start.
33+
- The `SentrySpanProcessor` and `SentryPropagator` are exported from `sentry_sdk.opentelemetry` instead of `sentry_sdk.integrations.opentelemetry`.
34+
35+
#### Profiling
36+
37+
- The `sampling_context` argument of `profiles_sampler` now additionally contains all span attributes known at span start.
2338
- The `Profile()` constructor does not accept a `hub` parameter anymore.
2439
- A `Profile` object does not have a `.hub` property anymore.
2540
- `MAX_PROFILE_DURATION_NS`, `PROFILE_MINIMUM_SAMPLES`, `Profile`, `Scheduler`, `ThreadScheduler`, `GeventScheduler`, `has_profiling_enabled`, `setup_profiler`, `teardown_profiler` are no longer accessible from `sentry_sdk.profiler`. They're still accessible from `sentry_sdk.profiler.transaction_profiler`.
2641
- `DEFAULT_SAMPLING_FREQUENCY`, `MAX_STACK_DEPTH`, `get_frame_name`, `extract_frame`, `extract_stack`, `frame_id` are no longer accessible from `sentry_sdk.profiler`. They're still accessible from `sentry_sdk.profiler.utils`.
27-
- `sentry_sdk.continue_trace` no longer returns a `Transaction` and is now a context manager.
28-
- Redis integration: In Redis pipeline spans there is no `span["data"]["redis.commands"]` that contains a dict `{"count": 3, "first_ten": ["cmd1", "cmd2", ...]}` but instead `span["data"]["redis.commands.count"]` (containing `3`) and `span["data"]["redis.commands.first_ten"]` (containing `["cmd1", "cmd2", ...]`).
29-
- clickhouse-driver integration: The query is now available under the `db.query.text` span attribute (only if `send_default_pii` is `True`).
30-
- `sentry_sdk.init` now returns `None` instead of a context manager.
31-
- The `sampling_context` argument of `traces_sampler` and `profiles_sampler` now additionally contains all span attributes known at span start.
32-
- We updated how we handle `ExceptionGroup`s. You will now get more data if ExceptionGroups are appearing in chained exceptions. It could happen that after updating the SDK the grouping of issues change because of this. So eventually you will see the same exception in two Sentry issues (one from before the update, one from after the update)
33-
- The integration for Python `logging` module does not send Sentry issues by default anymore when calling `logging.error()`, `logging.critical()` or `logging.exception()`. If you want to preserve the old behavior use `sentry_sdk.init(integrations=[LoggingIntegration(event_level="ERROR")])`.
34-
- The `SentrySpanProcessor` and `SentryPropagator` are exported from `sentry_sdk.opentelemetry` instead of `sentry_sdk.integrations.opentelemetry`.
42+
43+
44+
#### Integrations
45+
- Redis: In Redis pipeline spans there is no `span["data"]["redis.commands"]` that contains a dict `{"count": 3, "first_ten": ["cmd1", "cmd2", ...]}` but instead `span["data"]["redis.commands.count"]` (containing `3`) and `span["data"]["redis.commands.first_ten"]` (containing `["cmd1", "cmd2", ...]`).
46+
- clickhouse-driver: The query is now available under the `db.query.text` span attribute (only if `send_default_pii` is `True`).
47+
- Logging: By default, the SDK won't capture Sentry issues anymore when calling `logging.error()`, `logging.critical()` or `logging.exception()`. If you want to preserve the old behavior use `sentry_sdk.init(integrations=[LoggingIntegration(event_level="ERROR")])`.
3548
- The integration-specific content of the `sampling_context` argument of `traces_sampler` and `profiles_sampler` now looks different.
3649

3750
- The Celery integration doesn't add the `celery_job` dictionary anymore. Instead, the individual keys are now available as:
@@ -136,54 +149,88 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
136149
| `gcp_event.query_string` | `url.query` |
137150
| `gcp_event.headers` | `http.request.header.{header}` |
138151

152+
#### Internals
153+
154+
- The `sentry_sdk.Scope()` constructor no longer accepts a `client` parameter.
155+
- `sentry_sdk.init` now returns `None` instead of a context manager.
156+
139157
### Removed
140158

159+
#### General
160+
141161
- Dropped support for Python 3.6.
162+
- `set_measurement` has been removed.
163+
- Setting `Scope.user` directly is no longer supported. Use `Scope.set_user()` instead.
164+
165+
#### Tracing
166+
142167
- The `enable_tracing` `init` option has been removed. Configure `traces_sample_rate` directly.
143168
- The `propagate_traces` `init` option has been removed. Use `trace_propagation_targets` instead.
144169
- The `custom_sampling_context` parameter of `start_transaction` has been removed. Use `attributes` instead to set key-value pairs of data that should be accessible in the traces sampler. Note that span attributes need to conform to the [OpenTelemetry specification](https://opentelemetry.io/docs/concepts/signals/traces/#attributes), meaning only certain types can be set as values.
145-
- `set_measurement` has been removed.
146-
- The PyMongo integration no longer sets tags. The data is still accessible via span attributes.
147-
- The PyMongo integration doesn't set `operation_ids` anymore. The individual IDs (`operation_id`, `request_id`, `session_id`) are now accessible as separate span attributes.
148-
- `sentry_sdk.metrics` and associated metrics APIs have been removed as Sentry no longer accepts metrics data in this form. See https://sentry.zendesk.com/hc/en-us/articles/26369339769883-Upcoming-API-Changes-to-Metrics
149-
- The experimental options `enable_metrics`, `before_emit_metric` and `metric_code_locations` have been removed.
150170
- When setting span status, the HTTP status code is no longer automatically added as a tag.
151-
- Class `Hub` has been removed.
152-
- Class `_ScopeManager` has been removed.
153-
- The context manager `auto_session_tracking()` has been removed. Use `track_session()` instead.
154-
- The context manager `auto_session_tracking_scope()` has been removed. Use `track_session()` instead.
155-
- Utility function `is_auto_session_tracking_enabled()` has been removed. There is no public replacement. There is a private `_is_auto_session_tracking_enabled()` (if you absolutely need this function) It accepts a `scope` parameter instead of the previously used `hub` parameter.
156-
- Utility function `is_auto_session_tracking_enabled_scope()` has been removed. There is no public replacement. There is a private `_is_auto_session_tracking_enabled()` (if you absolutely need this function).
157-
- Setting `scope.level` has been removed. Use `scope.set_level` instead.
158-
- `span.containing_transaction` has been removed. Use `span.root_span` instead.
159-
- `continue_from_headers`, `continue_from_environ` and `from_traceparent` have been removed, please use top-level API `sentry_sdk.continue_trace` instead.
160-
- `PropagationContext` constructor no longer takes a `dynamic_sampling_context` but takes a `baggage` object instead.
161-
- `ThreadingIntegration` no longer takes the `propagate_hub` argument.
162-
- `Baggage.populate_from_transaction` has been removed.
163-
- `debug.configure_debug_hub` was removed.
164-
- `profiles_sample_rate` and `profiler_mode` were removed from options available via `_experiments`. Use the top-level `profiles_sample_rate` and `profiler_mode` options instead.
165-
- `Transport.capture_event` has been removed. Use `Transport.capture_envelope` instead.
166-
- Function transports are no longer supported. Subclass the `Transport` instead.
167-
- `start_transaction` (`start_span`) no longer takes the following arguments:
171+
- `start_transaction` is deprecated and no longer takes the following arguments:
168172
- `trace_id`, `baggage`: use `continue_trace` for propagation from headers or environment variables
169173
- `same_process_as_parent`
170174
- `span_id`
171175
- `parent_span_id`: you can supply a `parent_span` instead
172176
- The `Scope.transaction` property has been removed. To obtain the root span (previously transaction), use `Scope.root_span`. To set the root span's (transaction's) name, use `Scope.set_transaction_name()`.
173177
- The `Scope.span =` setter has been removed. Please use the new `span.activate()` api instead if you want to activate a new span manually instead of using the `start_span` context manager.
174-
- Passing a list or `None` for `failed_request_status_codes` in the Starlette integration is no longer supported. Pass a set of integers instead.
178+
- `span.containing_transaction` has been removed. Use `span.root_span` instead.
179+
- `continue_from_headers`, `continue_from_environ` and `from_traceparent` have been removed, please use top-level API `sentry_sdk.continue_trace` instead.
180+
- `Baggage.populate_from_transaction` has been removed.
181+
182+
#### Integrations
183+
184+
- PyMongo: The integration no longer sets tags. The data is still accessible via span attributes.
185+
- PyMongo: The integration doesn't set `operation_ids` anymore. The individual IDs (`operation_id`, `request_id`, `session_id`) are now accessible as separate span attributes.
186+
- Django: Dropped support for Django versions below 2.0.
187+
- trytond: Dropped support for trytond versions below 5.0.
188+
- Falcon: Dropped support for Falcon versions below 3.0.
189+
- eventlet: Dropped support for eventlet completely.
190+
- Threading: The integration no longer takes the `propagate_hub` argument.
191+
- Starlette: Passing a list or `None` for `failed_request_status_codes` is no longer supported. Pass a set of integers instead.
192+
193+
#### Profiling
194+
195+
- `profiles_sample_rate` and `profiler_mode` were removed from options available via `_experiments`. Use the top-level `profiles_sample_rate` and `profiler_mode` options instead.
196+
197+
#### Transport
198+
199+
- `Transport.capture_event` has been removed. Use `Transport.capture_envelope` instead.
200+
- Function transports are no longer supported. Subclass the `Transport` instead.
201+
202+
#### Sessions
203+
204+
- The context manager `auto_session_tracking()` has been removed. Use `track_session()` instead.
205+
- The context manager `auto_session_tracking_scope()` has been removed. Use `track_session()` instead.
206+
- Utility function `is_auto_session_tracking_enabled()` has been removed. There is no public replacement. There is a private `_is_auto_session_tracking_enabled()` (if you absolutely need this function) It accepts a `scope` parameter instead of the previously used `hub` parameter.
207+
- Utility function `is_auto_session_tracking_enabled_scope()` has been removed. There is no public replacement. There is a private `_is_auto_session_tracking_enabled()` (if you absolutely need this function).
208+
209+
#### Metrics
210+
211+
- `sentry_sdk.metrics` and associated metrics APIs have been removed as Sentry no longer accepts metrics data in this form. See https://sentry.zendesk.com/hc/en-us/articles/26369339769883-Upcoming-API-Changes-to-Metrics
212+
- The experimental options `enable_metrics`, `before_emit_metric` and `metric_code_locations` have been removed.
213+
214+
#### Internals
215+
216+
- Class `Hub` has been removed.
217+
- Class `_ScopeManager` has been removed.
218+
- `PropagationContext` constructor no longer takes a `dynamic_sampling_context` but takes a `baggage` object instead.
219+
- Setting `scope.level` has been removed. Use `scope.set_level` instead.
220+
- `debug.configure_debug_hub` was removed.
175221
- The `span` argument of `Scope.trace_propagation_meta` is no longer supported.
176-
- Setting `Scope.user` directly is no longer supported. Use `Scope.set_user()` instead.
177-
- Dropped support for Django versions below 2.0.
178-
- Dropped support for trytond versions below 5.0.
179-
- Dropped support for Falcon versions below 3.0.
180-
- Dropped support for eventlet completely.
222+
181223

182224
### Deprecated
183225

184226
- `sentry_sdk.start_transaction()` is deprecated. Use `sentry_sdk.start_span()` instead.
227+
- If you want to force creation of a new trace, use the `sentry_sdk.new_trace()` context manager.
185228
- `Span.set_data()` is deprecated. Use `Span.set_attribute()` instead.
186229

230+
231+
---------------------------------------------------------------------------------
232+
233+
187234
## Upgrading to 2.0
188235

189236
Looking to upgrade from Sentry SDK 1.x to 2.x? Here's a comprehensive list of what's changed. Looking for a more digestible summary? See the [guide in the docs](https://docs.sentry.io/platforms/python/migration/1.x-to-2.x) with the most common migration patterns.

sentry_sdk/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"capture_exception",
2323
"capture_message",
2424
"continue_trace",
25+
"new_trace",
2526
"flush",
2627
"get_baggage",
2728
"get_client",
@@ -47,6 +48,7 @@
4748
"logger",
4849
"start_session",
4950
"end_session",
51+
"set_transaction_name",
5052
]
5153

5254
# Initialize the debug support after everything is loaded

sentry_sdk/ai/monitoring.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def sync_wrapped(*args: Any, **kwargs: Any) -> Any:
3838
for k, v in kwargs.pop("sentry_data", {}).items():
3939
span.set_attribute(k, v)
4040
if curr_pipeline:
41-
span.set_attribute(SPANDATA.AI_PIPELINE_NAME, curr_pipeline)
41+
span.set_attribute(SPANDATA.GEN_AI_PIPELINE_NAME, curr_pipeline)
4242
return f(*args, **kwargs)
4343
else:
4444
_ai_pipeline_name.set(description)
@@ -68,7 +68,7 @@ async def async_wrapped(*args: Any, **kwargs: Any) -> Any:
6868
for k, v in kwargs.pop("sentry_data", {}).items():
6969
span.set_attribute(k, v)
7070
if curr_pipeline:
71-
span.set_attribute(SPANDATA.AI_PIPELINE_NAME, curr_pipeline)
71+
span.set_attribute(SPANDATA.GEN_AI_PIPELINE_NAME, curr_pipeline)
7272
return await f(*args, **kwargs)
7373
else:
7474
_ai_pipeline_name.set(description)
@@ -105,7 +105,7 @@ def record_token_usage(
105105
# TODO: move pipeline name elsewhere
106106
ai_pipeline_name = get_ai_pipeline_name()
107107
if ai_pipeline_name:
108-
span.set_attribute(SPANDATA.AI_PIPELINE_NAME, ai_pipeline_name)
108+
span.set_attribute(SPANDATA.GEN_AI_PIPELINE_NAME, ai_pipeline_name)
109109

110110
if input_tokens is not None:
111111
span.set_attribute(SPANDATA.GEN_AI_USAGE_INPUT_TOKENS, input_tokens)
@@ -117,10 +117,10 @@ def record_token_usage(
117117
)
118118

119119
if output_tokens is not None:
120-
span.set_data(SPANDATA.GEN_AI_USAGE_OUTPUT_TOKENS, output_tokens)
120+
span.set_attribute(SPANDATA.GEN_AI_USAGE_OUTPUT_TOKENS, output_tokens)
121121

122122
if output_tokens_reasoning is not None:
123-
span.set_data(
123+
span.set_attribute(
124124
SPANDATA.GEN_AI_USAGE_OUTPUT_TOKENS_REASONING,
125125
output_tokens_reasoning,
126126
)

sentry_sdk/ai/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ def _normalize_data(data: Any) -> Any:
2323
return list(_normalize_data(x) for x in data)
2424
if isinstance(data, dict):
2525
return {k: _normalize_data(v) for (k, v) in data.items()}
26+
2627
return data
2728

2829

2930
def set_data_normalized(span: Span, key: str, value: Any) -> None:
3031
normalized = _normalize_data(value)
31-
span.set_attribute(key, normalized)
32+
if isinstance(normalized, (int, float, bool, str)):
33+
span.set_attribute(key, normalized)
34+
else:
35+
span.set_attribute(key, str(normalized))

0 commit comments

Comments
 (0)