Skip to content

ref: Move consts, utils from integrations/opentelemetry/ #4272

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 29 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4b3284c
ref: Move sampler out of integrations/opentelemetry
sentrivana Apr 9, 2025
7741c64
ref: Move span processor out from integrations
sentrivana Apr 9, 2025
cf28b7b
ref: Move propagator out of integrations
sentrivana Apr 9, 2025
f34b066
forgot one
sentrivana Apr 9, 2025
841bd02
move to opentelemetry
sentrivana Apr 10, 2025
38f6886
Merge branch 'potel-base' into ivana/move-sampler-from-integration
sentrivana Apr 10, 2025
2a554c3
move to opentelemetry/
sentrivana Apr 10, 2025
5d6e318
alphabet
sentrivana Apr 10, 2025
89ae39e
move to opentelemetry/
sentrivana Apr 10, 2025
8819373
fix setup.py
sentrivana Apr 10, 2025
3f02f56
Merge branch 'potel-base' into ivana/potel/move-span-processor-out-of…
sentrivana Apr 10, 2025
db2f1b6
formatting
sentrivana Apr 10, 2025
38b051e
Merge branch 'ivana/potel/move-span-processor-out-of-integration' int…
sentrivana Apr 10, 2025
5d9dc58
ref: Move contextvars_context out of integrations
sentrivana Apr 10, 2025
5e26e54
remove comment
sentrivana Apr 10, 2025
c29719c
ref: Move utils, consts out of integrations/opentelemetry/
sentrivana Apr 10, 2025
ea89a5a
get rid of circ deps
sentrivana Apr 10, 2025
1c93520
fix test
sentrivana Apr 10, 2025
67d3117
.
sentrivana Apr 10, 2025
33709ef
.
sentrivana Apr 10, 2025
3c52872
make apidocs happy
sentrivana Apr 10, 2025
b10193d
Merge branch 'potel-base' into ivana/potel/move-span-processor-out-of…
sentrivana Apr 10, 2025
5b3376d
Merge branch 'ivana/potel/move-span-processor-out-of-integration' int…
sentrivana Apr 10, 2025
d16e026
Merge branch 'ivana/potel/move-propagator' into ivana/potel/move-cont…
sentrivana Apr 10, 2025
94ba998
Merge branch 'ivana/potel/move-context-sync' into ivana/potel/move-mo…
sentrivana Apr 10, 2025
0dcf1f3
Merge branch 'potel-base' into ivana/potel/move-more-otel-stuff
sentrivana Apr 10, 2025
7adcd1b
fix import
sentrivana Apr 10, 2025
586e3f5
Merge branch 'potel-base' into ivana/potel/move-more-otel-stuff
sentrivana Apr 14, 2025
a209812
Merge branch 'potel-base' into ivana/potel/move-more-otel-stuff
sentrivana Apr 14, 2025
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
5 changes: 2 additions & 3 deletions sentry_sdk/_init_implementation.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from typing import TYPE_CHECKING

import sentry_sdk
from sentry_sdk.consts import ClientConstructor
from sentry_sdk.integrations.opentelemetry.scope import setup_scope_context_management

if TYPE_CHECKING:
from typing import Any, Optional

import sentry_sdk.consts


def _check_python_deprecations():
# type: () -> None
Expand Down Expand Up @@ -36,7 +35,7 @@ def _init(*args, **kwargs):
# Use `ClientConstructor` to define the argument types of `init` and
# `ContextManager[Any]` to tell static analyzers about the return type.

class init(sentry_sdk.consts.ClientConstructor): # noqa: N801
class init(ClientConstructor): # noqa: N801
pass

else:
Expand Down
38 changes: 14 additions & 24 deletions sentry_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,7 @@
from typing import Union
from typing import Generator

from sentry_sdk.client import BaseClient
from sentry_sdk._types import (
Event,
Hint,
Breadcrumb,
BreadcrumbHint,
ExcInfo,
MeasurementUnit,
LogLevelStr,
)
from sentry_sdk.tracing import Span
import sentry_sdk

T = TypeVar("T")
F = TypeVar("F", bound=Callable[..., Any])
Expand Down Expand Up @@ -102,7 +92,7 @@ def clientmethod(f):

