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
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ jobs:
ci:
uses: community-of-python/community-workflow/.github/workflows/preset.yml@main
with:
python-version: '["3.10","3.11","3.12","3.13"]'
python-version: '["3.10","3.11","3.12","3.13", "3.14"]'
secrets: inherit
28 changes: 0 additions & 28 deletions docs/.vuepress/config.js

This file was deleted.

33 changes: 0 additions & 33 deletions docs/README.md

This file was deleted.

46 changes: 0 additions & 46 deletions docs/get-started.md

This file was deleted.

19 changes: 12 additions & 7 deletions microbootstrap/bootstrappers/faststream.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import typing_extensions
from faststream.asgi import AsgiFastStream, AsgiResponse
from faststream.asgi import get as handle_get
from faststream.specification import AsyncAPI

from microbootstrap.bootstrappers.base import ApplicationBootstrapper
from microbootstrap.config.faststream import FastStreamConfig
Expand Down Expand Up @@ -34,9 +35,11 @@ class FastStreamBootstrapper(ApplicationBootstrapper[FastStreamSettings, AsgiFas

def bootstrap_before(self: typing_extensions.Self) -> dict[str, typing.Any]:
return {
"title": self.settings.service_name,
"version": self.settings.service_version,
"description": self.settings.service_description,
"specification": AsyncAPI(
title=self.settings.service_name,
version=self.settings.service_version,
description=self.settings.service_description,
),
"on_shutdown": [self.teardown],
"on_startup": [self.console_writer.print_bootstrap_table],
"asyncapi_path": self.settings.asyncapi_path,
Expand All @@ -55,7 +58,7 @@ def is_ready(self) -> bool:
def bootstrap_after(self, application: AsgiFastStream) -> AsgiFastStream: # type: ignore[override]
if self.instrument_config.opentelemetry_middleware_cls and application.broker:
application.broker.add_middleware(
self.instrument_config.opentelemetry_middleware_cls(tracer_provider=self.tracer_provider)
self.instrument_config.opentelemetry_middleware_cls(tracer_provider=self.tracer_provider),
)
return application

Expand All @@ -82,13 +85,13 @@ def bootstrap_before(self) -> dict[str, typing.Any]:
self.instrument_config.prometheus_metrics_path,
prometheus_client.make_asgi_app(prometheus_client.REGISTRY),
),
)
),
}

def bootstrap_after(self, application: AsgiFastStream) -> AsgiFastStream: # type: ignore[override]
if self.instrument_config.prometheus_middleware_cls and application.broker:
application.broker.add_middleware(
self.instrument_config.prometheus_middleware_cls(registry=prometheus_client.REGISTRY)
self.instrument_config.prometheus_middleware_cls(registry=prometheus_client.REGISTRY),
)
return application

