Skip to content

Commit 7eb792b

Browse files
authored
feat(insights): add has_insights_xx span project flags (#72904)
Adds `has_insights_xx` flags for each insight module to track whether a project has sent spans for that insight module. These flags are used to determine whether to show the empty state screen when the user visits an insight module. Our current approach involves scanning through the past 90 days of metrics data to check for any matching spans, which is extremely inefficient. With these new project flags, we can avoid a table scan and improve insight module page load times by 2-3 seconds.
1 parent 5769ee3 commit 7eb792b

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

migrations_lockfile.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ feedback: 0004_index_together
99
hybridcloud: 0016_add_control_cacheversion
1010
nodestore: 0002_nodestore_no_dictfield
1111
replays: 0004_index_together
12-
sentry: 0730_add_subscription_fk_to_incident
12+
sentry: 0731_add_insight_project_flags
1313
social_auth: 0002_default_auto_field
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Generated by Django 5.0.6 on 2024-06-17 21:29
2+
3+
from django.db import migrations
4+
5+
import bitfield.models
6+
from sentry.new_migrations.migrations import CheckedMigration
7+
8+
9+
class Migration(CheckedMigration):
10+
# This flag is used to mark that a migration shouldn't be automatically run in production.
11+
# This should only be used for operations where it's safe to run the migration after your
12+
# code has deployed. So this should not be used for most operations that alter the schema
13+
# of a table.
14+
# Here are some things that make sense to mark as post deployment:
15+
# - Large data migrations. Typically we want these to be run manually so that they can be
16+
# monitored and not block the deploy for a long period of time while they run.
17+
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
18+
# run this outside deployments so that we don't block them. Note that while adding an index
19+
# is a schema change, it's completely safe to run the operation after the code has deployed.
20+
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment
21+
22+
is_post_deployment = False
23+
24+
dependencies = [
25+
("sentry", "0730_add_subscription_fk_to_incident"),
26+
]
27+
28+
operations = [
29+
migrations.AlterField(
30+
model_name="project",
31+
name="flags",
32+
field=bitfield.models.BitField(
33+
[
34+
"has_releases",
35+
"has_issue_alerts_targeting",
36+
"has_transactions",
37+
"has_alert_filters",
38+
"has_sessions",
39+
"has_profiles",
40+
"has_replays",
41+
"has_feedbacks",
42+
"has_new_feedbacks",
43+
"spike_protection_error_currently_active",
44+
"spike_protection_transaction_currently_active",
45+
"spike_protection_attachment_currently_active",
46+
"has_minified_stack_trace",
47+
"has_cron_monitors",
48+
"has_cron_checkins",
49+
"has_sourcemaps",
50+
"has_custom_metrics",
51+
"has_high_priority_alerts",
52+
"has_insights_http",
53+
"has_insights_db",
54+
"has_insights_assets",
55+
"has_insights_app_start",
56+
"has_insights_screen_load",
57+
"has_insights_vitals",
58+
"has_insights_caches",
59+
"has_insights_queues",
60+
"has_insights_llm_monitoring",
61+
],
62+
default=10,
63+
null=True,
64+
),
65+
),
66+
]

src/sentry/models/project.py

+27
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,33 @@ class flags(TypedClassBitField):
306306
# This Project has enough issue volume to use high priority alerts
307307
has_high_priority_alerts: bool
308308

309+
# This Project has sent insight request spans
310+
has_insights_http: bool
311+
312+
# This Project has sent insight db spans
313+
has_insights_db: bool
314+
315+
# This Project has sent insight assets spans
316+
has_insights_assets: bool
317+
318+
# This Project has sent insight app starts spans
319+
has_insights_app_start: bool
320+
321+
# This Project has sent insight screen load spans
322+
has_insights_screen_load: bool
323+
324+
# This Project has sent insight vitals spans
325+
has_insights_vitals: bool
326+
327+
# This Project has sent insight caches spans
328+
has_insights_caches: bool
329+
330+
# This Project has sent insight queues spans
331+
has_insights_queues: bool
332+
333+
# This Project has sent insight llm monitoring spans
334+
has_insights_llm_monitoring: bool
335+
309336
bitfield_default = 10
310337
bitfield_null = True
311338

0 commit comments

Comments
 (0)