@scopemethod
def get_client():
# type: () -> BaseClient
# type: () -> sentry_sdk.client.BaseClient
return Scope.get_client()


Expand Down Expand Up @@ -150,8 +140,8 @@ def last_event_id():

@scopemethod
def capture_event(
event, # type: Event
hint=None, # type: Optional[Hint]
event, # type: sentry_sdk._types.Event
hint=None, # type: Optional[sentry_sdk._types.Hint]
scope=None, # type: Optional[Any]
**scope_kwargs, # type: Any
):
Expand All @@ -162,7 +152,7 @@ def capture_event(
@scopemethod
def capture_message(
message, # type: str
level=None, # type: Optional[LogLevelStr]
level=None, # type: Optional[sentry_sdk._types.LogLevelStr]
scope=None, # type: Optional[Any]
**scope_kwargs, # type: Any
):
Expand All @@ -174,7 +164,7 @@ def capture_message(

@scopemethod
def capture_exception(
error=None, # type: Optional[Union[BaseException, ExcInfo]]
error=None, # type: Optional[Union[BaseException, sentry_sdk._types.ExcInfo]]
scope=None, # type: Optional[Any]
**scope_kwargs, # type: Any
):
Expand All @@ -184,8 +174,8 @@ def capture_exception(

@scopemethod
def add_breadcrumb(
crumb=None, # type: Optional[Breadcrumb]
hint=None, # type: Optional[BreadcrumbHint]
crumb=None, # type: Optional[sentry_sdk._types.Breadcrumb]
hint=None, # type: Optional[sentry_sdk._types.BreadcrumbHint]
**kwargs, # type: Any
):
# type: (...) -> None
Expand Down Expand Up @@ -224,7 +214,7 @@ def set_user(value):

@scopemethod
def set_level(value):
# type: (LogLevelStr) -> None
# type: (sentry_sdk._types.LogLevelStr) -> None
return get_isolation_scope().set_level(value)


Expand All @@ -238,7 +228,7 @@ def flush(


def start_span(**kwargs):
# type: (Any) -> Span
# type: (Any) -> sentry_sdk.tracing.Span
"""
Start and return a span.

Expand All @@ -255,10 +245,10 @@ def start_span(**kwargs):


def start_transaction(
transaction=None, # type: Optional[Span]
transaction=None, # type: Optional[sentry_sdk.tracing.Span]
**kwargs, # type: Any
):
# type: (...) -> Span
# type: (...) -> sentry_sdk.tracing.Span
"""
.. deprecated:: 3.0.0
This function is deprecated and will be removed in a future release.
Expand Down Expand Up @@ -298,14 +288,14 @@ def start_transaction(


def set_measurement(name, value, unit=""):
# type: (str, float, MeasurementUnit) -> None
# type: (str, float, sentry_sdk._types.MeasurementUnit) -> None
transaction = get_current_scope().root_span
if transaction is not None:
transaction.set_measurement(name, value, unit)


def get_current_span(scope=None):
# type: (Optional[Scope]) -> Optional[Span]
# type: (Optional[Scope]) -> Optional[sentry_sdk.tracing.Span]
"""
Returns the currently active span if there is one running, otherwise `None`
"""
Expand Down
40 changes: 40 additions & 0 deletions sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,46 @@ class OP:
SOCKET_DNS = "socket.dns"


BAGGAGE_HEADER_NAME = "baggage"
SENTRY_TRACE_HEADER_NAME = "sentry-trace"

DEFAULT_SPAN_ORIGIN = "manual"
DEFAULT_SPAN_NAME = "<unlabeled span>"


# Transaction source
# see https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations
class TransactionSource(str, Enum):
COMPONENT = "component"
CUSTOM = "custom"
ROUTE = "route"
TASK = "task"
URL = "url"
VIEW = "view"

def __str__(self):
# type: () -> str
return self.value


# These are typically high cardinality and the server hates them
LOW_QUALITY_TRANSACTION_SOURCES = [
TransactionSource.URL,
]

SOURCE_FOR_STYLE = {
"endpoint": TransactionSource.COMPONENT,
"function_name": TransactionSource.COMPONENT,
"handler_name": TransactionSource.COMPONENT,
"method_and_path_pattern": TransactionSource.ROUTE,
"path": TransactionSource.URL,
"route_name": TransactionSource.COMPONENT,
"route_pattern": TransactionSource.ROUTE,
"uri_template": TransactionSource.ROUTE,
"url": TransactionSource.ROUTE,
}


# This type exists to trick mypy and PyCharm into thinking `init` and `Client`
# take these arguments (even though they take opaque **kwargs)
class ClientConstructor:
Expand Down
14 changes: 8 additions & 6 deletions sentry_sdk/integrations/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
from functools import wraps

import sentry_sdk
from sentry_sdk.consts import OP, SPANSTATUS, SPANDATA
from sentry_sdk.consts import (
OP,
SPANSTATUS,
SPANDATA,
BAGGAGE_HEADER_NAME,
SOURCE_FOR_STYLE,
TransactionSource,
)
from sentry_sdk.integrations import (
_DEFAULT_FAILED_REQUEST_STATUS_CODES,
_check_minimum_version,
Expand All @@ -17,11 +24,6 @@
_request_headers_to_span_attributes,
request_body_within_bounds,
)
from sentry_sdk.tracing import (
BAGGAGE_HEADER_NAME,
SOURCE_FOR_STYLE,
TransactionSource,
)
from sentry_sdk.tracing_utils import should_propagate_trace
from sentry_sdk.utils import (
capture_internal_exceptions,
Expand Down
6 changes: 1 addition & 5 deletions sentry_sdk/integrations/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from functools import partial

import sentry_sdk
from sentry_sdk.consts import OP
from sentry_sdk.consts import OP, SOURCE_FOR_STYLE, TransactionSource

from sentry_sdk.integrations._asgi_common import (
_get_headers,
Expand All @@ -23,10 +23,6 @@
_request_headers_to_span_attributes,
)
from sentry_sdk.sessions import track_session
from sentry_sdk.tracing import (
SOURCE_FOR_STYLE,
TransactionSource,
)
from sentry_sdk.utils import (
ContextVar,
capture_internal_exceptions,
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/bottle.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import functools

import sentry_sdk
from sentry_sdk.tracing import SOURCE_FOR_STYLE
from sentry_sdk.consts import SOURCE_FOR_STYLE
from sentry_sdk.utils import (
capture_internal_exceptions,
ensure_integration_enabled,
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/celery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import sentry_sdk
from sentry_sdk import isolation_scope
from sentry_sdk.consts import OP, SPANSTATUS, SPANDATA
from sentry_sdk.consts import OP, SPANSTATUS, SPANDATA, BAGGAGE_HEADER_NAME
from sentry_sdk.integrations import _check_minimum_version, Integration, DidNotEnable
from sentry_sdk.integrations.celery.beat import (
_patch_beat_apply_entry,
Expand All @@ -13,7 +13,7 @@
)
from sentry_sdk.integrations.celery.utils import _now_seconds_since_epoch
from sentry_sdk.integrations.logging import ignore_logger
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME, TransactionSource
from sentry_sdk.tracing import TransactionSource
from sentry_sdk.tracing_utils import Baggage
from sentry_sdk.utils import (
capture_internal_exceptions,
Expand Down
3 changes: 1 addition & 2 deletions sentry_sdk/integrations/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
from importlib import import_module

import sentry_sdk
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.consts import OP, SPANDATA, SOURCE_FOR_STYLE, TransactionSource
from sentry_sdk.scope import add_global_event_processor, should_send_default_pii
from sentry_sdk.serializer import add_global_repr_processor
from sentry_sdk.tracing import SOURCE_FOR_STYLE, TransactionSource
from sentry_sdk.tracing_utils import add_query_source, record_sql_queries
from sentry_sdk.utils import (
AnnotatedValue,
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/falcon.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sentry_sdk
from sentry_sdk.consts import SOURCE_FOR_STYLE
from sentry_sdk.integrations import _check_minimum_version, Integration, DidNotEnable
from sentry_sdk.integrations._wsgi_common import RequestExtractor
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
from sentry_sdk.tracing import SOURCE_FOR_STYLE
from sentry_sdk.utils import (
capture_internal_exceptions,
ensure_integration_enabled,
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from functools import wraps

import sentry_sdk
from sentry_sdk.consts import SOURCE_FOR_STYLE, TransactionSource
from sentry_sdk.integrations import DidNotEnable
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing import SOURCE_FOR_STYLE, TransactionSource
from sentry_sdk.utils import (
transaction_from_function,
logger,
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/flask.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import sentry_sdk
from sentry_sdk.consts import SOURCE_FOR_STYLE
from sentry_sdk.integrations import _check_minimum_version, DidNotEnable, Integration
from sentry_sdk.integrations._wsgi_common import (
DEFAULT_HTTP_METHODS_TO_CAPTURE,
RequestExtractor,
)
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing import SOURCE_FOR_STYLE
from sentry_sdk.utils import (
capture_internal_exceptions,
ensure_integration_enabled,
Expand Down
3 changes: 1 addition & 2 deletions sentry_sdk/integrations/httpx.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sentry_sdk
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.consts import OP, SPANDATA, BAGGAGE_HEADER_NAME
from sentry_sdk.integrations import Integration, DidNotEnable
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME
from sentry_sdk.tracing_utils import Baggage, should_propagate_trace
from sentry_sdk.utils import (
SENSITIVE_DATA_SUBSTITUTE,
Expand Down
9 changes: 5 additions & 4 deletions sentry_sdk/integrations/huey.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

import sentry_sdk
from sentry_sdk.api import get_baggage, get_traceparent
from sentry_sdk.consts import OP, SPANSTATUS
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing import (
from sentry_sdk.consts import (
OP,
SPANSTATUS,
BAGGAGE_HEADER_NAME,
SENTRY_TRACE_HEADER_NAME,
TransactionSource,
)
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.utils import (
capture_internal_exceptions,
ensure_integration_enabled,
Expand Down
3 changes: 1 addition & 2 deletions sentry_sdk/integrations/litestar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Set
import sentry_sdk
from sentry_sdk.consts import OP
from sentry_sdk.consts import OP, TransactionSource, SOURCE_FOR_STYLE
from sentry_sdk.integrations import (
_DEFAULT_FAILED_REQUEST_STATUS_CODES,
DidNotEnable,
Expand All @@ -9,7 +9,6 @@
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
from sentry_sdk.integrations.logging import ignore_logger
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing import TransactionSource, SOURCE_FOR_STYLE
from sentry_sdk.utils import (
ensure_integration_enabled,
event_from_exception,
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/opentelemetry/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
use_span,
)

from sentry_sdk.integrations.opentelemetry.consts import (
from sentry_sdk.opentelemetry.consts import (
SENTRY_SCOPES_KEY,
SENTRY_FORK_ISOLATION_SCOPE_KEY,
SENTRY_USE_CURRENT_SCOPE_KEY,
SENTRY_USE_ISOLATION_SCOPE_KEY,
TRACESTATE_SAMPLED_KEY,
)
from sentry_sdk.integrations.opentelemetry.utils import trace_state_from_baggage
from sentry_sdk.opentelemetry.contextvars_context import (
SentryContextVarsRuntimeContext,
)
from sentry_sdk.opentelemetry.utils import trace_state_from_baggage
from sentry_sdk.scope import Scope, ScopeType
from sentry_sdk.tracing import Span
from sentry_sdk._types import TYPE_CHECKING
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import weakref

import sentry_sdk
from sentry_sdk.consts import SOURCE_FOR_STYLE
from sentry_sdk.integrations import Integration, DidNotEnable
from sentry_sdk.integrations._wsgi_common import RequestExtractor
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing import SOURCE_FOR_STYLE
from sentry_sdk.utils import (
capture_internal_exceptions,
ensure_integration_enabled,
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/quart.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from functools import wraps

import sentry_sdk
from sentry_sdk.consts import SOURCE_FOR_STYLE
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.integrations._wsgi_common import _filter_headers
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing import SOURCE_FOR_STYLE
from sentry_sdk.utils import (
capture_internal_exceptions,
ensure_integration_enabled,
Expand Down
Loading
Loading