structlog-sentry 2.1.0__tar.gz → 2.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: structlog-sentry
3
- Version: 2.1.0
3
+ Version: 2.2.0
4
4
  Summary: Sentry integration for structlog
5
5
  Home-page: https://github.com/kiwicom/structlog-sentry
6
6
  License: MIT
@@ -19,8 +19,9 @@ Classifier: Programming Language :: Python :: 3.9
19
19
  Classifier: Programming Language :: Python :: 3.10
20
20
  Classifier: Programming Language :: Python :: 3.11
21
21
  Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
22
23
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
- Requires-Dist: sentry-sdk
24
+ Requires-Dist: sentry-sdk (>=2.0,<3.0)
24
25
  Requires-Dist: structlog
25
26
  Project-URL: Repository, https://github.com/kiwicom/structlog-sentry
26
27
  Description-Content-Type: text/markdown
@@ -73,7 +74,7 @@ Do not forget to add the `structlog.stdlib.add_log_level` and optionally the
73
74
  `SentryProcessor` class takes the following arguments:
74
75
 
75
76
  - `level` Events of this or higher levels will be reported as Sentry
76
- breadcrumbs. Dfault is `logging.INFO`.
77
+ breadcrumbs. Default is `logging.INFO`.
77
78
  - `event_level` Events of this or higher levels will be reported to Sentry
78
79
  as events. Default is `logging.WARNING`.
79
80
  - `active` A flag to make this processor enabled/disabled.
@@ -89,7 +90,8 @@ Do not forget to add the `structlog.stdlib.add_log_level` and optionally the
89
90
  - `ignore_loggers` A list of logger names to ignore any events from.
90
91
  - `verbose` Report the action taken by the logger in the `event_dict`.
91
92
  Default is `False`.
92
- - `hub` Optionally specify `sentry_sdk.Hub`.
93
+ - `scope` Optionally specify `sentry_sdk.Client` (in `structlog-sentry<2.2`
94
+ this corresponds to `hub: sentry_sdk.Hub`).
93
95
 
94
96
  Now events are automatically captured by Sentry with `log.error()`:
95
97
 
@@ -140,7 +142,7 @@ structlog.configure(
140
142
  processors=[
141
143
  structlog.stdlib.add_logger_name,
142
144
  structlog.stdlib.add_log_level,
143
- SentryProcessor(level=logging.ERROR, tag_keys=["city", "timezone"]),
145
+ SentryProcessor(event_level=logging.ERROR, tag_keys=["city", "timezone"]),
144
146
  ],...
145
147
  )
146
148
 
@@ -155,7 +157,7 @@ structlog.configure(
155
157
  processors=[
156
158
  structlog.stdlib.add_logger_name,
157
159
  structlog.stdlib.add_log_level,
158
- SentryProcessor(level=logging.ERROR, tag_keys="__all__"),
160
+ SentryProcessor(event_level=logging.ERROR, tag_keys="__all__"),
159
161
  ],...
160
162
  )
161
163
  ```
@@ -170,7 +172,7 @@ structlog.configure(
170
172
  processors=[
171
173
  structlog.stdlib.add_logger_name,
172
174
  structlog.stdlib.add_log_level,
173
- SentryProcessor(level=logging.ERROR, as_context=False, tag_keys="__all__"),
175
+ SentryProcessor(event_level=logging.ERROR, as_context=False, tag_keys="__all__"),
174
176
  ],...
175
177
  )
176
178
  ```
@@ -185,7 +187,7 @@ structlog.configure(
185
187
  processors=[
186
188
  structlog.stdlib.add_logger_name,
187
189
  structlog.stdlib.add_log_level,
188
- SentryProcessor(level=logging.ERROR, ignore_loggers=["some.logger"]),
190
+ SentryProcessor(event_level=logging.ERROR, ignore_loggers=["some.logger"]),
189
191
  ],...
190
192
  )
191
193
  ```
@@ -46,7 +46,7 @@ Do not forget to add the `structlog.stdlib.add_log_level` and optionally the
46
46
  `SentryProcessor` class takes the following arguments:
47
47
 
48
48
  - `level` Events of this or higher levels will be reported as Sentry
49
- breadcrumbs. Dfault is `logging.INFO`.
49
+ breadcrumbs. Default is `logging.INFO`.
50
50
  - `event_level` Events of this or higher levels will be reported to Sentry
51
51
  as events. Default is `logging.WARNING`.
52
52
  - `active` A flag to make this processor enabled/disabled.
@@ -62,7 +62,8 @@ Do not forget to add the `structlog.stdlib.add_log_level` and optionally the
62
62
  - `ignore_loggers` A list of logger names to ignore any events from.
63
63
  - `verbose` Report the action taken by the logger in the `event_dict`.
64
64
  Default is `False`.
65
- - `hub` Optionally specify `sentry_sdk.Hub`.
65
+ - `scope` Optionally specify `sentry_sdk.Client` (in `structlog-sentry<2.2`
66
+ this corresponds to `hub: sentry_sdk.Hub`).
66
67
 
67
68
  Now events are automatically captured by Sentry with `log.error()`:
68
69
 
@@ -113,7 +114,7 @@ structlog.configure(
113
114
  processors=[
114
115
  structlog.stdlib.add_logger_name,
115
116
  structlog.stdlib.add_log_level,
116
- SentryProcessor(level=logging.ERROR, tag_keys=["city", "timezone"]),
117
+ SentryProcessor(event_level=logging.ERROR, tag_keys=["city", "timezone"]),
117
118
  ],...
118
119
  )
119
120
 
@@ -128,7 +129,7 @@ structlog.configure(
128
129
  processors=[
129
130
  structlog.stdlib.add_logger_name,
130
131
  structlog.stdlib.add_log_level,
131
- SentryProcessor(level=logging.ERROR, tag_keys="__all__"),
132
+ SentryProcessor(event_level=logging.ERROR, tag_keys="__all__"),
132
133
  ],...
133
134
  )
134
135
  ```
