|
1 | 1 | from __future__ import annotations |
2 | 2 | import dataclasses |
| 3 | +import logging |
3 | 4 | import os |
4 | 5 | import threading |
5 | 6 | import typing |
|
35 | 36 | from opentelemetry.metrics import Meter, MeterProvider |
36 | 37 | from opentelemetry.trace import TracerProvider |
37 | 38 |
|
38 | | - |
39 | 39 | OpentelemetryConfigT = typing.TypeVar("OpentelemetryConfigT", bound="OpentelemetryConfig") |
40 | 40 |
|
41 | 41 |
|
@@ -101,7 +101,7 @@ class BaseOpentelemetryInstrument(Instrument[OpentelemetryConfigT]): |
101 | 101 | ready_condition = "Provide all necessary config parameters" |
102 | 102 |
|
103 | 103 | def _load_instrumentors(self) -> None: |
104 | | - for entry_point in entry_points(group="opentelemetry_instrumentor"): # type: ignore[no-untyped-call] |
| 104 | + for entry_point in entry_points(group="opentelemetry_instrumentor"): |
105 | 105 | if entry_point.name in self.instrument_config.opentelemetry_disabled_instrumentations: |
106 | 106 | continue |
107 | 107 |
|
@@ -131,7 +131,9 @@ def teardown(self) -> None: |
131 | 131 | instrumentor_with_params.instrumentor.uninstrument(**instrumentor_with_params.additional_params) |
132 | 132 |
|
133 | 133 | def bootstrap(self) -> None: |
134 | | - attributes = { |
| 134 | + logging.getLogger("opentelemetry.instrumentation.instrumentor").disabled = True |
| 135 | + logging.getLogger("opentelemetry.trace").disabled = True |
| 136 | + attributes: typing.Final = { |
135 | 137 | ResourceAttributes.SERVICE_NAME: self.instrument_config.opentelemetry_service_name |
136 | 138 | or self.instrument_config.service_name, |
137 | 139 | ResourceAttributes.TELEMETRY_SDK_LANGUAGE: "python", |
@@ -169,7 +171,7 @@ def bootstrap(self) -> None: |
169 | 171 |
|
170 | 172 | class OpentelemetryInstrument(BaseOpentelemetryInstrument[OpentelemetryConfig]): |
171 | 173 | def define_exclude_urls(self) -> list[str]: |
172 | | - exclude_urls = [*self.instrument_config.opentelemetry_exclude_urls] |
| 174 | + exclude_urls: typing.Final = [*self.instrument_config.opentelemetry_exclude_urls] |
173 | 175 | if ( |
174 | 176 | not self.instrument_config.opentelemetry_generate_health_check_spans |
175 | 177 | and self.instrument_config.health_checks_path |
@@ -197,16 +199,16 @@ def _is_root_span(span: ReadableSpan) -> bool: |
197 | 199 | class PyroscopeSpanProcessor(SpanProcessor): |
198 | 200 | def on_start(self, span: Span, parent_context: Context | None = None) -> None: # noqa: ARG002 |
199 | 201 | if _is_root_span(span): |
200 | | - formatted_span_id = format_span_id(span.context.span_id) |
201 | | - thread_id = threading.get_ident() |
| 202 | + formatted_span_id: typing.Final = format_span_id(span.context.span_id) |
| 203 | + thread_id: typing.Final = threading.get_ident() |
202 | 204 |
|
203 | 205 | span.set_attribute(OTEL_PROFILE_ID_KEY, formatted_span_id) |
204 | 206 | pyroscope.add_thread_tag(thread_id, PYROSCOPE_SPAN_ID_KEY, formatted_span_id) |
205 | 207 | pyroscope.add_thread_tag(thread_id, PYROSCOPE_SPAN_NAME_KEY, span.name) |
206 | 208 |
|
207 | 209 | def on_end(self, span: ReadableSpan) -> None: |
208 | 210 | if _is_root_span(span): |
209 | | - thread_id = threading.get_ident() |
| 211 | + thread_id: typing.Final = threading.get_ident() |
210 | 212 | pyroscope.remove_thread_tag(thread_id, PYROSCOPE_SPAN_ID_KEY, format_span_id(span.context.span_id)) |
211 | 213 | pyroscope.remove_thread_tag(thread_id, PYROSCOPE_SPAN_NAME_KEY, span.name) |
212 | 214 |
|
|
0 commit comments