Expand All @@ -105,7 +108,9 @@ def bootstrap_before(self) -> dict[str, typing.Any]:
async def check_health(scope: typing.Any) -> AsgiResponse: # noqa: ANN401, ARG001
return (
AsgiResponse(
json.dumps(self.render_health_check_data()).encode(), 200, headers={"content-type": "text/plain"}
json.dumps(self.render_health_check_data()).encode(),
200,
headers={"content-type": "text/plain"},
)
if await self.define_health_status()
else AsgiResponse(b"Service is unhealthy", 500, headers={"content-type": "application/json"})
Expand Down
34 changes: 19 additions & 15 deletions microbootstrap/config/faststream.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@


if typing.TYPE_CHECKING:
import faststream.asyncapi.schema as asyncapi
from faststream.asgi.types import ASGIApp
from faststream.broker.core.usecase import BrokerUsecase
from faststream.types import AnyDict, AnyHttpUrl, Lifespan
from fast_depends import Provider
from fast_depends.library.serializer import SerializerProto
from faststream._internal.basic_types import (
AnyCallable,
Lifespan,
LoggerProto,
)
from faststream._internal.broker import BrokerUsecase
from faststream._internal.context import ContextRepo
from faststream.specification.base import SpecificationFactory


@dataclasses.dataclass
class FastStreamConfig:
broker: BrokerUsecase[typing.Any, typing.Any] | None = None
asgi_routes: typing.Sequence[tuple[str, ASGIApp]] = ()
logger: LoggerProto | None = None
provider: Provider | None = None
serializer: SerializerProto | None = None
context: ContextRepo | None = None
lifespan: Lifespan | None = None
terms_of_service: AnyHttpUrl | None = None
license: asyncapi.License | asyncapi.LicenseDict | AnyDict | None = None
contact: asyncapi.Contact | asyncapi.ContactDict | AnyDict | None = None
tags: typing.Sequence[asyncapi.Tag | asyncapi.TagDict | AnyDict] | None = None
external_docs: asyncapi.ExternalDocs | asyncapi.ExternalDocsDict | AnyDict | None = None
identifier: str | None = None
on_startup: typing.Sequence[typing.Callable[..., typing.Any]] = ()
after_startup: typing.Sequence[typing.Callable[..., typing.Any]] = ()
on_shutdown: typing.Sequence[typing.Callable[..., typing.Any]] = ()
after_shutdown: typing.Sequence[typing.Callable[..., typing.Any]] = ()
on_startup: typing.Sequence[AnyCallable] = ()
after_startup: typing.Sequence[AnyCallable] = ()
on_shutdown: typing.Sequence[AnyCallable] = ()
after_shutdown: typing.Sequence[AnyCallable] = ()
specification: SpecificationFactory | None = None
7 changes: 3 additions & 4 deletions microbootstrap/instruments/opentelemetry_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import pydantic
import structlog
from faststream._internal.types import BrokerMiddleware
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.instrumentation.dependencies import DependencyConflictError
from opentelemetry.instrumentation.environment_variables import OTEL_PYTHON_DISABLED_INSTRUMENTATIONS
Expand All @@ -31,7 +32,6 @@


if typing.TYPE_CHECKING:
import faststream
from opentelemetry.context import Context
from opentelemetry.metrics import Meter, MeterProvider
from opentelemetry.trace import TracerProvider
Expand Down Expand Up @@ -64,21 +64,20 @@ class OpentelemetryConfig(BaseInstrumentConfig):
default=[
one_package_to_exclude.strip()
for one_package_to_exclude in os.environ.get(OTEL_PYTHON_DISABLED_INSTRUMENTATIONS, "").split(",")
]
],
)
opentelemetry_log_traces: bool = False


@typing.runtime_checkable
class FastStreamTelemetryMiddlewareProtocol(typing.Protocol):
class FastStreamTelemetryMiddlewareProtocol(BrokerMiddleware, typing.Protocol):
def __init__(
self,
*,
tracer_provider: TracerProvider | None = None,
meter_provider: MeterProvider | None = None,
meter: Meter | None = None,
) -> None: ...
def __call__(self, msg: typing.Any | None) -> faststream.BaseMiddleware: ... # noqa: ANN401


class FastStreamOpentelemetryConfig(OpentelemetryConfig):
Expand Down
5 changes: 2 additions & 3 deletions microbootstrap/instruments/prometheus_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import typing

import pydantic
from faststream._internal.types import BrokerMiddleware

from microbootstrap.helpers import is_valid_path
from microbootstrap.instruments.base import BaseInstrumentConfig, Instrument


if typing.TYPE_CHECKING:
import faststream
import prometheus_client


Expand All @@ -33,7 +33,7 @@ class FastApiPrometheusConfig(BasePrometheusConfig):


@typing.runtime_checkable
class FastStreamPrometheusMiddlewareProtocol(typing.Protocol):
class FastStreamPrometheusMiddlewareProtocol(BrokerMiddleware, typing.Protocol):
def __init__(
self,
*,
Expand All @@ -42,7 +42,6 @@ def __init__(
metrics_prefix: str = "faststream",
received_messages_size_buckets: typing.Sequence[float] | None = None,
) -> None: ...
def __call__(self, msg: typing.Any | None) -> faststream.BaseMiddleware: ... # noqa: ANN401


class FastStreamPrometheusConfig(BasePrometheusConfig):
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
]
dependencies = [
"eval-type-backport>=0.2",
Expand Down