From ebce7ff0f1a6731fb4ece8b4a72379429cbdeb6c Mon Sep 17 00:00:00 2001 From: Lev Vereshchagin Date: Tue, 10 Mar 2026 16:11:07 +0300 Subject: [PATCH 1/3] Add type hints and silence OpenTelemetry logs --- .../instruments/opentelemetry_instrument.py | 14 ++++++++------ t.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 t.py diff --git a/microbootstrap/instruments/opentelemetry_instrument.py b/microbootstrap/instruments/opentelemetry_instrument.py index 962d1bd..c1fcae0 100644 --- a/microbootstrap/instruments/opentelemetry_instrument.py +++ b/microbootstrap/instruments/opentelemetry_instrument.py @@ -1,5 +1,6 @@ from __future__ import annotations import dataclasses +import logging import os import threading import typing @@ -35,7 +36,6 @@ from opentelemetry.metrics import Meter, MeterProvider from opentelemetry.trace import TracerProvider - OpentelemetryConfigT = typing.TypeVar("OpentelemetryConfigT", bound="OpentelemetryConfig") @@ -131,7 +131,9 @@ def teardown(self) -> None: instrumentor_with_params.instrumentor.uninstrument(**instrumentor_with_params.additional_params) def bootstrap(self) -> None: - attributes = { + logging.getLogger("opentelemetry.instrumentation.instrumentor").disabled = True + logging.getLogger("opentelemetry.trace").disabled = True + attributes: typing.Final = { ResourceAttributes.SERVICE_NAME: self.instrument_config.opentelemetry_service_name or self.instrument_config.service_name, ResourceAttributes.TELEMETRY_SDK_LANGUAGE: "python", @@ -169,7 +171,7 @@ def bootstrap(self) -> None: class OpentelemetryInstrument(BaseOpentelemetryInstrument[OpentelemetryConfig]): def define_exclude_urls(self) -> list[str]: - exclude_urls = [*self.instrument_config.opentelemetry_exclude_urls] + exclude_urls: typing.Final = [*self.instrument_config.opentelemetry_exclude_urls] if ( not self.instrument_config.opentelemetry_generate_health_check_spans and self.instrument_config.health_checks_path @@ -197,8 +199,8 @@ def _is_root_span(span: ReadableSpan) -> bool: class PyroscopeSpanProcessor(SpanProcessor): def on_start(self, span: Span, parent_context: Context | None = None) -> None: # noqa: ARG002 if _is_root_span(span): - formatted_span_id = format_span_id(span.context.span_id) - thread_id = threading.get_ident() + formatted_span_id: typing.Final = format_span_id(span.context.span_id) + thread_id: typing.Final = threading.get_ident() span.set_attribute(OTEL_PROFILE_ID_KEY, formatted_span_id) pyroscope.add_thread_tag(thread_id, PYROSCOPE_SPAN_ID_KEY, formatted_span_id) @@ -206,7 +208,7 @@ def on_start(self, span: Span, parent_context: Context | None = None) -> None: def on_end(self, span: ReadableSpan) -> None: if _is_root_span(span): - thread_id = threading.get_ident() + thread_id: typing.Final = threading.get_ident() pyroscope.remove_thread_tag(thread_id, PYROSCOPE_SPAN_ID_KEY, format_span_id(span.context.span_id)) pyroscope.remove_thread_tag(thread_id, PYROSCOPE_SPAN_NAME_KEY, span.name) diff --git a/t.py b/t.py new file mode 100644 index 0000000..b6bcc8d --- /dev/null +++ b/t.py @@ -0,0 +1,10 @@ +import typing + +from microbootstrap import LitestarSettings +from microbootstrap.bootstrappers.litestar import LitestarBootstrapper + + +def t(): + application: typing.Final = LitestarBootstrapper(LitestarSettings(opentelemetry_log_traces=True, service_debug=False)).bootstrap() +t() +t() From 96b734f8ccc5b5912304fb9a1c2136d3bfe7cc61 Mon Sep 17 00:00:00 2001 From: Lev Vereshchagin Date: Tue, 10 Mar 2026 16:11:18 +0300 Subject: [PATCH 2/3] Remove redundant test file t.py --- t.py | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 t.py diff --git a/t.py b/t.py deleted file mode 100644 index b6bcc8d..0000000 --- a/t.py +++ /dev/null @@ -1,10 +0,0 @@ -import typing - -from microbootstrap import LitestarSettings -from microbootstrap.bootstrappers.litestar import LitestarBootstrapper - - -def t(): - application: typing.Final = LitestarBootstrapper(LitestarSettings(opentelemetry_log_traces=True, service_debug=False)).bootstrap() -t() -t() From 85d7c849037ae4a77964f819ceef3c62b3970381 Mon Sep 17 00:00:00 2001 From: Lev Vereshchagin Date: Tue, 10 Mar 2026 16:19:06 +0300 Subject: [PATCH 3/3] Remove redundant type ignore comment --- microbootstrap/instruments/opentelemetry_instrument.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microbootstrap/instruments/opentelemetry_instrument.py b/microbootstrap/instruments/opentelemetry_instrument.py index c1fcae0..6a91309 100644 --- a/microbootstrap/instruments/opentelemetry_instrument.py +++ b/microbootstrap/instruments/opentelemetry_instrument.py @@ -101,7 +101,7 @@ class BaseOpentelemetryInstrument(Instrument[OpentelemetryConfigT]): ready_condition = "Provide all necessary config parameters" def _load_instrumentors(self) -> None: - for entry_point in entry_points(group="opentelemetry_instrumentor"): # type: ignore[no-untyped-call] + for entry_point in entry_points(group="opentelemetry_instrumentor"): if entry_point.name in self.instrument_config.opentelemetry_disabled_instrumentations: continue