@@ -143,7 +144,7 @@ structlog.configure(
143
144
  processors=[
144
145
  structlog.stdlib.add_logger_name,
145
146
  structlog.stdlib.add_log_level,
146
- SentryProcessor(level=logging.ERROR, as_context=False, tag_keys="__all__"),
147
+ SentryProcessor(event_level=logging.ERROR, as_context=False, tag_keys="__all__"),
147
148
  ],...
148
149
  )
149
150
  ```
@@ -158,7 +159,7 @@ structlog.configure(
158
159
  processors=[
159
160
  structlog.stdlib.add_logger_name,
160
161
  structlog.stdlib.add_log_level,
161
- SentryProcessor(level=logging.ERROR, ignore_loggers=["some.logger"]),
162
+ SentryProcessor(event_level=logging.ERROR, ignore_loggers=["some.logger"]),
162
163
  ],...
163
164
  )
164
165
  ```
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "structlog-sentry"
3
- version = "2.1.0"
3
+ version = "2.2.0"
4
4
  description = "Sentry integration for structlog"
5
5
  authors = ["Kiwi.com platform <platform@kiwi.com>"]
6
6
  license = "MIT"
@@ -27,7 +27,7 @@ include = ["*.md", "*.toml", "*.txt", "*.yml", "*.yaml", ".coveragerc", "tox.ini
27
27
 
28
28
  [tool.poetry.dependencies]
29
29
  python = "^3.7"
30
- sentry-sdk = "*"
30
+ sentry-sdk = "^2.0"
31
31
  structlog = "*"
32
32
 
33
33
  [tool.poetry.dev-dependencies]
@@ -6,7 +6,7 @@ from fnmatch import fnmatch
6
6
  from typing import Any, Optional
7
7
  from collections.abc import MutableMapping, Iterable
8
8
 
9
- from sentry_sdk import Hub
9
+ from sentry_sdk import Scope, get_isolation_scope
10
10
  from sentry_sdk.integrations.logging import _IGNORED_LOGGERS
11
11
  from sentry_sdk.utils import capture_internal_exceptions, event_from_exception
12
12
  from structlog.types import EventDict, ExcInfo, WrappedLogger
@@ -48,7 +48,7 @@ class SentryProcessor:
48
48
  tag_keys: list[str] | str | None = None,
49
49
  ignore_loggers: Iterable[str] | None = None,
50
50
  verbose: bool = False,
51
- hub: Hub | None = None,
51
+ scope: Scope | None = None,
52
52
  ) -> None:
53
53
  """
54
54
  :param level: Events of this or higher levels will be reported as
@@ -66,7 +66,7 @@ class SentryProcessor:
66
66
  :param ignore_loggers: A list of logger names to ignore any events from.
67
67
  :param verbose: Report the action taken by the logger in the `event_dict`.
68
68
  Default is :obj:`False`.
69
- :param hub: Optionally specify :obj:`sentry_sdk.Hub`.
69
+ :param scope: Optionally specify :obj:`sentry_sdk.Scope`.
70
70
  """
71
71
  self.event_level = event_level
72
72
  self.level = level
@@ -74,7 +74,7 @@ class SentryProcessor:
74
74
  self.tag_keys = tag_keys
75
75
  self.verbose = verbose
76
76
 
77
- self._hub = hub
77
+ self._scope = scope
78
78
  self._as_context = as_context
79
79
  self._original_event_dict: dict = {}
80
80
  self.ignore_breadcrumb_data = ignore_breadcrumb_data
@@ -107,8 +107,8 @@ class SentryProcessor:
107
107
 
108
108
  return logger_name
109
109
 
110
- def _get_hub(self) -> Hub:
111
- return self._hub or Hub.current
110
+ def _get_scope(self) -> Scope:
111
+ return self._scope or get_isolation_scope()
112
112
 
113
113
  def _get_event_and_hint(self, event_dict: EventDict) -> tuple[dict, dict]:
114
114
  """Create a sentry event and hint from structlog `event_dict` and sys.exc_info.
@@ -119,7 +119,7 @@ class SentryProcessor:
119
119
  has_exc_info = exc_info and exc_info != (None, None, None)
120
120
 
121
121
  if has_exc_info:
122
- client = self._get_hub().client
122
+ client = self._get_scope().client
123
123
  options: dict[str, Any] = client.options if client else {}
124
124
  event, hint = event_from_exception(
125
125
  exc_info,
@@ -172,7 +172,7 @@ class SentryProcessor:
172
172
  def _handle_event(self, event_dict: EventDict) -> None:
173
173
  with capture_internal_exceptions():
174
174
  event, hint = self._get_event_and_hint(event_dict)
175
- sid = self._get_hub().capture_event(event, hint=hint)
175
+ sid = self._get_scope().capture_event(event, hint=hint)
176
176
  if sid:
177
177
  event_dict["sentry_id"] = sid
178
178
  if self.verbose:
@@ -181,7 +181,7 @@ class SentryProcessor:
181
181
  def _handle_breadcrumb(self, event_dict: EventDict) -> None:
182
182
  with capture_internal_exceptions():
183
183
  event, hint = self._get_breadcrumb_and_hint(event_dict)
184
- self._get_hub().add_breadcrumb(event, hint=hint)
184
+ self._get_scope().add_breadcrumb(event, hint=hint)
185
185
 
186
186
  @staticmethod
187
187
  def _get_level_value(level_name: str) -> int: