diff --git a/src/sentry/api/bases/organization.py b/src/sentry/api/bases/organization.py index 5fb069cde2dbdf..130c6e1ec1c05d 100644 --- a/src/sentry/api/bases/organization.py +++ b/src/sentry/api/bases/organization.py @@ -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_span_data +from sentry.utils.sdk import bind_organization_context, set_span_attribute class NoProjects(Exception): @@ -569,7 +569,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_span_data("query.num_projects", len_projects) + set_span_attribute("query.num_projects", len_projects) params: FilterParams = { "start": start, diff --git a/src/sentry/api/endpoints/organization_event_details.py b/src/sentry/api/endpoints/organization_event_details.py index 456c64ddf52a3a..89ddbf72c78300 100644 --- a/src/sentry/api/endpoints/organization_event_details.py +++ b/src/sentry/api/endpoints/organization_event_details.py @@ -22,7 +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 +from sentry.utils.sdk import set_span_attribute VALID_AVERAGE_COLUMNS = {"span.self_time", "span.duration"} @@ -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 - set_span_data("query.groups", len(group_to_span_map)) + set_span_attribute("query.groups", len(group_to_span_map)) if len(group_to_span_map) == 0: return @@ -77,7 +77,7 @@ def add_comparison_to_event(event, average_columns, request: Request): ), ) ) - set_span_data("query.groups_found", len(result["data"])) + set_span_attribute("query.groups_found", len(result["data"])) for row in result["data"]: group = row["span.group"] for span in group_to_span_map[group]: diff --git a/src/sentry/api/endpoints/organization_events_trace.py b/src/sentry/api/endpoints/organization_events_trace.py index fb6c5bfdc5bfb7..47d0a41c2fca4d 100644 --- a/src/sentry/api/endpoints/organization_events_trace.py +++ b/src/sentry/api/endpoints/organization_events_trace.py @@ -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_span_data +from sentry.utils.sdk import set_span_attribute from sentry.utils.snuba import bulk_snuba_queries from sentry.utils.validators import INVALID_ID_DETAILS, is_event_id, is_span_id @@ -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") - set_span_data("trace_view.spans.span_minimum", span_minimum) + set_span_attribute("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 @@ -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") - set_span_data("trace_view.spans.time_buffer", time_buffer) + set_span_attribute("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"]: - set_span_data( + set_span_attribute( "trace_view.trace_duration", (ts_params["max"] - ts_params["min"]).total_seconds() ) sentry_sdk.set_tag("trace_view.missing_timestamp_constraints", False) @@ -899,7 +899,7 @@ def augment_transactions_with_spans( total_chunks = 3 else: total_chunks = 4 - set_span_data("trace_view.span_query.total_chunks", total_chunks) + set_span_attribute("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( @@ -1046,7 +1046,7 @@ def record_analytics( sentry_sdk.set_tag( "trace_view.transactions.grouped", format_grouped_length(len_transactions) ) - set_span_data("trace_view.transactions", len_transactions) + set_span_attribute("trace_view.transactions", len_transactions) projects: set[int] = set() for transaction in transactions: @@ -1055,7 +1055,7 @@ def record_analytics( 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_span_data("trace_view.projects", len_projects) + set_span_attribute("trace_view.projects", len_projects) def get(self, request: Request, organization: Organization, trace_id: str) -> HttpResponse: if not request.user.is_authenticated: diff --git a/src/sentry/api/endpoints/organization_profiling_functions.py b/src/sentry/api/endpoints/organization_profiling_functions.py index e6a0659f991041..768f0710f2e5cc 100644 --- a/src/sentry/api/endpoints/organization_profiling_functions.py +++ b/src/sentry/api/endpoints/organization_profiling_functions.py @@ -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_span_data +from sentry.utils.sdk import set_span_attribute from sentry.utils.snuba import bulk_snuba_queries TOP_FUNCTIONS_LIMIT = 50 @@ -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_span_data("profiling.top_functions", all_trending_functions_count) + set_span_attribute("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. @@ -215,7 +215,9 @@ def get_trends_data(stats_data) -> list[BreakpointData]: ] filtered_trending_functions_count = all_trending_functions_count - len(trending_functions) - set_span_data("profiling.top_functions.below_threshold", filtered_trending_functions_count) + set_span_attribute( + "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) diff --git a/src/sentry/api/endpoints/organization_tags.py b/src/sentry/api/endpoints/organization_tags.py index 4fd7c20c293840..8b26a5a9e7f4ff 100644 --- a/src/sentry/api/endpoints/organization_tags.py +++ b/src/sentry/api/endpoints/organization_tags.py @@ -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_span_data +from sentry.utils.sdk import set_span_attribute @region_silo_endpoint @@ -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_span_data("custom_tags.count", len(results)) + set_span_attribute("custom_tags.count", len(results)) return Response(serialize(results, request.user)) diff --git a/src/sentry/api/endpoints/organization_traces.py b/src/sentry/api/endpoints/organization_traces.py index 3acc5e84504fd1..72daab5c96a61a 100644 --- a/src/sentry/api/endpoints/organization_traces.py +++ b/src/sentry/api/endpoints/organization_traces.py @@ -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_span_data +from sentry.utils.sdk import set_span_attribute from sentry.utils.snuba import bulk_snuba_queries_with_referrers from sentry.utils.snuba_rpc import get_traces_rpc @@ -1417,7 +1417,7 @@ def process_user_queries( where, _ = resolve_conditions(user_query) queries[user_query] = where - set_span_data("user_queries_count", len(queries)) + set_span_attribute("user_queries_count", len(queries)) sentry_sdk.set_context("user_queries", {"raw_queries": user_queries}) return queries @@ -1452,7 +1452,7 @@ def process_rpc_user_queries( if where is not None: queries[user_query] = where - set_span_data("user_queries_count", len(queries)) + set_span_attribute("user_queries_count", len(queries)) sentry_sdk.set_context("user_queries", {"raw_queries": user_queries}) return queries diff --git a/src/sentry/api/utils.py b/src/sentry/api/utils.py index c87ed5d8a0e808..85974be350f0e4 100644 --- a/src/sentry/api/utils.py +++ b/src/sentry/api/utils.py @@ -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, set_span_data +from sentry.utils.sdk import capture_exception, merge_context_into_scope, set_span_attribute from sentry.utils.snuba import ( DatasetSelectionError, QueryConnectionFailed, @@ -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") - set_span_data("trace_view.transactions.time_buffer", time_buffer) + set_span_attribute("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 diff --git a/src/sentry/event_manager.py b/src/sentry/event_manager.py index bdb9444b9d8f74..3971752c028b04 100644 --- a/src/sentry/event_manager.py +++ b/src/sentry/event_manager.py @@ -136,7 +136,7 @@ from sentry.utils.performance_issues.performance_problem import PerformanceProblem from sentry.utils.projectflags import set_project_flag_and_signal from sentry.utils.safe import get_path, safe_execute, setdefault_path, trim -from sentry.utils.sdk import set_span_data +from sentry.utils.sdk import set_span_attribute from sentry.utils.tag_normalization import normalized_sdk_tag_from_event from .utils.event_tracker import TransactionStageStatus, track_sampled_event @@ -2605,8 +2605,8 @@ def save_transaction_events( ) except KeyError: continue - set_span_data("jobs", len(jobs)) - set_span_data("projects", len(projects)) + set_span_attribute("jobs", len(jobs)) + set_span_attribute("projects", len(projects)) # NOTE: Keep this list synchronized with sentry/spans/consumers/process_segments/message.py diff --git a/src/sentry/ingest/transaction_clusterer/rules.py b/src/sentry/ingest/transaction_clusterer/rules.py index 901694971dd7da..3979a5e410742f 100644 --- a/src/sentry/ingest/transaction_clusterer/rules.py +++ b/src/sentry/ingest/transaction_clusterer/rules.py @@ -9,7 +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 sentry.utils.sdk import set_span_attribute from .base import ReplacementRule @@ -146,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): - set_span_data("discarded_rules", len(rules) - self.MERGE_MAX_RULES) + set_span_attribute("discarded_rules", len(rules) - self.MERGE_MAX_RULES) sentry_sdk.Scope.get_isolation_scope().set_context( "clustering_rules_max", { diff --git a/src/sentry/models/release.py b/src/sentry/models/release.py index 0b2dcaf4a513bc..8ee88b2d169041 100644 --- a/src/sentry/models/release.py +++ b/src/sentry/models/release.py @@ -45,7 +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 +from sentry.utils.sdk import set_span_attribute logger = logging.getLogger(__name__) @@ -645,7 +645,7 @@ def set_commits(self, commit_list): This will clear any existing commit log and replace it with the given commits. """ - set_span_data("release.set_commits", len(commit_list)) + set_span_attribute("release.set_commits", len(commit_list)) from sentry.models.releases.set_commits import set_commits diff --git a/src/sentry/profiles/task.py b/src/sentry/profiles/task.py index 4afa825d58bc1f..c6b627460861cf 100644 --- a/src/sentry/profiles/task.py +++ b/src/sentry/profiles/task.py @@ -56,7 +56,7 @@ from sentry.utils.locking import UnableToAcquireLock from sentry.utils.outcomes import Outcome, track_outcome from sentry.utils.projectflags import set_project_flag_and_signal -from sentry.utils.sdk import set_span_data +from sentry.utils.sdk import set_span_attribute REVERSE_DEVICE_CLASS = {next(iter(tags)): label for label, tags in DEVICE_CLASS.items()} @@ -239,9 +239,9 @@ def process_profile_task( if "version" in profile: version = profile["version"] sentry_sdk.set_tag("format", f"sample_v{version}") - 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"])) + set_span_attribute("profile.samples", len(profile["profile"]["samples"])) + set_span_attribute("profile.stacks", len(profile["profile"]["stacks"])) + set_span_attribute("profile.frames", len(profile["profile"]["frames"])) elif "profiler_id" in profile and profile["platform"] == "android": sentry_sdk.set_tag("format", "android_chunk") else: @@ -267,9 +267,9 @@ def process_profile_task( _set_frames_platform(profile) if "version" in profile: - 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"])) + set_span_attribute("profile.samples.processed", len(profile["profile"]["samples"])) + set_span_attribute("profile.stacks.processed", len(profile["profile"]["stacks"])) + set_span_attribute("profile.frames.processed", len(profile["profile"]["frames"])) if options.get("profiling.stack_trace_rules.enabled"): try: @@ -386,7 +386,7 @@ def _symbolicate_profile(profile: Profile, project: Project) -> bool: raw_modules, raw_stacktraces, frames_sent = _prepare_frames_from_profile( profile, platform ) - set_span_data( + set_span_attribute( f"profile.frames.sent.{platform}", len(frames_sent), ) diff --git a/src/sentry/profiles/utils.py b/src/sentry/profiles/utils.py index 0287f9453e4592..eda1b486e0407c 100644 --- a/src/sentry/profiles/utils.py +++ b/src/sentry/profiles/utils.py @@ -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_span_data +from sentry.utils.sdk import set_span_attribute Profile = MutableMapping[str, Any] CallTrees = Mapping[str, list[Any]] @@ -113,7 +113,7 @@ def get_from_profiling_service( ) with sentry_sdk.start_span(op="json.dumps"): data = json.dumps(json_data).encode("utf-8") - set_span_data("payload.size", len(data)) + set_span_attribute("payload.size", len(data)) if metric: metric_name, metric_tags = metric metrics.distribution(metric_name, len(data), tags=metric_tags) diff --git a/src/sentry/search/events/fields.py b/src/sentry/search/events/fields.py index 2467bc20fddafb..c5de7772581f01 100644 --- a/src/sentry/search/events/fields.py +++ b/src/sentry/search/events/fields.py @@ -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_span_data +from sentry.utils.sdk import set_span_attribute from sentry.utils.snuba import ( SESSIONS_SNUBA_MAP, get_json_type, @@ -135,7 +135,7 @@ def project_threshold_config_expression( "project_threshold.count.grouped", format_grouped_length(num_project_thresholds, [10, 100, 250, 500]), ) - set_span_data("project_threshold.count", num_project_thresholds) + set_span_attribute("project_threshold.count", num_project_thresholds) num_transaction_thresholds = transaction_threshold_configs.count() sentry_sdk.set_tag("txn_threshold.count", num_transaction_thresholds) @@ -143,7 +143,7 @@ def project_threshold_config_expression( "txn_threshold.count.grouped", format_grouped_length(num_transaction_thresholds, [10, 100, 250, 500]), ) - set_span_data("txn_threshold.count", num_transaction_thresholds) + set_span_attribute("txn_threshold.count", num_transaction_thresholds) if num_project_thresholds + num_transaction_thresholds == 0: return ["tuple", [f"'{DEFAULT_PROJECT_THRESHOLD_METRIC}'", DEFAULT_PROJECT_THRESHOLD]] @@ -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_span_data("team_key_txns.count", count) + set_span_attribute("team_key_txns.count", count) # There are no team key transactions marked, so hard code false into the query. if count == 0: diff --git a/src/sentry/sentry_metrics/consumers/indexer/processing.py b/src/sentry/sentry_metrics/consumers/indexer/processing.py index 43b04ad8a5cb25..3971be7edd5893 100644 --- a/src/sentry/sentry_metrics/consumers/indexer/processing.py +++ b/src/sentry/sentry_metrics/consumers/indexer/processing.py @@ -24,7 +24,7 @@ from sentry.sentry_metrics.indexer.mock import MockIndexer from sentry.sentry_metrics.indexer.postgres.postgres_v2 import PostgresIndexer from sentry.utils import metrics -from sentry.utils.sdk import set_span_data +from sentry.utils.sdk import set_span_attribute logger = logging.getLogger(__name__) @@ -124,11 +124,11 @@ def _process_messages_impl( tags_validator=self.__get_tags_validator(), schema_validator=self.__get_schema_validator(), ) - set_span_data("indexer_batch.payloads.len", len(batch.parsed_payloads_by_meta)) + set_span_attribute("indexer_batch.payloads.len", len(batch.parsed_payloads_by_meta)) extracted_strings = batch.extract_strings() - set_span_data("org_strings.len", len(extracted_strings)) + set_span_attribute("org_strings.len", len(extracted_strings)) with metrics.timer("metrics_consumer.bulk_record"), sentry_sdk.start_span(op="bulk_record"): record_result = self._indexer.bulk_record(extracted_strings) @@ -138,6 +138,6 @@ def _process_messages_impl( results = batch.reconstruct_messages(mapping, bulk_record_meta) - set_span_data("new_messages.len", len(results.data)) + set_span_attribute("new_messages.len", len(results.data)) return results diff --git a/src/sentry/snuba/rpc_dataset_common.py b/src/sentry/snuba/rpc_dataset_common.py index 59375ebc26253c..f359251498a12e 100644 --- a/src/sentry/snuba/rpc_dataset_common.py +++ b/src/sentry/snuba/rpc_dataset_common.py @@ -44,7 +44,7 @@ from sentry.search.events.types import SAMPLING_MODES, EventsMeta, SnubaData, SnubaParams from sentry.snuba.discover import OTHER_KEY, create_groupby_dict, create_result_key from sentry.utils import json, snuba_rpc -from sentry.utils.sdk import set_span_data +from sentry.utils.sdk import set_span_attribute from sentry.utils.snuba import SnubaTSResult, process_value logger = logging.getLogger("sentry.snuba.spans_rpc") @@ -412,7 +412,7 @@ def process_table_response( assert len(column_value.results) == len(column_value.reliabilities), Exception( "Length of rpc results do not match length of rpc reliabilities" ) - set_span_data(f"SearchResolver.result_size.{attribute}", len(column_value.results)) + set_span_attribute(f"SearchResolver.result_size.{attribute}", len(column_value.results)) while len(final_data) < len(column_value.results): final_data.append({}) @@ -430,7 +430,7 @@ def process_table_response( final_confidence[index][attribute] = CONFIDENCES.get( column_value.reliabilities[index], None ) - set_span_data("SearchResolver.result_size.final_data", len(final_data)) + set_span_attribute("SearchResolver.result_size.final_data", len(final_data)) if debug: final_meta["query"] = json.loads(MessageToJson(table_request.rpc_request)) diff --git a/src/sentry/utils/sdk.py b/src/sentry/utils/sdk.py index f2768ad1f8d720..622217047fea3e 100644 --- a/src/sentry/utils/sdk.py +++ b/src/sentry/utils/sdk.py @@ -704,7 +704,7 @@ def set_measurement(measurement_name, value, unit=None): pass -def set_span_data(data_name, value): +def set_span_attribute(data_name, value): span = sentry_sdk.get_current_span() if span is not None: span.set_data(data_name, value)