Skip to content

Commit f5fb6e7

Browse files
feat(scope): Remove client parameter (#4449)
We don't use the `client` parameter in the `Scope`'s constructor, perhaps we can remove it and simplify the API. It is still possible to set the client with `Scope.set_client`. BREAKING CHANGE: `sentry_sdk.Scope` no longer has a `client` parameter. <!-- Describe your PR here --> --- Thank you for contributing to `sentry-python`! Please add tests to validate your changes, and lint your code using `tox -e linters`. Running the test suite on your PR might require maintainer approval.
1 parent 2db6a04 commit f5fb6e7

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

MIGRATION_GUIDE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
1616
- `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`.
1717
- You can no longer change the sampled status of a span with `span.sampled = False` after starting it.
1818
- The `Span()` constructor does not accept a `hub` parameter anymore.
19+
- The `sentry_sdk.Scope()` constructor no longer accepts a `client` parameter.
1920
- `Span.finish()` does not accept a `hub` parameter anymore.
2021
- `Span.finish()` no longer returns the `event_id` if the event is sent to sentry.
2122
- The `Profile()` constructor does not accept a `hub` parameter anymore.
@@ -31,6 +32,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
3132
- 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")])`.
3233
- The `SentrySpanProcessor` and `SentryPropagator` are exported from `sentry_sdk.opentelemetry` instead of `sentry_sdk.integrations.opentelemetry`.
3334
- The integration-specific content of the `sampling_context` argument of `traces_sampler` and `profiles_sampler` now looks different.
35+
3436
- The Celery integration doesn't add the `celery_job` dictionary anymore. Instead, the individual keys are now available as:
3537

3638
| Dictionary keys | Sampling context key | Example |
@@ -133,7 +135,6 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
133135
| `gcp_event.query_string` | `url.query` |
134136
| `gcp_event.headers` | `http.request.header.{header}` |
135137

136-
137138
### Removed
138139

139140
- Dropped support for Python 3.6.

sentry_sdk/scope.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ class Scope:
172172
"_flags",
173173
)
174174

175-
def __init__(self, ty=None, client=None):
176-
# type: (Optional[ScopeType], Optional[sentry_sdk.Client]) -> None
175+
def __init__(self, ty=None):
176+
# type: (Optional[ScopeType]) -> None
177177
self._type = ty
178178

179179
self._event_processors = [] # type: List[EventProcessor]
@@ -185,9 +185,6 @@ def __init__(self, ty=None, client=None):
185185

186186
self.client = NonRecordingClient() # type: sentry_sdk.client.BaseClient
187187

188-
if client is not None:
189-
self.set_client(client)
190-
191188
self.clear()
192189

193190
incoming_trace_information = self._load_trace_data_from_env()

tests/test_scope.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ def test_scope_client():
216216
assert scope.client.__class__ == NonRecordingClient
217217

218218
custom_client = Client()
219-
scope = Scope(ty="test_more", client=custom_client)
219+
scope = Scope(ty="test_more")
220+
scope.set_client(custom_client)
220221
assert scope._type == "test_more"
221222
assert scope.client is not None
222223
assert scope.client.__class__ == Client

0 commit comments

Comments
 (0)