Skip to content
Draft
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
26 changes: 3 additions & 23 deletions src/sentry/conf/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import sys
from collections.abc import Callable, Mapping, MutableSequence
from datetime import datetime, timedelta
from typing import Any, Final, Literal, Union, overload
from typing import Any, Literal, Union, overload
from urllib.parse import urlparse

import orjson
Expand Down Expand Up @@ -2679,32 +2679,12 @@ def custom_parameter_sort(parameter: dict) -> tuple[str, int]:

SENTRY_SDK_THREADING_INTEGRATION = os.environ.get("SENTRY_SDK_DISABLE_THREADING") != "1"

# The sample rate to use for profiles. This is conditional on the usage of
# traces_sample_rate. So that means the true sample rate will be approximately
# traces_sample_rate * profiles_sample_rate
# (subject to things like the traces_sampler)
SENTRY_PROFILES_SAMPLE_RATE = 1 if DEBUG else 0

# We want to test a few schedulers possible in the profiler. Some are platform
# specific, and each have their own pros/cons. See the sdk for more details.
SENTRY_PROFILER_MODE: Final = "sleep"

# To have finer control over which process will have profiling enabled, this
# environment variable will be required to enable profiling.
# To have finer control over which process will have continuous profiling enabled,
# this environment variable will be required to enable continuous profiling.
#
# This is because profiling requires that we run some stuff globally, and we
# are not ready to run this on the more critical parts of the codebase such as
# the ingest workers yet.
#
# This will allow us to have finer control over where we are running the
# profiler. For example, only on the web server.
SENTRY_PROFILING_ENABLED = os.environ.get("SENTRY_PROFILING_ENABLED", SPOTLIGHT)

# To have finer control over which process will have continuous profiling enabled,
# this environment variable will be required to enable continuous profiling.
#
# This setting takes precedence over `SENTRY_PROFILING_ENABLED` forcing the SDK
# to operate under the continuous profiling model.
SENTRY_CONTINUOUS_PROFILING_ENABLED = os.environ.get("SENTRY_CONTINUOUS_PROFILING_ENABLED", False)

# The sample rate to use for continuous profile sessions. This sample rate is
Expand Down
3 changes: 0 additions & 3 deletions src/sentry/conf/types/sdk_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ class SdkConfig(TypedDict):
before_send: NotRequired[Callable[[Event, Hint], Event | None]]
before_send_transaction: NotRequired[Callable[[Event, Hint], Event | None]]
before_send_log: NotRequired[Callable[[Log, Hint], Log | None]]
profiles_sample_rate: NotRequired[float]
profiles_sampler: NotRequired[Callable[[dict[str, Any]], float]]
profiler_mode: NotRequired[Literal["sleep", "thread", "gevent", "unknown"]]
profile_session_sample_rate: NotRequired[float]
profile_lifecycle: NotRequired[Literal["manual", "trace"]]
enable_db_query_source: NotRequired[bool]
Expand Down
20 changes: 1 addition & 19 deletions src/sentry/utils/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,6 @@ def traces_sampler(sampling_context):
return float(settings.SENTRY_BACKEND_APM_SAMPLING or 0)


def profiles_sampler(sampling_context):
PROFILES_SAMPLING_RATE = {
"consumer.join": options.get("consumer.join.profiling.rate"),
"spans.process.process_message": options.get("spans.process-spans.profiling.rate"),
}
if "transaction_context" in sampling_context:
transaction_name = sampling_context["transaction_context"].get("name")

if transaction_name in PROFILES_SAMPLING_RATE:
return PROFILES_SAMPLING_RATE[transaction_name]

# Default to the sampling rate in settings
return float(settings.SENTRY_PROFILES_SAMPLE_RATE or 0)


def before_send_transaction(event: Event, _: Hint) -> Event | None:
# Discard generic redirects.
# This condition can be removed once https://github.com/getsentry/team-sdks/issues/48 is fixed.
Expand Down Expand Up @@ -386,12 +371,9 @@ def configure_sdk():

if settings.SENTRY_CONTINUOUS_PROFILING_ENABLED:
sdk_options["profile_session_sample_rate"] = float(
settings.SENTRY_PROFILES_SAMPLE_RATE or 0
settings.SENTRY_PROFILE_SESSION_SAMPLE_RATE or 0
)
sdk_options["profile_lifecycle"] = settings.SENTRY_PROFILE_LIFECYCLE
elif settings.SENTRY_PROFILING_ENABLED:
sdk_options["profiles_sampler"] = profiles_sampler
sdk_options["profiler_mode"] = settings.SENTRY_PROFILER_MODE

from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.logging import LoggingIntegration
Expand Down
Loading