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
11 changes: 9 additions & 2 deletions microbootstrap/instruments/opentelemetry_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

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 Down Expand Up @@ -70,7 +69,7 @@ class OpentelemetryConfig(BaseInstrumentConfig):


@typing.runtime_checkable
class FastStreamTelemetryMiddlewareProtocol(BrokerMiddleware, typing.Protocol):
class FastStreamTelemetryMiddlewareProtocol(typing.Protocol):
def __init__(
self,
*,
Expand All @@ -79,6 +78,14 @@ def __init__(
meter: Meter | None = None,
) -> None: ...

def __call__(
self,
msg: typing.Any, # noqa: ANN401
/,
*,
context: typing.Any, # noqa: ANN401
) -> typing.Any: ... # noqa: ANN401


class FastStreamOpentelemetryConfig(OpentelemetryConfig):
opentelemetry_middleware_cls: type[FastStreamTelemetryMiddlewareProtocol] | None = None
Expand Down
10 changes: 8 additions & 2 deletions microbootstrap/instruments/prometheus_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import typing

import pydantic
from faststream._internal.types import BrokerMiddleware

from microbootstrap.helpers import is_valid_path
from microbootstrap.instruments.base import BaseInstrumentConfig, Instrument
Expand Down Expand Up @@ -34,7 +33,7 @@ class FastApiPrometheusConfig(BasePrometheusConfig):


@typing.runtime_checkable
class FastStreamPrometheusMiddlewareProtocol(BrokerMiddleware, typing.Protocol):
class FastStreamPrometheusMiddlewareProtocol(typing.Protocol):
def __init__(
self,
*,
Expand All @@ -44,6 +43,13 @@ def __init__(
received_messages_size_buckets: typing.Sequence[float] | None = None,
custom_labels: dict[str, str | typing.Callable[[typing.Any], str]] | None = None,
) -> None: ...
def __call__(
self,
msg: typing.Any, # noqa: ANN401
/,
*,
context: typing.Any, # noqa: ANN401
) -> typing.Any: ... # noqa: ANN401


class FastStreamPrometheusConfig(BasePrometheusConfig):
Expand Down
2 changes: 1 addition & 1 deletion tests/instruments/test_prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ async def test_faststream_prometheus_custom_labels(
expected_label_keys: set[str],
) -> None:
minimal_faststream_prometheus_config.prometheus_custom_labels = custom_labels
minimal_faststream_prometheus_config.prometheus_middleware_cls = RedisPrometheusMiddleware # type: ignore[assignment]
minimal_faststream_prometheus_config.prometheus_middleware_cls = RedisPrometheusMiddleware

broker: typing.Final = RedisBroker()
(
Expand Down