structlog-sentry 2.2.1__py3-none-any.whl → 2.2.2__py3-none-any.whl

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.
@@ -76,7 +76,6 @@ class SentryProcessor:
76
76
 
77
77
  self._scope = scope
78
78
  self._as_context = as_context
79
- self._original_event_dict: dict = {}
80
79
  self.ignore_breadcrumb_data = ignore_breadcrumb_data
81
80
 
82
81
  self._ignored_loggers: set[str] = set()
@@ -134,9 +133,9 @@ class SentryProcessor:
134
133
  event["logger"] = event_dict["logger"]
135
134
 
136
135
  if self._as_context:
137
- event["contexts"] = {"structlog": self._original_event_dict.copy()}
136
+ event["contexts"] = {"structlog": dict(event_dict)}
138
137
  if self.tag_keys == "__all__":
139
- event["tags"] = self._original_event_dict.copy()
138
+ event["tags"] = dict(event_dict)
140
139
  if isinstance(self.tag_keys, list):
141
140
  event["tags"] = {
142
141
  key: event_dict[key] for key in self.tag_keys if key in event_dict
@@ -202,7 +201,6 @@ class SentryProcessor:
202
201
  self, logger: WrappedLogger, name: str, event_dict: EventDict
203
202
  ) -> EventDict:
204
203
  """A middleware to process structlog `event_dict` and send it to Sentry."""
205
- self._original_event_dict = dict(event_dict)
206
204
  sentry_skip = event_dict.pop("sentry_skip", False)
207
205
 
208
206
  if self.active and not sentry_skip and self._can_record(logger, event_dict):
@@ -1,9 +1,9 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: structlog-sentry
3
- Version: 2.2.1
3
+ Version: 2.2.2
4
4
  Summary: Sentry integration for structlog
5
- Home-page: https://github.com/kiwicom/structlog-sentry
6
5
  License: MIT
6
+ License-File: LICENSE
7
7
  Author: Kiwi.com platform
8
8
  Author-email: platform@kiwi.com
9
9
  Requires-Python: >=3.7,<4.0
@@ -20,9 +20,12 @@ Classifier: Programming Language :: Python :: 3.10
20
20
  Classifier: Programming Language :: Python :: 3.11
21
21
  Classifier: Programming Language :: Python :: 3.12
22
22
  Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Programming Language :: Python :: 3.15
23
25
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
26
  Requires-Dist: sentry-sdk (>=2.15.0,<3.0.0)
25
27
  Requires-Dist: structlog
28
+ Project-URL: Homepage, https://github.com/kiwicom/structlog-sentry
26
29
  Project-URL: Repository, https://github.com/kiwicom/structlog-sentry
27
30
  Description-Content-Type: text/markdown
28
31
 
