structlog-sentry 2.0.2__tar.gz → 2.1.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.
- structlog_sentry-2.1.0/.pre-commit-config.yaml +30 -0
- {structlog_sentry-2.0.2 → structlog_sentry-2.1.0}/PKG-INFO +13 -13
- {structlog_sentry-2.0.2 → structlog_sentry-2.1.0}/README.md +11 -6
- {structlog_sentry-2.0.2 → structlog_sentry-2.1.0}/pyproject.toml +5 -4
- {structlog_sentry-2.0.2 → structlog_sentry-2.1.0}/structlog_sentry/__init__.py +24 -18
- {structlog_sentry-2.0.2 → structlog_sentry-2.1.0}/tox.ini +10 -1
- structlog_sentry-2.0.2/.pre-commit-config.yaml +0 -26
- {structlog_sentry-2.0.2 → structlog_sentry-2.1.0}/.coveragerc +0 -0
- {structlog_sentry-2.0.2 → structlog_sentry-2.1.0}/LICENSE +0 -0
- {structlog_sentry-2.0.2 → structlog_sentry-2.1.0}/structlog_sentry/py.typed +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: structlog-sentry
|
|
3
|
-
Version: 2.0
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Summary: Sentry integration for structlog
|
|
5
5
|
Home-page: https://github.com/kiwicom/structlog-sentry
|
|
6
6
|
License: MIT
|
|
@@ -18,13 +18,8 @@ Classifier: Programming Language :: Python :: 3.8
|
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.9
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.10
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
-
Classifier: Programming Language :: Python :: 3
|
|
22
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
24
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
25
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
26
22
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
-
Requires-Dist: packaging
|
|
28
23
|
Requires-Dist: sentry-sdk
|
|
29
24
|
Requires-Dist: structlog
|
|
30
25
|
Project-URL: Repository, https://github.com/kiwicom/structlog-sentry
|
|
@@ -61,12 +56,12 @@ sentry_sdk.init() # pass dsn in argument or via SENTRY_DSN env variable
|
|
|
61
56
|
|
|
62
57
|
structlog.configure(
|
|
63
58
|
processors=[
|
|
64
|
-
structlog.stdlib.add_logger_name, # optional,
|
|
59
|
+
structlog.stdlib.add_logger_name, # optional, must be placed before SentryProcessor()
|
|
65
60
|
structlog.stdlib.add_log_level, # required before SentryProcessor()
|
|
66
61
|
SentryProcessor(event_level=logging.ERROR),
|
|
67
62
|
],
|
|
68
|
-
logger_factory
|
|
69
|
-
wrapper_class
|
|
63
|
+
logger_factory=structlog.stdlib.LoggerFactory(),
|
|
64
|
+
wrapper_class=structlog.stdlib.BoundLogger,
|
|
70
65
|
)
|
|
71
66
|
|
|
72
67
|
|
|
@@ -83,6 +78,11 @@ Do not forget to add the `structlog.stdlib.add_log_level` and optionally the
|
|
|
83
78
|
as events. Default is `logging.WARNING`.
|
|
84
79
|
- `active` A flag to make this processor enabled/disabled.
|
|
85
80
|
- `as_context` Send `event_dict` as extra info to Sentry. Default is `True`.
|
|
81
|
+
- `ignore_breadcrumb_data` A list of data keys that will be excluded from
|
|
82
|
+
[breadcrumb data](https://docs.sentry.io/platforms/python/enriching-events/breadcrumbs/#manual-breadcrumbs).
|
|
83
|
+
Defaults to keys which are already sent separately, i.e. `level`, `logger`,
|
|
84
|
+
`event` and `timestamp`. All other data in `event_dict` will be sent as
|
|
85
|
+
breadcrumb data.
|
|
86
86
|
- `tag_keys` A list of keys. If any if these keys appear in `event_dict`,
|
|
87
87
|
the key and its corresponding value in `event_dict` will be used as Sentry
|
|
88
88
|
event tags. use `"__all__"` to report all key/value pairs of event as tags.
|
|
@@ -111,7 +111,7 @@ to enable this behavior, just pass `exc_info=True`.
|
|
|
111
111
|
|
|
112
112
|
When you want to use structlog's built-in
|
|
113
113
|
[`format_exc_info`](http://www.structlog.org/en/stable/api.html#structlog.processors.format_exc_info)
|
|
114
|
-
processor, make that the `SentryProcessor` comes
|
|
114
|
+
processor, make that the `SentryProcessor` comes _before_ `format_exc_info`!
|
|
115
115
|
Otherwise, the `SentryProcessor` won't have an `exc_info` to work with, because
|
|
116
116
|
it's removed from the event by `format_exc_info`.
|
|
117
117
|
|
|
@@ -209,7 +209,7 @@ INTEGRATIONS = [
|
|
|
209
209
|
sentry_sdk.init(integrations=INTEGRATIONS)
|
|
210
210
|
```
|
|
211
211
|
|
|
212
|
-
This integration tells `sentry_sdk` to
|
|
212
|
+
This integration tells `sentry_sdk` to _ignore_ standard logging and captures the events manually.
|
|
213
213
|
|
|
214
214
|
## Testing
|
|
215
215
|
|
|
@@ -221,5 +221,5 @@ tox
|
|
|
221
221
|
|
|
222
222
|
## Contributing
|
|
223
223
|
|
|
224
|
-
Create a merge request and tag @kiwicom/platform
|
|
224
|
+
Create a merge request and tag @kiwicom/platform for review.
|
|
225
225
|
|
|
@@ -29,12 +29,12 @@ sentry_sdk.init() # pass dsn in argument or via SENTRY_DSN env variable
|
|
|
29
29
|
|
|
30
30
|
structlog.configure(
|
|
31
31
|
processors=[
|
|
32
|
-
structlog.stdlib.add_logger_name, # optional,
|
|
32
|
+
structlog.stdlib.add_logger_name, # optional, must be placed before SentryProcessor()
|
|
33
33
|
structlog.stdlib.add_log_level, # required before SentryProcessor()
|
|
34
34
|
SentryProcessor(event_level=logging.ERROR),
|
|
35
35
|
],
|
|
36
|
-
logger_factory
|
|
37
|
-
wrapper_class
|
|
36
|
+
logger_factory=structlog.stdlib.LoggerFactory(),
|
|
37
|
+
wrapper_class=structlog.stdlib.BoundLogger,
|
|
38
38
|
)
|
|
39
39
|
|
|
40
40
|
|
|
@@ -51,6 +51,11 @@ Do not forget to add the `structlog.stdlib.add_log_level` and optionally the
|
|
|
51
51
|
as events. Default is `logging.WARNING`.
|
|
52
52
|
- `active` A flag to make this processor enabled/disabled.
|
|
53
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.
|
|
54
59
|
- `tag_keys` A list of keys. If any if these keys appear in `event_dict`,
|
|
55
60
|
the key and its corresponding value in `event_dict` will be used as Sentry
|
|
56
61
|
event tags. use `"__all__"` to report all key/value pairs of event as tags.
|
|
@@ -79,7 +84,7 @@ to enable this behavior, just pass `exc_info=True`.
|
|
|
79
84
|
|
|
80
85
|
When you want to use structlog's built-in
|
|
81
86
|
[`format_exc_info`](http://www.structlog.org/en/stable/api.html#structlog.processors.format_exc_info)
|
|
82
|
-
processor, make that the `SentryProcessor` comes
|
|
87
|
+
processor, make that the `SentryProcessor` comes _before_ `format_exc_info`!
|
|
83
88
|
Otherwise, the `SentryProcessor` won't have an `exc_info` to work with, because
|
|
84
89
|
it's removed from the event by `format_exc_info`.
|
|
85
90
|
|
|
@@ -177,7 +182,7 @@ INTEGRATIONS = [
|
|
|
177
182
|
sentry_sdk.init(integrations=INTEGRATIONS)
|
|
178
183
|
```
|
|
179
184
|
|
|
180
|
-
This integration tells `sentry_sdk` to
|
|
185
|
+
This integration tells `sentry_sdk` to _ignore_ standard logging and captures the events manually.
|
|
181
186
|
|
|
182
187
|
## Testing
|
|
183
188
|
|
|
@@ -189,4 +194,4 @@ tox
|
|
|
189
194
|
|
|
190
195
|
## Contributing
|
|
191
196
|
|
|
192
|
-
Create a merge request and tag @kiwicom/platform
|
|
197
|
+
Create a merge request and tag @kiwicom/platform for review.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "structlog-sentry"
|
|
3
|
-
version = "2.0
|
|
3
|
+
version = "2.1.0"
|
|
4
4
|
description = "Sentry integration for structlog"
|
|
5
5
|
authors = ["Kiwi.com platform <platform@kiwi.com>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -19,21 +19,22 @@ classifiers=[
|
|
|
19
19
|
"Programming Language :: Python :: 3.8",
|
|
20
20
|
"Programming Language :: Python :: 3.9",
|
|
21
21
|
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
22
24
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
23
25
|
]
|
|
24
26
|
include = ["*.md", "*.toml", "*.txt", "*.yml", "*.yaml", ".coveragerc", "tox.ini", "structlog_sentry/py.typed"]
|
|
25
27
|
|
|
26
28
|
[tool.poetry.dependencies]
|
|
27
29
|
python = "^3.7"
|
|
28
|
-
packaging = "*"
|
|
29
30
|
sentry-sdk = "*"
|
|
30
31
|
structlog = "*"
|
|
31
32
|
|
|
32
33
|
[tool.poetry.dev-dependencies]
|
|
33
34
|
pytest = "^7.1.3"
|
|
34
|
-
pytest-cov = "^
|
|
35
|
+
pytest-cov = "^4.1.0"
|
|
35
36
|
pytest-mock = "^3.8.2"
|
|
36
37
|
|
|
37
38
|
[build-system]
|
|
38
|
-
requires = ["poetry-core>=1.
|
|
39
|
+
requires = ["poetry-core>=1.5.1"]
|
|
39
40
|
build-backend = "poetry.core.masonry.api"
|
|
@@ -3,17 +3,14 @@ from __future__ import annotations
|
|
|
3
3
|
import logging
|
|
4
4
|
import sys
|
|
5
5
|
from fnmatch import fnmatch
|
|
6
|
-
from typing import Any,
|
|
6
|
+
from typing import Any, Optional
|
|
7
|
+
from collections.abc import MutableMapping, Iterable
|
|
7
8
|
|
|
8
|
-
from
|
|
9
|
-
|
|
10
|
-
from sentry_sdk import VERSION, Hub
|
|
9
|
+
from sentry_sdk import Hub
|
|
11
10
|
from sentry_sdk.integrations.logging import _IGNORED_LOGGERS
|
|
12
11
|
from sentry_sdk.utils import capture_internal_exceptions, event_from_exception
|
|
13
12
|
from structlog.types import EventDict, ExcInfo, WrappedLogger
|
|
14
13
|
|
|
15
|
-
_IS_OLD_VERSION = version.parse(VERSION) < version.parse("1.17.0")
|
|
16
|
-
|
|
17
14
|
|
|
18
15
|
def _figure_out_exc_info(v: Any) -> ExcInfo:
|
|
19
16
|
"""
|
|
@@ -42,6 +39,12 @@ class SentryProcessor:
|
|
|
42
39
|
event_level: int = logging.WARNING,
|
|
43
40
|
active: bool = True,
|
|
44
41
|
as_context: bool = True,
|
|
42
|
+
ignore_breadcrumb_data: Iterable[str] = (
|
|
43
|
+
"level",
|
|
44
|
+
"logger",
|
|
45
|
+
"event",
|
|
46
|
+
"timestamp",
|
|
47
|
+
),
|
|
45
48
|
tag_keys: list[str] | str | None = None,
|
|
46
49
|
ignore_loggers: Iterable[str] | None = None,
|
|
47
50
|
verbose: bool = False,
|
|
@@ -55,6 +58,8 @@ class SentryProcessor:
|
|
|
55
58
|
:param active: A flag to make this processor enabled/disabled.
|
|
56
59
|
:param as_context: Send `event_dict` as extra info to Sentry.
|
|
57
60
|
Default is :obj:`True`.
|
|
61
|
+
:param ignore_breadcrumb_data: A list of data keys that will be excluded from
|
|
62
|
+
breadcrumb data. Defaults to keys which are already sent separately.
|
|
58
63
|
:param tag_keys: A list of keys. If any if these keys appear in `event_dict`,
|
|
59
64
|
the key and its corresponding value in `event_dict` will be used as Sentry
|
|
60
65
|
event tags. use `"__all__"` to report all key/value pairs of event as tags.
|
|
@@ -71,14 +76,17 @@ class SentryProcessor:
|
|
|
71
76
|
|
|
72
77
|
self._hub = hub
|
|
73
78
|
self._as_context = as_context
|
|
74
|
-
self._original_event_dict: dict =
|
|
79
|
+
self._original_event_dict: dict = {}
|
|
80
|
+
self.ignore_breadcrumb_data = ignore_breadcrumb_data
|
|
75
81
|
|
|
76
82
|
self._ignored_loggers: set[str] = set()
|
|
77
83
|
if ignore_loggers is not None:
|
|
78
84
|
self._ignored_loggers.update(set(ignore_loggers))
|
|
79
85
|
|
|
80
86
|
@staticmethod
|
|
81
|
-
def _get_logger_name(
|
|
87
|
+
def _get_logger_name(
|
|
88
|
+
logger: WrappedLogger, event_dict: MutableMapping[str, Any]
|
|
89
|
+
) -> Optional[str]:
|
|
82
90
|
"""Get logger name from event_dict with a fallbacks to logger.name and
|
|
83
91
|
record.name
|
|
84
92
|
|
|
@@ -111,16 +119,11 @@ class SentryProcessor:
|
|
|
111
119
|
has_exc_info = exc_info and exc_info != (None, None, None)
|
|
112
120
|
|
|
113
121
|
if has_exc_info:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
"include_local_variables", options.get("with_locals")
|
|
117
|
-
)
|
|
118
|
-
key = "with_locals" if _IS_OLD_VERSION else "include_local_variables"
|
|
122
|
+
client = self._get_hub().client
|
|
123
|
+
options: dict[str, Any] = client.options if client else {}
|
|
119
124
|
event, hint = event_from_exception(
|
|
120
125
|
exc_info,
|
|
121
|
-
client_options=
|
|
122
|
-
key: include_local_variables,
|
|
123
|
-
},
|
|
126
|
+
client_options=options,
|
|
124
127
|
)
|
|
125
128
|
else:
|
|
126
129
|
event, hint = {}, {}
|
|
@@ -142,13 +145,16 @@ class SentryProcessor:
|
|
|
142
145
|
return event, hint
|
|
143
146
|
|
|
144
147
|
def _get_breadcrumb_and_hint(self, event_dict: EventDict) -> tuple[dict, dict]:
|
|
148
|
+
data = {
|
|
149
|
+
k: v for k, v in event_dict.items() if k not in self.ignore_breadcrumb_data
|
|
150
|
+
}
|
|
145
151
|
event = {
|
|
146
152
|
"type": "log",
|
|
147
153
|
"level": event_dict.get("level"), # type: ignore
|
|
148
154
|
"category": event_dict.get("logger"),
|
|
149
155
|
"message": event_dict["event"],
|
|
150
156
|
"timestamp": event_dict.get("timestamp"),
|
|
151
|
-
"data":
|
|
157
|
+
"data": data,
|
|
152
158
|
}
|
|
153
159
|
|
|
154
160
|
return event, {"log_record": event_dict}
|
|
@@ -196,7 +202,7 @@ class SentryProcessor:
|
|
|
196
202
|
self, logger: WrappedLogger, name: str, event_dict: EventDict
|
|
197
203
|
) -> EventDict:
|
|
198
204
|
"""A middleware to process structlog `event_dict` and send it to Sentry."""
|
|
199
|
-
self._original_event_dict = event_dict
|
|
205
|
+
self._original_event_dict = dict(event_dict)
|
|
200
206
|
sentry_skip = event_dict.pop("sentry_skip", False)
|
|
201
207
|
|
|
202
208
|
if self.active and not sentry_skip and self._can_record(logger, event_dict):
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
[tox]
|
|
2
2
|
envlist =
|
|
3
3
|
lint
|
|
4
|
-
py{37,38,39,310}
|
|
4
|
+
py{37,38,39,310,311,312}
|
|
5
5
|
isolated_build = true
|
|
6
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
|
+
|
|
7
16
|
[testenv]
|
|
8
17
|
whitelist_externals = poetry
|
|
9
18
|
deps = poetry
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
repos:
|
|
2
|
-
- repo: https://github.com/psf/black
|
|
3
|
-
rev: 23.3.0
|
|
4
|
-
hooks:
|
|
5
|
-
- id: black
|
|
6
|
-
language_version: python3
|
|
7
|
-
|
|
8
|
-
- repo: https://github.com/pycqa/flake8
|
|
9
|
-
rev: 6.0.0
|
|
10
|
-
hooks:
|
|
11
|
-
- id: flake8
|
|
12
|
-
language_version: python3
|
|
13
|
-
|
|
14
|
-
- repo: https://github.com/pycqa/isort
|
|
15
|
-
rev: 5.12.0
|
|
16
|
-
hooks:
|
|
17
|
-
- id: isort
|
|
18
|
-
# extra dependencies for config in pyproject.toml
|
|
19
|
-
additional_dependencies: [".[pyproject]"]
|
|
20
|
-
|
|
21
|
-
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
22
|
-
rev: v4.4.0
|
|
23
|
-
hooks:
|
|
24
|
-
- id: trailing-whitespace
|
|
25
|
-
- id: end-of-file-fixer
|
|
26
|
-
- id: debug-statements
|
|
File without changes
|
|
File without changes
|
|
File without changes
|