Skip to content

Commit aa712ef

Browse files
committed
Support PEP 561 to opentelemetry-instrumentation-requests
1 parent 54cbf59 commit aa712ef

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
([#3100](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3100))
1818
- Add support to database stability opt-in in `_semconv` utilities and add tests
1919
([#3111](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3111))
20+
- `opentelemetry-opentelemetry-requests` Add `py.typed` file to enable PEP 561
21+
([#3134](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3134))
2022

2123
### Fixed
2224

instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def response_hook(span, request_obj, response)
7575
import functools
7676
import types
7777
from timeit import default_timer
78-
from typing import Callable, Collection, Optional
78+
from typing import Any, Callable, Collection, Optional
7979
from urllib.parse import urlparse
8080

8181
from requests.models import PreparedRequest, Response
@@ -146,7 +146,7 @@ def _instrument(
146146
duration_histogram_new: Histogram,
147147
request_hook: _RequestHookT = None,
148148
response_hook: _ResponseHookT = None,
149-
excluded_urls: ExcludeList = None,
149+
excluded_urls: ExcludeList | None = None,
150150
sem_conv_opt_in_mode: _StabilityMode = _StabilityMode.DEFAULT,
151151
):
152152
"""Enables tracing of all requests calls that go through
@@ -164,7 +164,9 @@ def _instrument(
164164

165165
# pylint: disable-msg=too-many-locals,too-many-branches
166166
@functools.wraps(wrapped_send)
167-
def instrumented_send(self, request, **kwargs):
167+
def instrumented_send(
168+
self: Session, request: PreparedRequest, **kwargs: Any
169+
):
168170
if excluded_urls and excluded_urls.url_disabled(request.url):
169171
return wrapped_send(self, request, **kwargs)
170172

@@ -345,7 +347,7 @@ def _uninstrument():
345347
_uninstrument_from(Session)
346348

347349

348-
def _uninstrument_from(instr_root, restore_as_bound_func=False):
350+
def _uninstrument_from(instr_root, restore_as_bound_func: bool = False):
349351
for instr_func_name in ("request", "send"):
350352
instr_func = getattr(instr_root, instr_func_name)
351353
if not getattr(
@@ -361,7 +363,7 @@ def _uninstrument_from(instr_root, restore_as_bound_func=False):
361363
setattr(instr_root, instr_func_name, original)
362364

363365

364-
def get_default_span_name(method):
366+
def get_default_span_name(method: str) -> str:
365367
"""
366368
Default implementation for name_callback, returns HTTP {method_name}.
367369
https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/http/#name
@@ -385,7 +387,7 @@ class RequestsInstrumentor(BaseInstrumentor):
385387
def instrumentation_dependencies(self) -> Collection[str]:
386388
return _instruments
387389

388-
def _instrument(self, **kwargs):
390+
def _instrument(self, **kwargs: Any):
389391
"""Instruments requests module
390392
391393
Args:
@@ -443,10 +445,10 @@ def _instrument(self, **kwargs):
443445
sem_conv_opt_in_mode=semconv_opt_in_mode,
444446
)
445447

446-
def _uninstrument(self, **kwargs):
448+
def _uninstrument(self, **kwargs: Any):
447449
_uninstrument()
448450

449451
@staticmethod
450-
def uninstrument_session(session):
452+
def uninstrument_session(session: Session):
451453
"""Disables instrumentation on the session object."""
452454
_uninstrument_from(session, restore_as_bound_func=True)

instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/py.typed

Whitespace-only changes.

0 commit comments

Comments
 (0)