Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
([#3134](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3134))

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def response_hook(span, request_obj, response)
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
Expand Down Expand Up @@ -146,7 +146,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
Expand All @@ -164,7 +164,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)

Expand Down Expand Up @@ -345,7 +347,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(
Expand All @@ -361,7 +363,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
Expand All @@ -385,7 +387,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:
Expand Down Expand Up @@ -443,10 +445,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)
Loading