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
9 changes: 8 additions & 1 deletion lite_bootstrap/bootstrappers/fastapi_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,19 @@ class FastAPILoggingInstrument(LoggingInstrument):
class FastAPIOpenTelemetryInstrument(OpenTelemetryInstrument):
bootstrap_config: FastAPIConfig

def _build_excluded_urls(self) -> list[str]:
excluded_urls = [*self.bootstrap_config.opentelemetry_excluded_urls]
for one_url in (self.bootstrap_config.health_checks_path, self.bootstrap_config.prometheus_metrics_path):
if one_url and one_url not in excluded_urls:
excluded_urls.append(one_url)
return excluded_urls

def bootstrap(self) -> None:
super().bootstrap()
FastAPIInstrumentor.instrument_app(
app=self.bootstrap_config.application,
tracer_provider=get_tracer_provider(),
excluded_urls=",".join(self.bootstrap_config.opentelemetry_excluded_urls),
excluded_urls=",".join(self._build_excluded_urls()),
)

def teardown(self) -> None:
Expand Down
9 changes: 8 additions & 1 deletion lite_bootstrap/bootstrappers/litestar_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,19 @@ class LitestarLoggingInstrument(LoggingInstrument):
class LitestarOpenTelemetryInstrument(OpenTelemetryInstrument):
bootstrap_config: LitestarConfig

def _build_excluded_urls(self) -> list[str]:
excluded_urls = [*self.bootstrap_config.opentelemetry_excluded_urls]
for one_url in (self.bootstrap_config.health_checks_path, self.bootstrap_config.prometheus_metrics_path):
if one_url and one_url not in excluded_urls:
excluded_urls.append(one_url)
return excluded_urls

def bootstrap(self) -> None:
super().bootstrap()
self.bootstrap_config.application_config.middleware.append(
OpenTelemetryConfig(
tracer_provider=get_tracer_provider(),
exclude=self.bootstrap_config.opentelemetry_excluded_urls,
exclude=self._build_excluded_urls(),
).middleware,
)

Expand Down