Skip to content
Merged
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
6 changes: 6 additions & 0 deletions sentry_sdk/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@


if MYPY:
from numbers import Real
from types import TracebackType
from typing import Any
from typing import Callable
from typing import Dict
from typing import Optional
from typing import Tuple
from typing import Type
from typing import Union
from typing_extensions import Literal

ExcInfo = Tuple[
Expand All @@ -24,10 +26,14 @@
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]]

TracesSampler = Callable[[SamplingContext], Union[Real, bool]]

# https://github.com/python/mypy/issues/5710
NotImplementedType = Any

Expand Down
8 changes: 7 additions & 1 deletion sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
from sentry_sdk.transport import Transport
from sentry_sdk.integrations import Integration

from sentry_sdk._types import Event, EventProcessor, BreadcrumbProcessor
from sentry_sdk._types import (
BreadcrumbProcessor,
Event,
EventProcessor,
TracesSampler,
)

# Experiments are feature flags to enable and disable certain unstable SDK
# functionality. Changing them from the defaults (`None`) in production
Expand Down Expand Up @@ -63,6 +68,7 @@ def __init__(
ca_certs=None, # type: Optional[str]
propagate_traces=True, # type: bool
traces_sample_rate=0.0, # type: float
traces_sampler=None, # type: Optional[TracesSampler]
auto_enabling_integrations=True, # type: bool
_experiments={}, # type: Experiments # noqa: B006
):
Expand Down
4 changes: 3 additions & 1 deletion sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,12 @@ def get_trace_context(self):


class Transaction(Span):
__slots__ = ("name",)
__slots__ = ("name", "parent_sampled")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to store this value in every transaction?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there's no other way (that I can see) to get it to the traces_sampler. The only link between from_traceparent and start_transaction is the Transaction object itself.

It's true that once it's been used, I could delete it off of the transaction object, but is that necessary/worth it?


def __init__(
self,
name="", # type: str
parent_sampled=None, # type: Optional[bool]
**kwargs # type: Any
):
# type: (...) -> None
Expand All @@ -468,6 +469,7 @@ def __init__(
name = kwargs.pop("transaction")
Span.__init__(self, **kwargs)
self.name = name
self.parent_sampled = parent_sampled

def __repr__(self):
# type: () -> str
Expand Down