Skip to content

Commit

Permalink
Merge pull request #72 from community-of-python/71-add-sentry-tags
Browse files Browse the repository at this point in the history
add sentry_tags
  • Loading branch information
lesnik512 authored Feb 7, 2025
2 parents b4c32f7 + 1a086a1 commit ba551ca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ class YourSettings(BaseServiceSettings):
sentry_attach_stacktrace: bool = True
sentry_integrations: list[Integration] = []
sentry_additional_params: dict[str, typing.Any] = {}
sentry_tags: dict[str, str] | None = None

... # Other settings here
```
Expand Down
6 changes: 6 additions & 0 deletions microbootstrap/instruments/sentry_instrument.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations
import contextlib
import typing

import pydantic
Expand All @@ -19,6 +20,7 @@ class SentryConfig(BaseInstrumentConfig):
sentry_attach_stacktrace: bool = True
sentry_integrations: list[Integration] = pydantic.Field(default_factory=list)
sentry_additional_params: dict[str, typing.Any] = pydantic.Field(default_factory=dict)
sentry_tags: dict[str, str] | None = None


class SentryInstrument(Instrument[SentryConfig]):
Expand All @@ -40,6 +42,10 @@ def bootstrap(self) -> None:
integrations=self.instrument_config.sentry_integrations,
**self.instrument_config.sentry_additional_params,
)
if self.instrument_config.sentry_tags:
# for sentry<2.1.0
with contextlib.suppress(AttributeError):
sentry_sdk.set_tags(self.instrument_config.sentry_tags)

@classmethod
def get_config_type(cls) -> type[SentryConfig]:
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def default_litestar_app() -> litestar.Litestar:

@pytest.fixture
def minimal_sentry_config() -> SentryConfig:
return SentryConfig(sentry_dsn="https://[email protected]/0")
return SentryConfig(sentry_dsn="https://[email protected]/0", sentry_tags={"test": "test"})


@pytest.fixture
Expand Down

0 comments on commit ba551ca

Please sign in to comment.