Skip to content

chore: upgrade sentry_sdk for logging fix #91900

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 2 commits into from
May 20, 2025
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
2 changes: 1 addition & 1 deletion requirements-base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ sentry-ophio>=1.1.3
sentry-protos==0.2.0
sentry-redis-tools>=0.5.0
sentry-relay>=0.9.9
sentry-sdk[http2]>=2.25.1
sentry-sdk[http2]>=2.29.1
slack-sdk>=3.27.2
snuba-sdk>=3.0.43
simplejson>=3.17.6
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev-frozen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ sentry-ophio==1.1.3
sentry-protos==0.2.0
sentry-redis-tools==0.5.0
sentry-relay==0.9.9
sentry-sdk==2.27.0
sentry-sdk==2.29.1
sentry-usage-accountant==0.0.10
simplejson==3.17.6
six==1.16.0
Expand Down
2 changes: 1 addition & 1 deletion requirements-frozen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ sentry-ophio==1.1.3
sentry-protos==0.2.0
sentry-redis-tools==0.5.0
sentry-relay==0.9.9
sentry-sdk==2.27.0
sentry-sdk==2.29.1
sentry-usage-accountant==0.0.10
simplejson==3.17.6
six==1.16.0
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/api/bases/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from sentry.utils import auth
from sentry.utils.hashlib import hash_values
from sentry.utils.numbers import format_grouped_length
from sentry.utils.sdk import bind_organization_context, set_measurement
from sentry.utils.sdk import bind_organization_context, set_span_data


class NoProjects(Exception):
Expand Down Expand Up @@ -566,7 +566,7 @@ def get_filter_params(
len_projects = len(projects)
sentry_sdk.set_tag("query.num_projects", len_projects)
sentry_sdk.set_tag("query.num_projects.grouped", format_grouped_length(len_projects))
set_measurement("query.num_projects", len_projects)
set_span_data("query.num_projects", len_projects)

params: FilterParams = {
"start": start,
Expand Down
6 changes: 3 additions & 3 deletions src/sentry/api/endpoints/organization_event_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from datetime import datetime, timedelta
from typing import Any

import sentry_sdk
from rest_framework.request import Request
from rest_framework.response import Response
from snuba_sdk import Column, Condition, Function, Op
Expand All @@ -23,6 +22,7 @@
from sentry.snuba.dataset import Dataset
from sentry.snuba.query_sources import QuerySource
from sentry.snuba.referrer import Referrer
from sentry.utils.sdk import set_span_data

VALID_AVERAGE_COLUMNS = {"span.self_time", "span.duration"}

Expand All @@ -39,7 +39,7 @@ def add_comparison_to_event(event, average_columns, request: Request):
group_to_span_map[group].append(span)

# Nothing to add comparisons to
sentry_sdk.set_measurement("query.groups", len(group_to_span_map))
set_span_data("query.groups", len(group_to_span_map))
if len(group_to_span_map) == 0:
return

Expand Down Expand Up @@ -77,7 +77,7 @@ def add_comparison_to_event(event, average_columns, request: Request):
),
)
)
sentry_sdk.set_measurement("query.groups_found", len(result["data"]))
set_span_data("query.groups_found", len(result["data"]))
for row in result["data"]:
group = row["span.group"]
for span in group_to_span_map[group]:
Expand Down
15 changes: 8 additions & 7 deletions src/sentry/api/endpoints/organization_events_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from sentry.snuba.referrer import Referrer
from sentry.utils.iterators import chunked
from sentry.utils.numbers import base32_encode, format_grouped_length
from sentry.utils.sdk import set_measurement
from sentry.utils.sdk import set_span_data
from sentry.utils.snuba import bulk_snuba_queries
from sentry.utils.validators import INVALID_ID_DETAILS, is_event_id, is_span_id

