diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9368812..ed92ac4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,4 +27,4 @@ jobs: key: ${{ runner.os }}-${{ hashFiles('poetry.lock') }} strategy: matrix: - toxenv: [py37, py38, py39, py310] + toxenv: [py37, py38, py39, py310, py311, py312] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d24e855..9b7c6bb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,31 +1,23 @@ repos: - - repo: https://github.com/psf/black - rev: 23.3.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.2 hooks: - - id: black - language_version: python3 + - id: ruff-format - - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.2 hooks: - - id: flake8 - language_version: python3 - - - repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - # extra dependencies for config in pyproject.toml - additional_dependencies: [".[pyproject]"] + - id: ruff + args: ["--fix", "--exit-non-zero-on-fix", "--config", "pyproject.toml"] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: debug-statements - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.4.0 + rev: v1.9.0 hooks: - id: mypy diff --git a/structlog_sentry/__init__.py b/structlog_sentry/__init__.py index 925ea81..02a68a1 100644 --- a/structlog_sentry/__init__.py +++ b/structlog_sentry/__init__.py @@ -3,7 +3,8 @@ import logging import sys from fnmatch import fnmatch -from typing import Any, Iterable, Optional +from typing import Any, Optional +from collections.abc import MutableMapping, Iterable from sentry_sdk import Hub from sentry_sdk.integrations.logging import _IGNORED_LOGGERS @@ -83,7 +84,9 @@ def __init__( self._ignored_loggers.update(set(ignore_loggers)) @staticmethod - def _get_logger_name(logger: WrappedLogger, event_dict: dict) -> Optional[str]: + def _get_logger_name( + logger: WrappedLogger, event_dict: MutableMapping[str, Any] + ) -> Optional[str]: """Get logger name from event_dict with a fallbacks to logger.name and record.name @@ -116,9 +119,11 @@ def _get_event_and_hint(self, event_dict: EventDict) -> tuple[dict, dict]: has_exc_info = exc_info and exc_info != (None, None, None) if has_exc_info: + client = self._get_hub().client + options: dict[str, Any] = client.options if client else {} event, hint = event_from_exception( exc_info, - client_options=self._get_hub().client.options, + client_options=options, ) else: event, hint = {}, {} @@ -197,7 +202,7 @@ def __call__( self, logger: WrappedLogger, name: str, event_dict: EventDict ) -> EventDict: """A middleware to process structlog `event_dict` and send it to Sentry.""" - self._original_event_dict = event_dict.copy() + self._original_event_dict = dict(event_dict) sentry_skip = event_dict.pop("sentry_skip", False) if self.active and not sentry_skip and self._can_record(logger, event_dict): diff --git a/tox.ini b/tox.ini index f699dc8..edaa251 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] envlist = lint - py{37,38,39,310} + py{37,38,39,310,311,312} isolated_build = true [testenv]