Skip to content

Commit 3a28405

Browse files
authored
add health check path to OTL exclude (#84)
1 parent 92b3804 commit 3a28405

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

microbootstrap/bootstrappers/fastapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def bootstrap_after(self, application: ApplicationT) -> ApplicationT:
9191
FastAPIInstrumentor.instrument_app(
9292
application,
9393
tracer_provider=self.tracer_provider,
94-
excluded_urls=",".join(self.instrument_config.opentelemetry_exclude_urls),
94+
excluded_urls=",".join(self.define_exclude_urls()),
9595
)
9696
return application
9797

microbootstrap/bootstrappers/litestar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def bootstrap_before(self) -> dict[str, typing.Any]:
109109
"middleware": [
110110
LitestarOpentelemetryConfig(
111111
tracer_provider=self.tracer_provider,
112-
exclude=self.instrument_config.opentelemetry_exclude_urls,
112+
exclude=self.define_exclude_urls(),
113113
).middleware,
114114
],
115115
}

microbootstrap/instruments/opentelemetry_instrument.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class OpenTelemetryInstrumentor:
3030
class OpentelemetryConfig(BaseInstrumentConfig):
3131
service_name: str = "micro-service"
3232
service_version: str = "1.0.0"
33+
health_checks_path: str = "/health/"
3334

3435
opentelemetry_service_name: str | None = None
3536
opentelemetry_container_name: str | None = None
@@ -104,6 +105,12 @@ def bootstrap(self) -> None:
104105

105106

106107
class OpentelemetryInstrument(BaseOpentelemetryInstrument[OpentelemetryConfig]):
108+
def define_exclude_urls(self) -> list[str]:
109+
exclude_urls = [*self.instrument_config.opentelemetry_exclude_urls]
110+
if self.instrument_config.health_checks_path and self.instrument_config.health_checks_path not in exclude_urls:
111+
exclude_urls.append(self.instrument_config.health_checks_path)
112+
return exclude_urls
113+
107114
@classmethod
108115
def get_config_type(cls) -> type[OpentelemetryConfig]:
109116
return OpentelemetryConfig

0 commit comments

Comments
 (0)