Skip to content

Commit 270094f

Browse files
authored
ref(sdk): Remove excessive json.loads spans (#64883)
### Summary Many of our transactions use up their span limit immediately because of json.loads creating spans for every field call etc. ![Screenshot 2024-02-08 at 11 25 04 AM](https://github.com/getsentry/sentry/assets/6111995/cc5181cf-845a-4546-9703-8989c68d0a52) I ran the devserver and tried a couple endpoints and removed spans for anything I saw spamming. Feel free to re-add it if you find a python profile for your transaction that shows json.loads is taking up a significant amount of time, I'm just trying to get most of them that concern me at the moment without opening a bunch of PRs one by one. In the future we should probably consider moving these over to a metric as the span offers no additional information, so we can avoid this altogether. At the moment, since json can be called at startup there is currently an issue with config not being loaded so metrics can be used here so that would need to be resolved first.
1 parent 6013463 commit 270094f

File tree

6 files changed

+10
-8
lines changed

6 files changed

+10
-8
lines changed

src/sentry/db/models/fields/jsonfield.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def get_default(self):
8383
if callable(default):
8484
default = default()
8585
if isinstance(default, str):
86-
return json.loads(default)
87-
return json.loads(json.dumps(default))
86+
return json.loads(default, skip_trace=True)
87+
return json.loads(json.dumps(default), skip_trace=True)
8888
return super().get_default()
8989

9090
def get_internal_type(self):
@@ -101,7 +101,7 @@ def to_python(self, value):
101101
if self.blank:
102102
return ""
103103
try:
104-
value = json.loads(value)
104+
value = json.loads(value, skip_trace=True)
105105
except ValueError:
106106
msg = self.error_messages["invalid"] % value
107107
raise ValidationError(msg)

src/sentry/db/models/fields/picklefield.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ def to_python(self, value):
2626
if value is None:
2727
return None
2828
try:
29-
return json.loads(value)
29+
return json.loads(value, skip_trace=True)
3030
except (ValueError, TypeError):
3131
return super().to_python(value)

src/sentry/ingest/billing_metrics_consumer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ def submit(self, message: Message[KafkaPayload]) -> None:
8585
self.__next_step.submit(message)
8686

8787
def _get_payload(self, message: Message[KafkaPayload]) -> GenericMetric:
88-
payload = json.loads(message.payload.value.decode("utf-8"), use_rapid_json=True)
88+
payload = json.loads(
89+
message.payload.value.decode("utf-8"), use_rapid_json=True, skip_trace=True
90+
)
8991
return cast(GenericMetric, payload)
9092

9193
def _count_processed_items(self, generic_metric: GenericMetric) -> Mapping[DataCategory, int]:

src/sentry/ingest/consumer/processors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def process_event(message: IngestMessage, project: Project) -> None:
106106
# serializing it again.
107107
# XXX: Do not use CanonicalKeyDict here. This may break preprocess_event
108108
# which assumes that data passed in is a raw dictionary.
109-
data = json.loads(payload, use_rapid_json=True)
109+
data = json.loads(payload, use_rapid_json=True, skip_trace=True)
110110
if project_id == settings.SENTRY_PROJECT:
111111
metrics.incr(
112112
"internal.captured.ingest_consumer.parsed",

src/sentry/utils/codecs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def encode(self, value: JSONData) -> str:
7575
return str(json.dumps(value))
7676

7777
def decode(self, value: str) -> JSONData:
78-
return json.loads(value)
78+
return json.loads(value, skip_trace=True)
7979

8080

8181
class ZlibCodec(Codec[bytes, bytes]):

src/sentry/utils/snuba.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ def _bulk_snuba_query(
958958
for index, item in enumerate(query_results):
959959
response, _, reverse = item
960960
try:
961-
body = json.loads(response.data)
961+
body = json.loads(response.data, skip_trace=True)
962962
if SNUBA_INFO:
963963
if "sql" in body:
964964
print( # NOQA: only prints when an env variable is set

0 commit comments

Comments
 (0)