Skip to content

Commit 9d101c1

Browse files
committed
Add cross-instrument parameter for health checks span generation
1 parent 94aacd6 commit 9d101c1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

microbootstrap/bootstrappers/faststream.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ def get_config_type(cls) -> type[FastStreamPrometheusConfig]:
111111
class FastStreamHealthChecksInstrument(HealthChecksInstrument):
112112
def bootstrap(self) -> None: ...
113113
def bootstrap_before(self) -> dict[str, typing.Any]:
114-
@tracer.start_as_current_span(f"GET {self.instrument_config.health_checks_path}")
115114
@handle_get
116115
async def check_health(scope: typing.Any) -> AsgiResponse: # noqa: ANN401, ARG001
117116
return (
@@ -124,6 +123,11 @@ async def check_health(scope: typing.Any) -> AsgiResponse: # noqa: ANN401, ARG0
124123
else AsgiResponse(b"Service is unhealthy", 500, headers={"content-type": "application/json"})
125124
)
126125

126+
if self.instrument_config.opentelemetry_generate_health_check_spans:
127+
check_health = tracer.start_as_current_span(f"GET {self.instrument_config.health_checks_path}")(
128+
check_health,
129+
)
130+
127131
return {"asgi_routes": ((self.instrument_config.health_checks_path, check_health),)}
128132

129133
async def define_health_status(self) -> bool:

microbootstrap/instruments/health_checks_instrument.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class HealthChecksConfig(BaseInstrumentConfig):
1919
health_checks_path: str = "/health/"
2020
health_checks_include_in_schema: bool = False
2121

22+
# Cross-instrument parameter, comes from opentelemetry
23+
opentelemetry_generate_health_check_spans: bool = True
24+
2225

2326
class HealthChecksInstrument(Instrument[HealthChecksConfig]):
2427
instrument_name = "Health checks"

0 commit comments

Comments
 (0)