diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a35e342df..3c35391e8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3100](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3100)) - Add support to database stability opt-in in `_semconv` utilities and add tests ([#3111](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3111)) +- `opentelemetry-opentelemetry-requests` Add `py.typed` file to enable PEP 561 + ([#3135](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3135)) - `opentelemetry-instrumentation-system-metrics` Add `py.typed` file to enable PEP 561 ([#3132](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3132)) - `opentelemetry-opentelemetry-sqlite3` Add `py.typed` file to enable PEP 561 diff --git a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py index d1afa834d6..6c197d530e 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py @@ -72,10 +72,12 @@ def response_hook(span, request_obj, response) --- """ +from __future__ import annotations + import functools import types from timeit import default_timer -from typing import Callable, Collection, Optional +from typing import Any, Callable, Collection, Optional from urllib.parse import urlparse from requests.models import PreparedRequest, Response @@ -146,7 +148,7 @@ def _instrument( duration_histogram_new: Histogram, request_hook: _RequestHookT = None, response_hook: _ResponseHookT = None, - excluded_urls: ExcludeList = None, + excluded_urls: ExcludeList | None = None, sem_conv_opt_in_mode: _StabilityMode = _StabilityMode.DEFAULT, ): """Enables tracing of all requests calls that go through @@ -164,7 +166,9 @@ def _instrument( # pylint: disable-msg=too-many-locals,too-many-branches @functools.wraps(wrapped_send) - def instrumented_send(self, request, **kwargs): + def instrumented_send( + self: Session, request: PreparedRequest, **kwargs: Any + ): if excluded_urls and excluded_urls.url_disabled(request.url): return wrapped_send(self, request, **kwargs) @@ -345,7 +349,7 @@ def _uninstrument(): _uninstrument_from(Session) -def _uninstrument_from(instr_root, restore_as_bound_func=False): +def _uninstrument_from(instr_root, restore_as_bound_func: bool = False): for instr_func_name in ("request", "send"): instr_func = getattr(instr_root, instr_func_name) if not getattr( @@ -361,7 +365,7 @@ def _uninstrument_from(instr_root, restore_as_bound_func=False): setattr(instr_root, instr_func_name, original) -def get_default_span_name(method): +def get_default_span_name(method: str) -> str: """ Default implementation for name_callback, returns HTTP {method_name}. https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/http/#name @@ -385,7 +389,7 @@ class RequestsInstrumentor(BaseInstrumentor): def instrumentation_dependencies(self) -> Collection[str]: return _instruments - def _instrument(self, **kwargs): + def _instrument(self, **kwargs: Any): """Instruments requests module Args: @@ -443,10 +447,10 @@ def _instrument(self, **kwargs): sem_conv_opt_in_mode=semconv_opt_in_mode, ) - def _uninstrument(self, **kwargs): + def _uninstrument(self, **kwargs: Any): _uninstrument() @staticmethod - def uninstrument_session(session): + def uninstrument_session(session: Session): """Disables instrumentation on the session object.""" _uninstrument_from(session, restore_as_bound_func=True) diff --git a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/py.typed b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/py.typed new file mode 100644 index 0000000000..e69de29bb2