@@ -0,0 +1,6 @@
1
+ structlog_sentry/__init__.py,sha256=_Fk1ZOyK0tWnKLP7l9PaYJRcStsMPJvmm2hGGi9UvCs,8061
2
+ structlog_sentry/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ structlog_sentry-2.2.2.dist-info/METADATA,sha256=Fd8NR89XFtrA99JbpPcdRA0utC6tVgCpgCH-YZE12uo,7682
4
+ structlog_sentry-2.2.2.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
5
+ structlog_sentry-2.2.2.dist-info/licenses/LICENSE,sha256=UWmiHDL_McEeMpY2BixxsfIinafoqz9zvy80-y6Agyk,1065
6
+ structlog_sentry-2.2.2.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.1
2
+ Generator: poetry-core 2.5.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
.coveragerc DELETED
@@ -1,2 +0,0 @@
1
- [run]
2
- branch = True
.pre-commit-config.yaml DELETED
@@ -1,30 +0,0 @@
1
- repos:
2
- - repo: https://github.com/astral-sh/ruff-pre-commit
3
- rev: v0.3.2
4
- hooks:
5
- - id: ruff-format
6
-
7
- - repo: https://github.com/astral-sh/ruff-pre-commit
8
- rev: v0.3.2
9
- hooks:
10
- - id: ruff
11
- args: ["--fix", "--exit-non-zero-on-fix", "--config", "pyproject.toml"]
12
-
13
- - repo: https://github.com/pre-commit/pre-commit-hooks
14
- rev: v4.5.0
15
- hooks:
16
- - id: trailing-whitespace
17
- - id: end-of-file-fixer
18
- - id: debug-statements
19
-
20
- - repo: https://github.com/pre-commit/mirrors-mypy
21
- rev: v1.9.0
22
- hooks:
23
- - id: mypy
24
-
25
- - repo: https://github.com/pre-commit/mirrors-prettier
26
- rev: v3.1.0
27
- hooks:
28
- - id: prettier
29
- name: prettier (*.md)
30
- files: .*\.md
README.md DELETED
@@ -1,198 +0,0 @@
1
- # structlog-sentry
2
-
3
- | What | Where |
4
- | ------------- | --------------------------------------------- |
5
- | Documentation | <https://github.com/kiwicom/structlog-sentry> |
6
- | Maintainer | @kiwicom/platform |
7
-
8
- Based on <https://gist.github.com/hynek/a1f3f92d57071ebc5b91>
9
-
10
- ## Installation
11
-
12
- Install the package with [pip](https://pip.pypa.io/):
13
-
14
- ```
15
- pip install structlog-sentry
16
- ```
17
-
18
- ## Usage
19
-
20
- This module is intended to be used with `structlog` like this:
21
-
22
- ```python
23
- import sentry_sdk
24
- import structlog
25
- from structlog_sentry import SentryProcessor
26
-
27
-
28
- sentry_sdk.init() # pass dsn in argument or via SENTRY_DSN env variable
29
-
30
- structlog.configure(
31
- processors=[
32
- structlog.stdlib.add_logger_name, # optional, must be placed before SentryProcessor()
33
- structlog.stdlib.add_log_level, # required before SentryProcessor()
34
- SentryProcessor(event_level=logging.ERROR),
35
- ],
36
- logger_factory=structlog.stdlib.LoggerFactory(),
37
- wrapper_class=structlog.stdlib.BoundLogger,
38
- )
39
-
40
-
41
- log = structlog.get_logger()
42
- ```
43
-
44
- Do not forget to add the `structlog.stdlib.add_log_level` and optionally the
45
- `structlog.stdlib.add_logger_name` processors before `SentryProcessor`. The
46
- `SentryProcessor` class takes the following arguments:
47
-
48
- - `level` Events of this or higher levels will be reported as Sentry
49
- breadcrumbs. Default is `logging.INFO`.
50
- - `event_level` Events of this or higher levels will be reported to Sentry
51
- as events. Default is `logging.WARNING`.
52
- - `active` A flag to make this processor enabled/disabled.
53
- - `as_context` Send `event_dict` as extra info to Sentry. Default is `True`.
54
- - `ignore_breadcrumb_data` A list of data keys that will be excluded from
55
- [breadcrumb data](https://docs.sentry.io/platforms/python/enriching-events/breadcrumbs/#manual-breadcrumbs).
56
- Defaults to keys which are already sent separately, i.e. `level`, `logger`,
57
- `event` and `timestamp`. All other data in `event_dict` will be sent as
58
- breadcrumb data.
59
- - `tag_keys` A list of keys. If any if these keys appear in `event_dict`,
60
- the key and its corresponding value in `event_dict` will be used as Sentry
61
- event tags. use `"__all__"` to report all key/value pairs of event as tags.
62
- - `ignore_loggers` A list of logger names to ignore any events from.
63
- - `verbose` Report the action taken by the logger in the `event_dict`.
64
- Default is `False`.
65
- - `scope` Optionally specify `sentry_sdk.Client` (in `structlog-sentry<2.2`
66
- this corresponds to `hub: sentry_sdk.Hub`).
67
-
68
- Now events are automatically captured by Sentry with `log.error()`:
69
-
70
- ```python
71
- try:
72
- 1/0
73
- except ZeroDivisionError:
74
- log.error("zero divsiion")
75
-
76
- try:
77
- resp = requests.get(f"https://api.example.com/users/{user_id}/")
78
- resp.raise_for_status()
79
- except RequestException:
80
- log.error("request error", user_id=user_id)
81
- ```
82
-
83
- This won't automatically collect `sys.exc_info()` along with the message, if you want
84
- to enable this behavior, just pass `exc_info=True`.
85
-
86
- When you want to use structlog's built-in
87
- [`format_exc_info`](http://www.structlog.org/en/stable/api.html#structlog.processors.format_exc_info)
88
- processor, make that the `SentryProcessor` comes _before_ `format_exc_info`!
89
- Otherwise, the `SentryProcessor` won't have an `exc_info` to work with, because
90
- it's removed from the event by `format_exc_info`.
91
-
92
- Logging calls with no `sys.exc_info()` are also automatically captured by Sentry
93
- either as breadcrumbs (if configured by the `level` argument) or as events:
94
-
95
- ```python
96
- log.info("info message", scope="accounts")
97
- log.warning("warning message", scope="invoices")
98
- log.error("error message", scope="products")
99
- ```
100
-
101
- If you do not want to forward a specific logs into Sentry, you can pass the
102
- `sentry_skip=True` optional argument to logger methods, like this:
103
-
104
- ```python
105
- log.error("error message", sentry_skip=True)
106
- ```
107
-
108
- ### Sentry Tags
109
-
110
- You can set some or all of key/value pairs of structlog `event_dict` as sentry `tags`:
111
-
112
- ```python
113
- structlog.configure(
114
- processors=[
115
- structlog.stdlib.add_logger_name,
116
- structlog.stdlib.add_log_level,
117
- SentryProcessor(event_level=logging.ERROR, tag_keys=["city", "timezone"]),
118
- ],...
119
- )
120
-
121
- log.error("error message", city="Tehran", timezone="UTC+3:30", movie_title="Some title")
122
- ```
123
-
124
- this will report the error and the sentry event will have **city** and **timezone** tags.
125
- If you want to have all event data as tags, create the `SentryProcessor` with `tag_keys="__all__"`.
126
-
127
- ```python
128
- structlog.configure(
129
- processors=[
130
- structlog.stdlib.add_logger_name,
131
- structlog.stdlib.add_log_level,
132
- SentryProcessor(event_level=logging.ERROR, tag_keys="__all__"),
133
- ],...
134
- )
135
- ```
136
-
137
- ### Skip Context
138
-
139
- By default `SentryProcessor` will send `event_dict` key/value pairs as contextual info to sentry.
140
- Sometimes you may want to skip this, specially when sending the `event_dict` as sentry tags:
141
-
142
- ```python
143
- structlog.configure(
144
- processors=[
145
- structlog.stdlib.add_logger_name,
146
- structlog.stdlib.add_log_level,
147
- SentryProcessor(event_level=logging.ERROR, as_context=False, tag_keys="__all__"),
148
- ],...
149
- )
150
- ```
151
-
152
- ### Ignore specific loggers
153
-
154
- If you want to ignore specific loggers from being processed by the `SentryProcessor` just pass
155
- a list of loggers when instantiating the processor:
156
-
157
- ```python
158
- structlog.configure(
159
- processors=[
160
- structlog.stdlib.add_logger_name,
161
- structlog.stdlib.add_log_level,
162
- SentryProcessor(event_level=logging.ERROR, ignore_loggers=["some.logger"]),
163
- ],...
164
- )
165
- ```
166
-
167
- ### Logging as JSON
168
-
169
- If you want to configure `structlog` to format the output as **JSON** (maybe for
170
- [elk-stack](https://www.elastic.co/elk-stack)) you have to disable standard logging
171
- integration in Sentry SDK by passing the `LoggingIntegration(event_level=None, level=None)`
172
- instance to `sentry_sdk.init` method. This prevents duplication of an event reported to sentry:
173
-
174
- ```python
175
- from sentry_sdk.integrations.logging import LoggingIntegration
176
-
177
-
178
- INTEGRATIONS = [
179
- # ... other integrations
180
- LoggingIntegration(event_level=None, level=None),
181
- ]
182
-
183
- sentry_sdk.init(integrations=INTEGRATIONS)
184
- ```
185
-
186
- This integration tells `sentry_sdk` to _ignore_ standard logging and captures the events manually.
187
-
188
- ## Testing
189
-
190
- To run all tests:
191
-
192
- ```
193
- tox
194
- ```
195
-
196
- ## Contributing
197
-
198
- Create a merge request and tag @kiwicom/platform for review.
pyproject.toml DELETED
@@ -1,40 +0,0 @@
1
- [tool.poetry]
2
- name = "structlog-sentry"
3
- version = "2.2.1"
4
- description = "Sentry integration for structlog"
5
- authors = ["Kiwi.com platform <platform@kiwi.com>"]
6
- license = "MIT"
7
- readme = "README.md"
8
- repository = "https://github.com/kiwicom/structlog-sentry"
9
- homepage = "https://github.com/kiwicom/structlog-sentry"
10
-
11
- classifiers=[
12
- "Development Status :: 5 - Production/Stable",
13
- "Environment :: Web Environment",
14
- "Intended Audience :: Developers",
15
- "License :: OSI Approved :: MIT License",
16
- "Programming Language :: Python",
17
- "Programming Language :: Python :: 3",
18
- "Programming Language :: Python :: 3.7",
19
- "Programming Language :: Python :: 3.8",
20
- "Programming Language :: Python :: 3.9",
21
- "Programming Language :: Python :: 3.10",
22
- "Programming Language :: Python :: 3.11",
23
- "Programming Language :: Python :: 3.12",
24
- "Topic :: Software Development :: Libraries :: Python Modules",
25
- ]
26
- include = ["*.md", "*.toml", "*.txt", "*.yml", "*.yaml", ".coveragerc", "tox.ini", "structlog_sentry/py.typed"]
27
-
28
- [tool.poetry.dependencies]
29
- python = "^3.7"
30
- sentry-sdk = "^2.15.0"
31
- structlog = "*"
32
-
33
- [tool.poetry.dev-dependencies]
34
- pytest = "^7.1.3"
35
- pytest-cov = "^4.1.0"
36
- pytest-mock = "^3.8.2"
37
-
38
- [build-system]
39
- requires = ["poetry-core>=1.5.1"]
40
- build-backend = "poetry.core.masonry.api"
@@ -1,11 +0,0 @@
1
- .coveragerc,sha256=SiH_JVKFeJVNCP4fBk230hbdrGBzY1m9jGkcOB7Zepg,20
2
- .pre-commit-config.yaml,sha256=zIOjUeATjctTu8aVNm_vCuqhYpKAt6rxN4oDmjMCmik,725
3
- README.md,sha256=XHH-Ts43svOmX_UNiOQtIt8vQ2l5QR2r0R8D-6JnMu0,6398
4
- pyproject.toml,sha256=qiGL6SGtEdHD5Stb9AmvQg8kzxp6CWEayah4DV0W_H0,1307
5
- structlog_sentry/__init__.py,sha256=otKu_VuBmsWrVuVbjqcDg6BJxW_KMHT9idzX-dzaCcM,8191
6
- structlog_sentry/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- tox.ini,sha256=GK7oZYVx7jBSpb4o4R0hafLtuRlZiUphx07Igvw8kB8,702
8
- structlog_sentry-2.2.1.dist-info/LICENSE,sha256=UWmiHDL_McEeMpY2BixxsfIinafoqz9zvy80-y6Agyk,1065
9
- structlog_sentry-2.2.1.dist-info/METADATA,sha256=BZgLz4u196Q5BMPiaJCT98Oy2ssQYPIlJAUmbX1A2_w,7546
10
- structlog_sentry-2.2.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
11
- structlog_sentry-2.2.1.dist-info/RECORD,,
tox.ini DELETED
@@ -1,41 +0,0 @@
1
- [tox]
2
- envlist =
3
- lint
4
- py{37,38,39,310,311,312}
5
- isolated_build = true
6
-
7
- [gh-actions]
8
- python =
9
- 3.7: py37
10
- 3.8: py38
11
- 3.9: py39
12
- 3.10: py310
13
- 3.11: py311
14
- 3.12: py312
15
-
16
- [testenv]
17
- whitelist_externals = poetry
18
- deps = poetry
19
- commands =
20
- poetry install
21
- poetry run coverage run --parallel-mode -m pytest {posargs}
22
- poetry run coverage combine
23
- poetry run coverage report
24
-
25
- [testenv:lint]
26
- basepython = python3.9
27
- skip_install = true
28
- deps = pre-commit
29
- passenv = HOMEPATH # needed on Windows
30
- commands = pre-commit run --all-files
31
-
32
- [isort]
33
- profile = black
34
- filter_files = true
35
- known_first_party = pytest,sentry_sdk,structlog
36
-
37
- [flake8]
38
- max-line-length = 88
39
-
40
- [pytest]
41
- testpaths = test