Skip to content

ref(api): Improve sentry_sdk.trace type hints #2633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 16, 2024
Merged
Changes from all commits
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
22 changes: 21 additions & 1 deletion sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@
if TYPE_CHECKING:
import typing

from collections.abc import Callable
from typing import Any
from typing import Dict
from typing import Iterator
from typing import List
from typing import Optional
from typing import overload
from typing import ParamSpec
from typing import Tuple
from typing import Union
from typing import TypeVar

P = ParamSpec("P")
R = TypeVar("R")

import sentry_sdk.profiler
from sentry_sdk._types import Event, MeasurementUnit, SamplingContext
Expand Down Expand Up @@ -983,8 +990,21 @@ def _set_initial_sampling_decision(self, sampling_context):
pass


if TYPE_CHECKING:

@overload
def trace(func=None):
# type: (None) -> Callable[[Callable[P, R]], Callable[P, R]]
pass

@overload
def trace(func):
# type: (Callable[P, R]) -> Callable[P, R]
pass


def trace(func=None):
# type: (Any) -> Any
# type: (Optional[Callable[P, R]]) -> Union[Callable[P, R], Callable[[Callable[P, R]], Callable[P, R]]]
"""
Decorator to start a child span under the existing current transaction.
If there is no current transaction, then nothing will be traced.
Expand Down