Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 0 additions & 3 deletions scripts/populate_tox/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@
},
"statsig": {
"package": "statsig",
"deps": {
"*": ["typing_extensions"],
},
},
"strawberry": {
"package": "strawberry-graphql[fastapi,flask]",
Expand Down
289 changes: 146 additions & 143 deletions sentry_sdk/_types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
from typing import TYPE_CHECKING, TypeVar, Union
from datetime import datetime
from collections.abc import Container, MutableMapping, Sequence

from types import TracebackType
from typing import (
TYPE_CHECKING,
TypeVar,
Union,
Any,
Callable,
Dict,
Literal,
Mapping,
NotRequired,
Optional,
Type,
TypedDict,
)


# Re-exported for compat, since code out there in the wild might use this variable.
Expand Down Expand Up @@ -96,146 +113,147 @@ def substituted_because_contains_sensitive_data(cls):
T = TypeVar("T")
Annotated = Union[AnnotatedValue, T]

Hint = Dict[str, Any]
Log = TypedDict(
"Log",
{
"severity_text": str,
"severity_number": int,
"body": str,
"attributes": dict[str, str | bool | float | int],
"time_unix_nano": int,
"trace_id": Optional[str],
},
)

# "critical" is an alias of "fatal" recognized by Relay
LogLevelStr = Literal["fatal", "critical", "error", "warning", "info", "debug"]

EventDataCategory = Literal[
"default",
"error",
"crash",
"transaction",
"security",
"attachment",
"session",
"internal",
"profile",
"profile_chunk",
"monitor",
"span",
"log",
]

DurationUnit = Literal[
"nanosecond",
"microsecond",
"millisecond",
"second",
"minute",
"hour",
"day",
"week",
]

InformationUnit = Literal[
"bit",
"byte",
"kilobyte",
"kibibyte",
"megabyte",
"mebibyte",
"gigabyte",
"gibibyte",
"terabyte",
"tebibyte",
"petabyte",
"pebibyte",
"exabyte",
"exbibyte",
]

FractionUnit = Literal["ratio", "percent"]
MeasurementUnit = Union[DurationUnit, InformationUnit, FractionUnit, str]

MeasurementValue = TypedDict(
"MeasurementValue",
{
"value": float,
"unit": NotRequired[Optional[MeasurementUnit]],
},
)

Breadcrumb = Dict[str, Any]
BreadcrumbHint = Dict[str, Any]

SamplingContext = Dict[str, Any]

Event = TypedDict(
"Event",
{
"breadcrumbs": Annotated[
dict[Literal["values"], list[dict[str, Any]]]
], # TODO: We can expand on this type
"check_in_id": str,
"contexts": dict[str, dict[str, object]],
"dist": str,
"duration": Optional[float],
"environment": str,
"errors": list[dict[str, Any]], # TODO: We can expand on this type
"event_id": str,
"exception": dict[
Literal["values"], list[dict[str, Any]]
], # TODO: We can expand on this type
"extra": MutableMapping[str, object],
"fingerprint": list[str],
"level": LogLevelStr,
"logentry": Mapping[str, object],
"logger": str,
"measurements": dict[str, MeasurementValue],
"message": str,
"modules": dict[str, str],
"monitor_config": Mapping[str, object],
"monitor_slug": Optional[str],
"platform": Literal["python"],
"profile": object, # Should be sentry_sdk.profiler.Profile, but we can't import that here due to circular imports
"release": str,
"request": dict[str, object],
"sdk": Mapping[str, object],
"server_name": str,
"spans": Annotated[list[dict[str, object]]],
"stacktrace": dict[
str, object
], # We access this key in the code, but I am unsure whether we ever set it
"start_timestamp": datetime,
"status": Optional[str],
"tags": MutableMapping[str, str], # Tags must be less than 200 characters each
"threads": dict[
Literal["values"], list[dict[str, Any]]
], # TODO: We can expand on this type
"timestamp": Optional[datetime], # Must be set before sending the event
"transaction": str,
"transaction_info": Mapping[str, Any], # TODO: We can expand on this type
"type": Literal["check_in", "transaction"],
"user": dict[str, object],
"_dropped_spans": int,
},
total=False,
)

if TYPE_CHECKING:
from collections.abc import Container, MutableMapping, Sequence

from datetime import datetime

from types import TracebackType
from typing import Any
from typing import Callable
from typing import Dict
from typing import Mapping
from typing import NotRequired
from typing import Optional
from typing import Type
from typing_extensions import Literal, TypedDict
if TYPE_CHECKING:

class SDKInfo(TypedDict):
name: str
version: str
packages: Sequence[Mapping[str, str]]

# "critical" is an alias of "fatal" recognized by Relay
LogLevelStr = Literal["fatal", "critical", "error", "warning", "info", "debug"]

DurationUnit = Literal[
"nanosecond",
"microsecond",
"millisecond",
"second",
"minute",
"hour",
"day",
"week",
]

InformationUnit = Literal[
"bit",
"byte",
"kilobyte",
"kibibyte",
"megabyte",
"mebibyte",
"gigabyte",
"gibibyte",
"terabyte",
"tebibyte",
"petabyte",
"pebibyte",
"exabyte",
"exbibyte",
]

FractionUnit = Literal["ratio", "percent"]
MeasurementUnit = Union[DurationUnit, InformationUnit, FractionUnit, str]

MeasurementValue = TypedDict(
"MeasurementValue",
{
"value": float,
"unit": NotRequired[Optional[MeasurementUnit]],
},
)

Event = TypedDict(
"Event",
{
"breadcrumbs": Annotated[
dict[Literal["values"], list[dict[str, Any]]]
], # TODO: We can expand on this type
"check_in_id": str,
"contexts": dict[str, dict[str, object]],
"dist": str,
"duration": Optional[float],
"environment": str,
"errors": list[dict[str, Any]], # TODO: We can expand on this type
"event_id": str,
"exception": dict[
Literal["values"], list[dict[str, Any]]
], # TODO: We can expand on this type
"extra": MutableMapping[str, object],
"fingerprint": list[str],
"level": LogLevelStr,
"logentry": Mapping[str, object],
"logger": str,
"measurements": dict[str, MeasurementValue],
"message": str,
"modules": dict[str, str],
"monitor_config": Mapping[str, object],
"monitor_slug": Optional[str],
"platform": Literal["python"],
"profile": object, # Should be sentry_sdk.profiler.Profile, but we can't import that here due to circular imports
"release": str,
"request": dict[str, object],
"sdk": Mapping[str, object],
"server_name": str,
"spans": Annotated[list[dict[str, object]]],
"stacktrace": dict[
str, object
], # We access this key in the code, but I am unsure whether we ever set it
"start_timestamp": datetime,
"status": Optional[str],
"tags": MutableMapping[
str, str
], # Tags must be less than 200 characters each
"threads": dict[
Literal["values"], list[dict[str, Any]]
], # TODO: We can expand on this type
"timestamp": Optional[datetime], # Must be set before sending the event
"transaction": str,
"transaction_info": Mapping[str, Any], # TODO: We can expand on this type
"type": Literal["check_in", "transaction"],
"user": dict[str, object],
"_dropped_spans": int,
},
total=False,
)

ExcInfo = Union[
tuple[Type[BaseException], BaseException, Optional[TracebackType]],
tuple[None, None, None],
]

Hint = Dict[str, Any]
Log = TypedDict(
"Log",
{
"severity_text": str,
"severity_number": int,
"body": str,
"attributes": dict[str, str | bool | float | int],
"time_unix_nano": int,
"trace_id": Optional[str],
},
)

Breadcrumb = Dict[str, Any]
BreadcrumbHint = Dict[str, Any]

SamplingContext = Dict[str, Any]

EventProcessor = Callable[[Event, Hint], Optional[Event]]
ErrorProcessor = Callable[[Event, ExcInfo], Optional[Event]]
BreadcrumbProcessor = Callable[[Breadcrumb, BreadcrumbHint], Optional[Breadcrumb]]
Expand All @@ -247,21 +265,6 @@ class SDKInfo(TypedDict):
# https://github.com/python/mypy/issues/5710
NotImplementedType = Any

EventDataCategory = Literal[
"default",
"error",
"crash",
"transaction",
"security",
"attachment",
"session",
"internal",
"profile",
"profile_chunk",
"monitor",
"span",
"log",
]
SessionStatus = Literal["ok", "exited", "crashed", "abnormal"]

ContinuousProfilerMode = Literal["thread", "gevent", "unknown"]
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ class CompressionAlgo(Enum):
from typing import Optional
from typing import Callable
from typing import Union
from typing import Literal
from typing import List
from typing import Type
from typing import Dict
from typing import Any
from typing import Sequence
from typing import Tuple
from typing_extensions import Literal
from typing_extensions import TypedDict
from typing import TypedDict

from sentry_sdk._types import (
BreadcrumbProcessor,
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/_asgi_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
if TYPE_CHECKING:
from typing import Any
from typing import Dict
from typing import Literal
from typing import Optional
from typing import Union
from typing_extensions import Literal

from sentry_sdk.utils import AnnotatedValue

Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/profiler/continuous_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
from typing import Optional
from typing import Set
from typing import Type
from typing import TypedDict
from typing import Union
from typing_extensions import TypedDict

from sentry_sdk._types import ContinuousProfilerMode, SDKInfo
from sentry_sdk.profiler.utils import (
ExtractedSample,
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/profiler/transaction_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
from typing import Optional
from typing import Set
from typing import Type
from typing_extensions import TypedDict
from typing import TypedDict

from sentry_sdk.profiler.utils import (
ProcessedStack,
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/profiler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from typing import Optional
from typing import Sequence
from typing import Tuple
from typing_extensions import TypedDict
from typing import TypedDict

ThreadId = str

Expand Down
Loading
Loading