Expand Down Expand Up @@ -761,7 +761,7 @@ def build_span_query(trace_id: str, spans_params: SnubaParams, query_spans: list
# Performance improvement, snuba's parser is extremely slow when we're sending thousands of
# span_ids here, using a `splitByChar` means that snuba will not parse the giant list of spans
span_minimum = options.get("performance.traces.span_query_minimum_spans")
sentry_sdk.set_measurement("trace_view.spans.span_minimum", span_minimum)
set_span_data("trace_view.spans.span_minimum", span_minimum)
sentry_sdk.set_tag("trace_view.split_by_char.optimization", len(query_spans) > span_minimum)
if len(query_spans) > span_minimum:
# TODO: because we're not doing an IN on a list of literals, snuba will not optimize the query with the HexInt
Expand Down Expand Up @@ -813,14 +813,14 @@ def augment_transactions_with_spans(
projects.add(error["project.id"])
ts_params = find_timestamp_params(transactions)
time_buffer = options.get("performance.traces.span_query_timebuffer_hours")
sentry_sdk.set_measurement("trace_view.spans.time_buffer", time_buffer)
set_span_data("trace_view.spans.time_buffer", time_buffer)
if ts_params["min"]:
params.start = ts_params["min"] - timedelta(hours=time_buffer)
if ts_params["max"]:
params.end = ts_params["max"] + timedelta(hours=time_buffer)

if ts_params["max"] and ts_params["min"]:
sentry_sdk.set_measurement(
set_span_data(
"trace_view.trace_duration", (ts_params["max"] - ts_params["min"]).total_seconds()
)
sentry_sdk.set_tag("trace_view.missing_timestamp_constraints", False)
Expand Down Expand Up @@ -899,7 +899,7 @@ def augment_transactions_with_spans(
total_chunks = 3
else:
total_chunks = 4
sentry_sdk.set_measurement("trace_view.span_query.total_chunks", total_chunks)
set_span_data("trace_view.span_query.total_chunks", total_chunks)
chunks = chunked(list_spans, (len(list_spans) // total_chunks) + 1)
queries = [build_span_query(trace_id, spans_params, chunk) for chunk in chunks]
results = bulk_snuba_queries(
Expand Down Expand Up @@ -1046,15 +1046,16 @@ def record_analytics(
sentry_sdk.set_tag(
"trace_view.transactions.grouped", format_grouped_length(len_transactions)
)
set_measurement("trace_view.transactions", len_transactions)
set_span_data("trace_view.transactions", len_transactions)

projects: set[int] = set()
for transaction in transactions:
projects.add(transaction["project.id"])

len_projects = len(projects)
sentry_sdk.set_tag("trace_view.projects", len_projects)
sentry_sdk.set_tag("trace_view.projects.grouped", format_grouped_length(len_projects))
set_measurement("trace_view.projects", len_projects)
set_span_data("trace_view.projects", len_projects)

def get(self, request: Request, organization: Organization, trace_id: str) -> HttpResponse:
if not self.has_feature(organization, request):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from sentry.snuba.dataset import Dataset
from sentry.snuba.referrer import Referrer
from sentry.utils.dates import parse_stats_period, validate_interval
from sentry.utils.sdk import set_measurement
from sentry.utils.sdk import set_span_data
from sentry.utils.snuba import bulk_snuba_queries

TOP_FUNCTIONS_LIMIT = 50
Expand Down Expand Up @@ -202,7 +202,7 @@ def get_trends_data(stats_data) -> list[BreakpointData]:
trending_functions = get_trends_data(stats_data)

all_trending_functions_count = len(trending_functions)
set_measurement("profiling.top_functions", all_trending_functions_count)
set_span_data("profiling.top_functions", all_trending_functions_count)

# Profiling functions have a resolution of ~10ms. To increase the confidence
# of the results, the caller can specify a min threshold for the trend difference.
Expand All @@ -215,9 +215,7 @@ def get_trends_data(stats_data) -> list[BreakpointData]:
]

filtered_trending_functions_count = all_trending_functions_count - len(trending_functions)
set_measurement(
"profiling.top_functions.below_threshold", filtered_trending_functions_count
)
set_span_data("profiling.top_functions.below_threshold", filtered_trending_functions_count)

# Make sure to sort the results so that it's in order of largest change
# to smallest change (ASC/DESC depends on the trend type)
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/api/endpoints/organization_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from sentry.api.utils import clamp_date_range, handle_query_errors
from sentry.snuba.dataset import Dataset
from sentry.utils.numbers import format_grouped_length
from sentry.utils.sdk import set_measurement
from sentry.utils.sdk import set_span_data


@region_silo_endpoint
Expand Down Expand Up @@ -83,6 +83,6 @@ def get(self, request: Request, organization) -> Response:
format_grouped_length(len(results), [1, 10, 50, 100]),
)
sentry_sdk.set_tag("dataset_queried", dataset.value)
set_measurement("custom_tags.count", len(results))
set_span_data("custom_tags.count", len(results))

return Response(serialize(results, request.user))
6 changes: 3 additions & 3 deletions src/sentry/api/endpoints/organization_traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from sentry.snuba.dataset import Dataset
from sentry.snuba.referrer import Referrer
from sentry.utils.numbers import clip
from sentry.utils.sdk import set_measurement
from sentry.utils.sdk import set_span_data
from sentry.utils.snuba import bulk_snuba_queries_with_referrers
from sentry.utils.snuba_rpc import get_traces_rpc

Expand Down Expand Up @@ -1417,7 +1417,7 @@ def process_user_queries(
where, _ = resolve_conditions(user_query)
queries[user_query] = where

set_measurement("user_queries_count", len(queries))
set_span_data("user_queries_count", len(queries))
sentry_sdk.set_context("user_queries", {"raw_queries": user_queries})

return queries
Expand Down Expand Up @@ -1452,7 +1452,7 @@ def process_rpc_user_queries(
if where is not None:
queries[user_query] = where

set_measurement("user_queries_count", len(queries))
set_span_data("user_queries_count", len(queries))
sentry_sdk.set_context("user_queries", {"raw_queries": user_queries})

return queries
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from sentry.silo.base import SiloMode
from sentry.types.region import get_local_region
from sentry.utils.dates import parse_stats_period
from sentry.utils.sdk import capture_exception, merge_context_into_scope
from sentry.utils.sdk import capture_exception, merge_context_into_scope, set_span_data
from sentry.utils.snuba import (
DatasetSelectionError,
QueryConnectionFailed,
Expand Down Expand Up @@ -454,7 +454,7 @@ def update_snuba_params_with_timestamp(
# While possible, the majority of traces shouldn't take more than a week
# Starting with 3d for now, but potentially something we can increase if this becomes a problem
time_buffer = options.get("performance.traces.transaction_query_timebuffer_days")
sentry_sdk.set_measurement("trace_view.transactions.time_buffer", time_buffer)
set_span_data("trace_view.transactions.time_buffer", time_buffer)
example_start = example_timestamp - timedelta(days=time_buffer)
example_end = example_timestamp + timedelta(days=time_buffer)
# If timestamp is being passed it should always overwrite the statsperiod or start & end
Expand Down
7 changes: 3 additions & 4 deletions src/sentry/event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
from sentry.utils.performance_issues.performance_detection import detect_performance_problems
from sentry.utils.performance_issues.performance_problem import PerformanceProblem
from sentry.utils.safe import get_path, safe_execute, setdefault_path, trim
from sentry.utils.sdk import set_measurement
from sentry.utils.sdk import set_span_data
from sentry.utils.tag_normalization import normalized_sdk_tag_from_event

from .utils.event_tracker import TransactionStageStatus, track_sampled_event
Expand Down Expand Up @@ -2587,9 +2587,8 @@ def save_transaction_events(
)
except KeyError:
continue

set_measurement(measurement_name="jobs", value=len(jobs))
set_measurement(measurement_name="projects", value=len(projects))
set_span_data("jobs", len(jobs))
set_span_data("projects", len(projects))

# NOTE: Keep this list synchronized with sentry/spans/consumers/process_segments/message.py

Expand Down
3 changes: 2 additions & 1 deletion src/sentry/ingest/transaction_clusterer/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from sentry.ingest.transaction_clusterer.rule_validator import RuleValidator
from sentry.models.project import Project
from sentry.utils import metrics
from sentry.utils.sdk import set_span_data

from .base import ReplacementRule

Expand Down Expand Up @@ -145,7 +146,7 @@ def _trim_rules(self, rules: RuleSet) -> RuleSet:
sorted_rules = [rule for rule in sorted_rules if rule[1] >= last_seen_deadline]

if self.MERGE_MAX_RULES < len(rules):
sentry_sdk.set_measurement("discarded_rules", len(rules) - self.MERGE_MAX_RULES)
set_span_data("discarded_rules", len(rules) - self.MERGE_MAX_RULES)
sentry_sdk.Scope.get_isolation_scope().set_context(
"clustering_rules_max",
{
Expand Down
4 changes: 3 additions & 1 deletion src/sentry/models/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from sentry.utils.db import atomic_transaction
from sentry.utils.hashlib import hash_values, md5_text
from sentry.utils.numbers import validate_bigint
from sentry.utils.sdk import set_span_data

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -644,7 +645,8 @@ def set_commits(self, commit_list):
This will clear any existing commit log and replace it with the given
commits.
"""
sentry_sdk.set_measurement("release.set_commits", len(commit_list))
set_span_data("release.set_commits", len(commit_list))

from sentry.models.releases.set_commits import set_commits

set_commits(self, commit_list)
Expand Down
18 changes: 8 additions & 10 deletions src/sentry/profiles/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from sentry.utils.kafka_config import get_kafka_producer_cluster_options, get_topic_definition
from sentry.utils.locking import UnableToAcquireLock
from sentry.utils.outcomes import Outcome, track_outcome
from sentry.utils.sdk import set_measurement
from sentry.utils.sdk import set_span_data

REVERSE_DEVICE_CLASS = {next(iter(tags)): label for label, tags in DEVICE_CLASS.items()}

Expand Down Expand Up @@ -223,10 +223,9 @@ def process_profile_task(
if "version" in profile:
version = profile["version"]
sentry_sdk.set_tag("format", f"sample_v{version}")

set_measurement("profile.samples", len(profile["profile"]["samples"]))
set_measurement("profile.stacks", len(profile["profile"]["stacks"]))
set_measurement("profile.frames", len(profile["profile"]["frames"]))
set_span_data("profile.samples", len(profile["profile"]["samples"]))
set_span_data("profile.stacks", len(profile["profile"]["stacks"]))
set_span_data("profile.frames", len(profile["profile"]["frames"]))
elif "profiler_id" in profile and profile["platform"] == "android":
sentry_sdk.set_tag("format", "android_chunk")
else:
Expand All @@ -252,9 +251,9 @@ def process_profile_task(
_set_frames_platform(profile)

if "version" in profile:
set_measurement("profile.samples.processed", len(profile["profile"]["samples"]))
set_measurement("profile.stacks.processed", len(profile["profile"]["stacks"]))
set_measurement("profile.frames.processed", len(profile["profile"]["frames"]))
set_span_data("profile.samples.processed", len(profile["profile"]["samples"]))
set_span_data("profile.stacks.processed", len(profile["profile"]["stacks"]))
set_span_data("profile.frames.processed", len(profile["profile"]["frames"]))

if options.get("profiling.stack_trace_rules.enabled"):
try:
Expand Down Expand Up @@ -372,8 +371,7 @@ def _symbolicate_profile(profile: Profile, project: Project) -> bool:
raw_modules, raw_stacktraces, frames_sent = _prepare_frames_from_profile(
profile, platform
)

set_measurement(
set_span_data(
f"profile.frames.sent.{platform}",
len(frames_sent),
)
Expand Down
5 changes: 2 additions & 3 deletions src/sentry/profiles/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from sentry.grouping.enhancer import Enhancements, keep_profiling_rules
from sentry.net.http import connection_from_url
from sentry.utils import json, metrics
from sentry.utils.sdk import set_measurement
from sentry.utils.sdk import set_span_data

Profile = MutableMapping[str, Any]
CallTrees = Mapping[str, list[Any]]
Expand Down Expand Up @@ -113,8 +113,7 @@ def get_from_profiling_service(
)
with sentry_sdk.start_span(op="json.dumps"):
data = json.dumps(json_data).encode("utf-8")

set_measurement("payload.size", len(data), unit="byte")
set_span_data("payload.size", len(data))
if metric:
metric_name, metric_tags = metric
metrics.distribution(metric_name, len(data), tags=metric_tags)
Expand Down
8 changes: 4 additions & 4 deletions src/sentry/search/events/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from sentry.search.events.types import NormalizedArg, ParamsType
from sentry.search.utils import InvalidQuery, parse_duration
from sentry.utils.numbers import format_grouped_length
from sentry.utils.sdk import set_measurement
from sentry.utils.sdk import set_span_data
from sentry.utils.snuba import (
SESSIONS_SNUBA_MAP,
get_json_type,
Expand Down Expand Up @@ -135,15 +135,15 @@ def project_threshold_config_expression(
"project_threshold.count.grouped",
format_grouped_length(num_project_thresholds, [10, 100, 250, 500]),
)
set_measurement("project_threshold.count", num_project_thresholds)
set_span_data("project_threshold.count", num_project_thresholds)

num_transaction_thresholds = transaction_threshold_configs.count()
sentry_sdk.set_tag("txn_threshold.count", num_transaction_thresholds)
sentry_sdk.set_tag(
"txn_threshold.count.grouped",
format_grouped_length(num_transaction_thresholds, [10, 100, 250, 500]),
)
set_measurement("txn_threshold.count", num_transaction_thresholds)
set_span_data("txn_threshold.count", num_transaction_thresholds)

if num_project_thresholds + num_transaction_thresholds == 0:
return ["tuple", [f"'{DEFAULT_PROJECT_THRESHOLD_METRIC}'", DEFAULT_PROJECT_THRESHOLD]]
Expand Down Expand Up @@ -283,7 +283,7 @@ def team_key_transaction_expression(organization_id, team_ids, project_ids):
sentry_sdk.set_tag(
"team_key_txns.count.grouped", format_grouped_length(count, [10, 100, 250, 500])
)
set_measurement("team_key_txns.count", count)
set_span_data("team_key_txns.count", count)

# There are no team key transactions marked, so hard code false into the query.
if count == 0:
Expand Down
Loading
Loading