Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ __pycache__/*
.idea
.DS_Store
.env
.mypy_cache
.pytest_cache
.ruff_cache
.coverage
Expand Down
4 changes: 2 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ lint:
uv run eof-fixer .
uv run ruff format
uv run ruff check --fix
uv run mypy .
uv run ty check

lint-ci:
uv run eof-fixer . --check
uv run ruff format --check
uv run ruff check --no-fix
uv run mypy .
uv run ty check

test *args:
uv run --no-sync pytest {{ args }}
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Lite-Bootstrap
==
[![Test Coverage](https://codecov.io/gh/modern-python/lite-bootstrap/branch/main/graph/badge.svg)](https://codecov.io/gh/modern-python/lite-bootstrap)
[![MyPy Strict](https://img.shields.io/badge/mypy-strict-blue)](https://mypy.readthedocs.io/en/stable/getting_started.html#strict-mode-and-configuration)
[![Supported versions](https://img.shields.io/pypi/pyversions/lite-bootstrap.svg)](https://pypi.python.org/pypi/lite-bootstrap)
[![downloads](https://img.shields.io/pypi/dm/lite-bootstrap.svg)](https://pypistats.org/packages/lite-bootstrap)
[![GitHub stars](https://img.shields.io/github/stars/modern-python/lite-bootstrap)](https://github.com/modern-python/lite-bootstrap/stargazers)
Expand Down
2 changes: 1 addition & 1 deletion lite_bootstrap/bootstrappers/fastapi_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class FastApiCorsInstrument(CorsInstrument):

def bootstrap(self) -> None:
self.bootstrap_config.application.add_middleware(
CORSMiddleware,
CORSMiddleware, # ty: ignore[invalid-argument-type]
allow_origins=self.bootstrap_config.cors_allowed_origins,
allow_methods=self.bootstrap_config.cors_allowed_methods,
allow_headers=self.bootstrap_config.cors_allowed_headers,
Expand Down
8 changes: 4 additions & 4 deletions lite_bootstrap/bootstrappers/faststream_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(

@dataclasses.dataclass(kw_only=True, slots=True, frozen=True)
class FastStreamConfig(HealthChecksConfig, LoggingConfig, OpentelemetryConfig, PrometheusConfig, SentryConfig):
application: "AsgiFastStream" = dataclasses.field(default_factory=lambda: AsgiFastStream())
application: "AsgiFastStream" = dataclasses.field(default_factory=AsgiFastStream)
opentelemetry_middleware_cls: type[FastStreamTelemetryMiddlewareProtocol] | None = None
prometheus_middleware_cls: type[FastStreamPrometheusMiddlewareProtocol] | None = None

Expand Down Expand Up @@ -103,7 +103,7 @@ def bootstrap(self) -> None:
if self.bootstrap_config.opentelemetry_middleware_cls and self.bootstrap_config.application.broker:
self.bootstrap_config.opentelemetry_middleware_cls(tracer_provider=get_tracer_provider())
self.bootstrap_config.application.broker.add_middleware(
self.bootstrap_config.opentelemetry_middleware_cls(tracer_provider=get_tracer_provider()) # type: ignore[arg-type]
self.bootstrap_config.opentelemetry_middleware_cls(tracer_provider=get_tracer_provider())
)


Expand All @@ -116,7 +116,7 @@ class FastStreamSentryInstrument(SentryInstrument):
class FastStreamPrometheusInstrument(PrometheusInstrument):
bootstrap_config: FastStreamConfig
collector_registry: "prometheus_client.CollectorRegistry" = dataclasses.field(
default_factory=lambda: prometheus_client.CollectorRegistry(), init=False
default_factory=prometheus_client.CollectorRegistry, init=False
)
not_ready_message = PrometheusInstrument.not_ready_message + " or prometheus_middleware_cls is missing"
missing_dependency_message = "prometheus_client is not installed"
Expand All @@ -138,7 +138,7 @@ def bootstrap(self) -> None:
)
if self.bootstrap_config.prometheus_middleware_cls and self.bootstrap_config.application.broker:
self.bootstrap_config.application.broker.add_middleware(
self.bootstrap_config.prometheus_middleware_cls(registry=self.collector_registry) # type: ignore[arg-type]
self.bootstrap_config.prometheus_middleware_cls(registry=self.collector_registry)
)


Expand Down
2 changes: 1 addition & 1 deletion lite_bootstrap/bootstrappers/litestar_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class LitestarConfig(
SentryConfig,
SwaggerConfig,
):
application_config: "AppConfig" = dataclasses.field(default_factory=lambda: AppConfig())
application_config: "AppConfig" = dataclasses.field(default_factory=AppConfig)
opentelemetry_excluded_urls: list[str] = dataclasses.field(default_factory=list)
prometheus_additional_params: dict[str, typing.Any] = dataclasses.field(default_factory=dict)
swagger_extra_params: dict[str, typing.Any] = dataclasses.field(default_factory=dict)
Expand Down
2 changes: 1 addition & 1 deletion lite_bootstrap/instruments/opentelemetry_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


if typing.TYPE_CHECKING:
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor # type: ignore[attr-defined]
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor

if import_checker.is_opentelemetry_installed:
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
Expand Down
2 changes: 1 addition & 1 deletion lite_bootstrap/instruments/sentry_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def enrich_sentry_event_from_structlog_log(
return None

if event_name := loaded_formatted_log.get("event"):
event["logentry"]["formatted"] = event_name # type: ignore[index]
event["logentry"]["formatted"] = event_name
else:
return event

Expand Down
6 changes: 1 addition & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ dev = [
"redis>=5.2.1",
]
lint = [
"mypy",
"ty",
"ruff",
"eof-fixer",
]
Expand All @@ -136,10 +136,6 @@ build-backend = "uv_build"
module-name = "lite_bootstrap"
module-root = ""

[tool.mypy]
python_version = "3.10"
strict = true

[tool.ruff]
fix = false
unsafe-fixes = true
Expand Down
9 changes: 5 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

import pytest
import sentry_sdk
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor # type: ignore[attr-defined]
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from sentry_sdk.envelope import Envelope
from structlog.typing import EventDict, WrappedLogger

from lite_bootstrap import import_checker


class CustomInstrumentor(BaseInstrumentor): # type: ignore[misc]
class CustomInstrumentor(BaseInstrumentor):
def instrumentation_dependencies(self) -> typing.Collection[str]:
return []

Expand All @@ -22,9 +23,9 @@ def _uninstrument(self, **kwargs: typing.Mapping[str, typing.Any]) -> None:
class SentryTestTransport(sentry_sdk.Transport):
def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: # noqa: ANN401
super().__init__(*args, **kwargs)
self.mock_envelopes: list[sentry_sdk.envelope.Envelope] = []
self.mock_envelopes: list[Envelope] = []

def capture_envelope(self, envelope: sentry_sdk.envelope.Envelope) -> None:
def capture_envelope(self, envelope: Envelope) -> None:
self.mock_envelopes.append(envelope)


Expand Down
Loading