Skip to content

Commit 1f8da77

Browse files
authored
Fix OpenTelemetry & Prometheus without FastStream (#127)
* Fix OpenTelemetry & Prometheus without FastStream * Remove unnecessary type ignore comment for prometheus middleware assignment
1 parent 92c0047 commit 1f8da77

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

microbootstrap/instruments/opentelemetry_instrument.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import pydantic
88
import structlog
9-
from faststream._internal.types import BrokerMiddleware
109
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
1110
from opentelemetry.instrumentation.dependencies import DependencyConflictError
1211
from opentelemetry.instrumentation.environment_variables import OTEL_PYTHON_DISABLED_INSTRUMENTATIONS
@@ -70,7 +69,7 @@ class OpentelemetryConfig(BaseInstrumentConfig):
7069

7170

7271
@typing.runtime_checkable
73-
class FastStreamTelemetryMiddlewareProtocol(BrokerMiddleware, typing.Protocol):
72+
class FastStreamTelemetryMiddlewareProtocol(typing.Protocol):
7473
def __init__(
7574
self,
7675
*,
@@ -79,6 +78,14 @@ def __init__(
7978
meter: Meter | None = None,
8079
) -> None: ...
8180

81+
def __call__(
82+
self,
83+
msg: typing.Any, # noqa: ANN401
84+
/,
85+
*,
86+
context: typing.Any, # noqa: ANN401
87+
) -> typing.Any: ... # noqa: ANN401
88+
8289

8390
class FastStreamOpentelemetryConfig(OpentelemetryConfig):
8491
opentelemetry_middleware_cls: type[FastStreamTelemetryMiddlewareProtocol] | None = None

microbootstrap/instruments/prometheus_instrument.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import typing
33

44
import pydantic
5-
from faststream._internal.types import BrokerMiddleware
65

76
from microbootstrap.helpers import is_valid_path
87
from microbootstrap.instruments.base import BaseInstrumentConfig, Instrument
@@ -34,7 +33,7 @@ class FastApiPrometheusConfig(BasePrometheusConfig):
3433

3534

3635
@typing.runtime_checkable
37-
class FastStreamPrometheusMiddlewareProtocol(BrokerMiddleware, typing.Protocol):
36+
class FastStreamPrometheusMiddlewareProtocol(typing.Protocol):
3837
def __init__(
3938
self,
4039
*,
@@ -44,6 +43,13 @@ def __init__(
4443
received_messages_size_buckets: typing.Sequence[float] | None = None,
4544
custom_labels: dict[str, str | typing.Callable[[typing.Any], str]] | None = None,
4645
) -> None: ...
46+
def __call__(
47+
self,
48+
msg: typing.Any, # noqa: ANN401
49+
/,
50+
*,
51+
context: typing.Any, # noqa: ANN401
52+
) -> typing.Any: ... # noqa: ANN401
4753

4854

4955
class FastStreamPrometheusConfig(BasePrometheusConfig):

tests/instruments/test_prometheus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ async def test_faststream_prometheus_custom_labels(
145145
expected_label_keys: set[str],
146146
) -> None:
147147
minimal_faststream_prometheus_config.prometheus_custom_labels = custom_labels
148-
minimal_faststream_prometheus_config.prometheus_middleware_cls = RedisPrometheusMiddleware # type: ignore[assignment]
148+
minimal_faststream_prometheus_config.prometheus_middleware_cls = RedisPrometheusMiddleware
149149

150150
broker: typing.Final = RedisBroker()
151151
(

0 commit comments

Comments
 (0)