/
server.py
4078 lines (3672 loc) · 162 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
These settings act as the default (base) settings for the Sentry-provided web-server
"""
from __future__ import annotations
import os
import os.path
import platform
import re
import socket
import sys
import tempfile
from collections.abc import Callable, Mapping, MutableSequence
from datetime import datetime, timedelta
from typing import Any, Final, Union, overload
from urllib.parse import urlparse
import sentry
from sentry.conf.types.consumer_definition import ConsumerDefinition
from sentry.conf.types.logging_config import LoggingConfig
from sentry.conf.types.role_dict import RoleDict
from sentry.conf.types.sdk_config import ServerSdkConfig
from sentry.conf.types.topic_definition import TopicDefinition
from sentry.utils import json # NOQA (used in getsentry config)
from sentry.utils.celery import crontab_with_minute_jitter
from sentry.utils.types import Type, type_from_value
def gettext_noop(s: str) -> str:
return s
socket.setdefaulttimeout(5)
_EnvTypes = Union[str, float, int, list, dict]
@overload
def env(key: str) -> str:
...
@overload
def env(key: str, default: _EnvTypes, type: Type | None = None) -> _EnvTypes:
...
def env(
key: str,
default: str | _EnvTypes = "",
type: Type | None = None,
) -> _EnvTypes:
"""
Extract an environment variable for use in configuration
:param key: The environment variable to be extracted.
:param default: The value to be returned if `key` is not found.
:param type: The type of the returned object (defaults to the type of `default`).
Type parsers must come from sentry.utils.types and not python stdlib.
:return: The environment variable if it exists, else `default`.
"""
# First check an internal cache, so we can `pop` multiple times
# without actually losing the value.
try:
rv = _env_cache[key]
except KeyError:
if "SENTRY_RUNNING_UWSGI" in os.environ:
# We do this so when the process forks off into uwsgi
# we want to actually be popping off values. This is so that
# at runtime, the variables aren't actually available.
fn: Callable[[str], str] = os.environ.pop
else:
fn = os.environ.__getitem__
try:
rv = fn(key)
_env_cache[key] = rv
except KeyError:
rv = default
if type is None:
type = type_from_value(default)
return type(rv)
_env_cache: dict[str, object] = {}
ENVIRONMENT = os.environ.get("SENTRY_ENVIRONMENT", "production")
NO_SPOTLIGHT = os.environ.get("NO_SPOTLIGHT", False)
IS_DEV = ENVIRONMENT == "development"
DEBUG = IS_DEV
# override the settings dumped in the debug view
DEFAULT_EXCEPTION_REPORTER_FILTER = (
"sentry.debug.utils.exception_reporter_filter.NoSettingsExceptionReporterFilter"
)
ADMINS = ()
# Hosts that are considered in the same network (including VPNs).
INTERNAL_IPS = ()
# List of IP subnets which should not be accessible
SENTRY_DISALLOWED_IPS = ()
# When resolving DNS for external sources (source map fetching, webhooks, etc),
# ensure that domains are fully resolved first to avoid poking internal
# search domains.
SENTRY_ENSURE_FQDN = False
# XXX [!!]: When adding a new key here BE SURE to configure it in getsentry, as
# it can not be `default`. The default cluster in sentry.io
# production is NOT a true redis cluster and WILL error in prod.
SENTRY_DYNAMIC_SAMPLING_RULES_REDIS_CLUSTER = "default"
SENTRY_INCIDENT_RULES_REDIS_CLUSTER = "default"
SENTRY_RATE_LIMIT_REDIS_CLUSTER = "default"
SENTRY_RULE_TASK_REDIS_CLUSTER = "default"
SENTRY_TRANSACTION_NAMES_REDIS_CLUSTER = "default"
SENTRY_WEBHOOK_LOG_REDIS_CLUSTER = "default"
SENTRY_ARTIFACT_BUNDLES_INDEXING_REDIS_CLUSTER = "default"
SENTRY_INTEGRATION_ERROR_LOG_REDIS_CLUSTER = "default"
SENTRY_DEBUG_FILES_REDIS_CLUSTER = "default"
SENTRY_MONITORS_REDIS_CLUSTER = "default"
SENTRY_STATISTICAL_DETECTORS_REDIS_CLUSTER = "default"
SENTRY_METRIC_META_REDIS_CLUSTER = "default"
SENTRY_ESCALATION_THRESHOLDS_REDIS_CLUSTER = "default"
SENTRY_SPAN_BUFFER_CLUSTER = "default"
# Hosts that are allowed to use system token authentication.
# http://en.wikipedia.org/wiki/Reserved_IP_addresses
INTERNAL_SYSTEM_IPS = (
"0.0.0.0/8",
"10.0.0.0/8",
"100.64.0.0/10",
"127.0.0.0/8",
"169.254.0.0/16",
"172.16.0.0/12",
"192.0.0.0/29",
"192.0.2.0/24",
"192.88.99.0/24",
"192.168.0.0/16",
"198.18.0.0/15",
"198.51.100.0/24",
"224.0.0.0/4",
"240.0.0.0/4",
"255.255.255.255/32",
)
MANAGERS = ADMINS
APPEND_SLASH = True
PROJECT_ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), os.pardir))
CONF_DIR = os.path.abspath(os.path.dirname(__file__))
# XXX(dcramer): handle case when we've installed from source vs just running
# this straight out of the repository
if "site-packages" in __file__:
NODE_MODULES_ROOT = os.path.join(PROJECT_ROOT, "node_modules")
else:
NODE_MODULES_ROOT = os.path.join(PROJECT_ROOT, os.pardir, os.pardir, "node_modules")
NODE_MODULES_ROOT = os.path.normpath(NODE_MODULES_ROOT)
DEVSERVICES_CONFIG_DIR = os.path.normpath(
os.path.join(PROJECT_ROOT, os.pardir, os.pardir, "config")
)
SENTRY_DISTRIBUTED_CLICKHOUSE_TABLES = False
RELAY_CONFIG_DIR = os.path.join(DEVSERVICES_CONFIG_DIR, "relay")
SYMBOLICATOR_CONFIG_DIR = os.path.join(DEVSERVICES_CONFIG_DIR, "symbolicator")
# XXX(epurkhiser): The generated chartucterie config.js file will be stored
# here. This directory may not exist until that file is generated.
CHARTCUTERIE_CONFIG_DIR = os.path.join(DEVSERVICES_CONFIG_DIR, "chartcuterie")
CDC_CONFIG_DIR = os.path.join(DEVSERVICES_CONFIG_DIR, "cdc")
sys.path.insert(0, os.path.normpath(os.path.join(PROJECT_ROOT, os.pardir)))
DATABASES = {
"default": {
"ENGINE": "sentry.db.postgres",
"NAME": "sentry",
"USER": "postgres",
"PASSWORD": "",
"HOST": "127.0.0.1",
"PORT": "",
"AUTOCOMMIT": True,
"ATOMIC_REQUESTS": False,
}
}
if "DATABASE_URL" in os.environ:
url = urlparse(os.environ["DATABASE_URL"])
# Update with environment configuration.
DATABASES["default"].update(
{
"NAME": url.path[1:],
"USER": url.username,
"PASSWORD": url.password,
"HOST": url.hostname,
"PORT": url.port,
}
)
# This should always be UTC.
TIME_ZONE = "UTC"
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = "en-us"
LANGUAGES: tuple[tuple[str, str], ...] = (
("af", gettext_noop("Afrikaans")),
("ar", gettext_noop("Arabic")),
("az", gettext_noop("Azerbaijani")),
("bg", gettext_noop("Bulgarian")),
("be", gettext_noop("Belarusian")),
("bn", gettext_noop("Bengali")),
("br", gettext_noop("Breton")),
("bs", gettext_noop("Bosnian")),
("ca", gettext_noop("Catalan")),
("cs", gettext_noop("Czech")),
("cy", gettext_noop("Welsh")),
("da", gettext_noop("Danish")),
("de", gettext_noop("German")),
("el", gettext_noop("Greek")),
("en", gettext_noop("English")),
("eo", gettext_noop("Esperanto")),
("es", gettext_noop("Spanish")),
("et", gettext_noop("Estonian")),
("eu", gettext_noop("Basque")),
("fa", gettext_noop("Persian")),
("fi", gettext_noop("Finnish")),
("fr", gettext_noop("French")),
("ga", gettext_noop("Irish")),
("gl", gettext_noop("Galician")),
("he", gettext_noop("Hebrew")),
("hi", gettext_noop("Hindi")),
("hr", gettext_noop("Croatian")),
("hu", gettext_noop("Hungarian")),
("ia", gettext_noop("Interlingua")),
("id", gettext_noop("Indonesian")),
("is", gettext_noop("Icelandic")),
("it", gettext_noop("Italian")),
("ja", gettext_noop("Japanese")),
("ka", gettext_noop("Georgian")),
("kk", gettext_noop("Kazakh")),
("km", gettext_noop("Khmer")),
("kn", gettext_noop("Kannada")),
("ko", gettext_noop("Korean")),
("lb", gettext_noop("Luxembourgish")),
("lt", gettext_noop("Lithuanian")),
("lv", gettext_noop("Latvian")),
("mk", gettext_noop("Macedonian")),
("ml", gettext_noop("Malayalam")),
("mn", gettext_noop("Mongolian")),
("my", gettext_noop("Burmese")),
("nb", gettext_noop("Norwegian Bokmal")),
("ne", gettext_noop("Nepali")),
("nl", gettext_noop("Dutch")),
("nn", gettext_noop("Norwegian Nynorsk")),
("os", gettext_noop("Ossetic")),
("pa", gettext_noop("Punjabi")),
("pl", gettext_noop("Polish")),
("pt", gettext_noop("Portuguese")),
("pt-br", gettext_noop("Brazilian Portuguese")),
("ro", gettext_noop("Romanian")),
("ru", gettext_noop("Russian")),
("sk", gettext_noop("Slovak")),
("sl", gettext_noop("Slovenian")),
("sq", gettext_noop("Albanian")),
("sr", gettext_noop("Serbian")),
("sv-se", gettext_noop("Swedish")),
("sw", gettext_noop("Swahili")),
("ta", gettext_noop("Tamil")),
("te", gettext_noop("Telugu")),
("th", gettext_noop("Thai")),
("tr", gettext_noop("Turkish")),
("tt", gettext_noop("Tatar")),
("udm", gettext_noop("Udmurt")),
("uk", gettext_noop("Ukrainian")),
("ur", gettext_noop("Urdu")),
("vi", gettext_noop("Vietnamese")),
("zh-cn", gettext_noop("Simplified Chinese")),
("zh-tw", gettext_noop("Traditional Chinese")),
)
from .locale import CATALOGS
LANGUAGES = tuple((code, name) for code, name in LANGUAGES if code in CATALOGS)
SUPPORTED_LANGUAGES = frozenset(CATALOGS)
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
USE_TZ = True
# CAVEAT: If you're adding a middleware that modifies a response's content,
# and appears before CommonMiddleware, you must either reorder your middleware
# so that responses aren't modified after Content-Length is set, or have the
# response modifying middleware reset the Content-Length header.
# This is because CommonMiddleware Sets the Content-Length header for non-streaming responses.
MIDDLEWARE: tuple[str, ...] = (
"csp.middleware.CSPMiddleware",
"sentry.middleware.health.HealthCheck",
"sentry.middleware.security.SecurityHeadersMiddleware",
"sentry.middleware.env.SentryEnvMiddleware",
"sentry.middleware.proxy.SetRemoteAddrFromForwardedFor",
"sentry.middleware.stats.RequestTimingMiddleware",
"sentry.middleware.access_log.access_log_middleware",
"sentry.middleware.stats.ResponseCodeMiddleware",
"sentry.middleware.subdomain.SubdomainMiddleware",
"django.middleware.common.CommonMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"sentry.middleware.auth.AuthenticationMiddleware",
"sentry.middleware.integrations.IntegrationControlMiddleware",
"sentry.middleware.api_gateway.ApiGatewayMiddleware",
"sentry.middleware.customer_domain.CustomerDomainMiddleware",
"sentry.middleware.sudo.SudoMiddleware",
"sentry.middleware.superuser.SuperuserMiddleware",
"sentry.middleware.staff.StaffMiddleware",
"sentry.middleware.locale.SentryLocaleMiddleware",
"sentry.middleware.ratelimit.RatelimitMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
)
ROOT_URLCONF = "sentry.conf.urls"
# TODO(joshuarli): Django 1.10 introduced this option, which restricts the size of a
# request body. We have some middleware in sentry.middleware.proxy that sets the
# Content Length to max uint32 in certain cases related to minidump.
# Once relay's fully rolled out, that can be deleted.
# Until then, the safest and easiest thing to do is to disable this check
# to leave things the way they were with Django <1.9.
DATA_UPLOAD_MAX_MEMORY_SIZE = None
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(PROJECT_ROOT, "templates")],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"django.template.context_processors.csrf",
"django.template.context_processors.request",
]
},
}
]
SENTRY_OUTBOX_MODELS: Mapping[str, list[str]] = {
"CONTROL": ["sentry.ControlOutbox"],
"REGION": ["sentry.RegionOutbox"],
}
# Do not modify reordering
# The applications listed first in INSTALLED_APPS have precedence
INSTALLED_APPS: tuple[str, ...] = (
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.messages",
"django.contrib.sessions",
"django.contrib.sites",
"drf_spectacular",
"crispy_forms",
"rest_framework",
"sentry",
"sentry.analytics",
"sentry.incidents.apps.Config",
"sentry.discover",
"sentry.analytics.events",
"sentry.nodestore",
"sentry.monitors",
"sentry.replays",
"sentry.release_health",
"sentry.search",
"sentry.sentry_metrics.indexer.postgres.apps.Config",
"sentry.snuba",
"sentry.lang.java.apps.Config",
"sentry.lang.javascript.apps.Config",
"sentry.plugins.sentry_interface_types.apps.Config",
"sentry.plugins.sentry_urls.apps.Config",
"sentry.plugins.sentry_useragents.apps.Config",
"sentry.plugins.sentry_webhooks.apps.Config",
"sentry.utils.suspect_resolutions.apps.Config",
"sentry.utils.suspect_resolutions_releases.apps.Config",
"social_auth",
"sudo",
"sentry.eventstream",
"sentry.auth.providers.google.apps.Config",
"sentry.auth.providers.fly.apps.Config",
"django.contrib.staticfiles",
"sentry.issues.apps.Config",
"sentry.feedback",
"sentry.hybridcloud",
)
# Silence internal hints from Django's system checks
SILENCED_SYSTEM_CHECKS = (
# Django recommends to use OneToOneField over ForeignKey(unique=True)
# however this changes application behavior in ways that break association
# loading
"fields.W342",
# We have a "catch-all" react_page_view that we only want to match on URLs
# ending with a `/` to allow APPEND_SLASHES to kick in for the ones lacking
# the trailing slash. This confuses the warning as the regex is `/$` which
# looks like it starts with a slash but it doesn't.
"urls.W002",
# Our own AuthenticationMiddleware suffices as a replacement for
# django.contrib.auth.middleware.AuthenticationMiddleware; both add the
# authenticated user to the HttpRequest which is what's needed here.
"admin.E408",
# This is fixed in Django@7c08f26bf0439c1ed593b51b51ad847f7e262bc1.
# It's not our problem; refer to Django issue 32260.
"urls.E007",
)
CSP_INCLUDE_NONCE_IN = [
"script-src",
]
CSP_DEFAULT_SRC = [
"'none'",
]
CSP_SCRIPT_SRC = [
"'self'",
"'unsafe-inline'",
"'report-sample'",
]
CSP_FONT_SRC = [
"'self'",
"data:",
]
CSP_CONNECT_SRC = [
"'self'",
"*.algolia.net",
"*.algolianet.com",
"*.algolia.io",
]
CSP_FRAME_ANCESTORS = [
"'none'",
]
CSP_OBJECT_SRC = [
"'none'",
]
CSP_WORKER_SRC = [
"'none'",
]
CSP_BASE_URI = [
"'none'",
]
CSP_STYLE_SRC = [
"'unsafe-inline'",
"*", # required for replays
]
CSP_IMG_SRC = [
"blob:",
"data:",
"*", # required for replays
]
CSP_MEDIA_SRC = [
"*", # required for replays
]
if ENVIRONMENT == "development":
CSP_SCRIPT_SRC += [
"'unsafe-eval'",
]
CSP_CONNECT_SRC += [
"ws://127.0.0.1:8000",
"http://localhost:8969/stream",
"webpack-internal:",
]
# Before enforcing Content Security Policy, we recommend creating a separate
# Sentry project and collecting CSP violations in report only mode:
# https://docs.sentry.io/product/security-policy-reporting/
# Point this parameter to your Sentry installation:
# CSP_REPORT_URI = "https://example.com/api/{PROJECT_ID}/security/?sentry_key={SENTRY_KEY}"
# To enforce CSP (block violated resources), update the following parameter to False
CSP_REPORT_ONLY = True
STATIC_ROOT = os.path.realpath(os.path.join(PROJECT_ROOT, "static"))
STATIC_URL = "/_static/{version}/"
# webpack assets live at a different URL that is unversioned
# as we configure webpack to include file content based hash in the filename
STATIC_FRONTEND_APP_URL = "/_static/dist/"
# The webpack output directory
STATICFILES_DIRS = [
os.path.join(STATIC_ROOT, "sentry", "dist"),
]
# various middleware will use this to identify resources which should not access
# cookies
ANONYMOUS_STATIC_PREFIXES = (
"/_static/",
"/avatar/",
"/organization-avatar/",
"/team-avatar/",
"/project-avatar/",
"/js-sdk-loader/",
)
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
)
ASSET_VERSION = 0
# setup a default media root to somewhere useless
MEDIA_ROOT = "/tmp/sentry-files"
MEDIA_URL = "_media/"
LOCALE_PATHS = (os.path.join(PROJECT_ROOT, "locale"),)
CSRF_FAILURE_VIEW = "sentry.web.frontend.csrf_failure.view"
CSRF_COOKIE_NAME = "sc"
# Auth configuration
from django.urls import reverse_lazy
LOGIN_REDIRECT_URL = reverse_lazy("sentry-login-redirect")
LOGIN_URL = reverse_lazy("sentry-login")
AUTHENTICATION_BACKENDS = (
"sentry.utils.auth.EmailAuthBackend",
# The following authentication backends are used by social auth only.
# We don't use them for user authentication.
"social_auth.backends.asana.AsanaBackend",
"social_auth.backends.github.GithubBackend",
"social_auth.backends.bitbucket.BitbucketBackend",
"social_auth.backends.visualstudio.VisualStudioBackend",
)
AUTH_PASSWORD_VALIDATORS: list[dict[str, Any]] = [
{"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
"OPTIONS": {"min_length": 8},
},
{
"NAME": "sentry.auth.password_validation.MaximumLengthValidator",
"OPTIONS": {"max_length": 256},
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
{
"NAME": "sentry.auth.password_validation.PwnedPasswordsValidator",
"OPTIONS": {"threshold": 20},
},
]
SOCIAL_AUTH_USER_MODEL = AUTH_USER_MODEL = "sentry.User"
SESSION_ENGINE = "django.contrib.sessions.backends.signed_cookies"
SESSION_COOKIE_NAME = "sentrysid"
# setting SESSION_COOKIE_SAMESITE to None below for now because
# Django's default in 2.1 now `Lax`.
# this breaks certain IDP flows where we need cookies sent to us on a redirected POST
# request, and `Lax` doesnt permit this.
# See here: https://docs.djangoproject.com/en/2.1/ref/settings/#session-cookie-samesite
SESSION_COOKIE_SAMESITE = None
BITBUCKET_CONSUMER_KEY = ""
BITBUCKET_CONSUMER_SECRET = ""
ASANA_CLIENT_ID = ""
ASANA_CLIENT_SECRET = ""
VISUALSTUDIO_APP_ID = ""
VISUALSTUDIO_APP_SECRET = ""
VISUALSTUDIO_CLIENT_SECRET = ""
VISUALSTUDIO_SCOPES = ["vso.work_write", "vso.project", "vso.code", "vso.release"]
SOCIAL_AUTH_PIPELINE = (
"social_auth.backends.pipeline.user.get_username",
"social_auth.backends.pipeline.social.social_auth_user",
"social_auth.backends.pipeline.associate.associate_by_email",
"social_auth.backends.pipeline.misc.save_status_to_session",
"social_auth.backends.pipeline.social.associate_user",
"social_auth.backends.pipeline.social.load_extra_data",
"social_auth.backends.pipeline.user.update_user_details",
"social_auth.backends.pipeline.misc.save_status_to_session",
)
SOCIAL_AUTH_REVOKE_TOKENS_ON_DISCONNECT = True
SOCIAL_AUTH_LOGIN_REDIRECT_URL = "/account/settings/identities/"
SOCIAL_AUTH_ASSOCIATE_ERROR_URL = SOCIAL_AUTH_LOGIN_REDIRECT_URL
INITIAL_CUSTOM_USER_MIGRATION = "0108_fix_user"
# Auth engines and the settings required for them to be listed
AUTH_PROVIDERS = {
"github": ("GITHUB_APP_ID", "GITHUB_API_SECRET"),
"bitbucket": ("BITBUCKET_CONSUMER_KEY", "BITBUCKET_CONSUMER_SECRET"),
"asana": ("ASANA_CLIENT_ID", "ASANA_CLIENT_SECRET"),
"visualstudio": (
"VISUALSTUDIO_APP_ID",
"VISUALSTUDIO_APP_SECRET",
"VISUALSTUDIO_CLIENT_SECRET",
),
}
AUTH_PROVIDER_LABELS = {
"github": "GitHub",
"bitbucket": "Bitbucket",
"asana": "Asana",
"visualstudio": "Visual Studio",
}
import random
def SOCIAL_AUTH_DEFAULT_USERNAME() -> str:
return random.choice(["Darth Vader", "Obi-Wan Kenobi", "R2-D2", "C-3PO", "Yoda"])
SOCIAL_AUTH_PROTECTED_USER_FIELDS = ["email"]
SOCIAL_AUTH_FORCE_POST_DISCONNECT = True
# Hybrid cloud multi-silo configuration #
# Defined by `sentry devserver` to enable siloed local development
SILO_DEVSERVER = os.environ.get("SENTRY_SILO_DEVSERVER", False)
# Which silo this instance runs as (CONTROL|REGION|MONOLITH|None) are the expected values
SILO_MODE = os.environ.get("SENTRY_SILO_MODE", None)
# If this instance is a region silo, which region is it running in?
SENTRY_REGION = os.environ.get("SENTRY_REGION", None)
# Returns the customer single tenant ID.
CUSTOMER_ID = os.environ.get("CUSTOMER_ID", None)
# List of the available regions, or a JSON string
# that is parsed.
SENTRY_REGION_CONFIG: Any = ()
# Shared secret used to sign cross-region RPC requests.
RPC_SHARED_SECRET: list[str] | None = None
# Timeout for RPC requests between regions
RPC_TIMEOUT = 5.0
# Shared secret used to sign cross-region RPC requests with the seer microservice.
SEER_RPC_SHARED_SECRET: list[str] | None = None
# The protocol, host and port for control silo
# Usecases include sending requests to the Integration Proxy Endpoint and RPC requests.
SENTRY_CONTROL_ADDRESS: str | None = os.environ.get("SENTRY_CONTROL_ADDRESS", None)
# Fallback region name for monolith deployments
# This region name is also used by the ApiGateway to proxy org-less region
# requests.
SENTRY_MONOLITH_REGION: str = "--monolith--"
# The key used for generating or verifying the HMAC signature for Integration Proxy Endpoint requests.
SENTRY_SUBNET_SECRET = os.environ.get("SENTRY_SUBNET_SECRET", None)
# Queue configuration
from kombu import Exchange, Queue
BROKER_URL = "redis://127.0.0.1:6379"
BROKER_TRANSPORT_OPTIONS: dict[str, int] = {}
# Ensure workers run async by default
# in Development you might want them to run in-process
# though it would cause timeouts/recursions in some cases
CELERY_ALWAYS_EAGER = False
# Complain about bad use of pickle. See sentry.celery.SentryTask.apply_async for how
# this works.
CELERY_COMPLAIN_ABOUT_BAD_USE_OF_PICKLE = False
# We use the old task protocol because during benchmarking we noticed that it's faster
# than the new protocol. If we ever need to bump this it should be fine, there were no
# compatibility issues, just need to run benchmarks and do some tests to make sure
# things run ok.
CELERY_TASK_PROTOCOL = 1
CELERY_EAGER_PROPAGATES_EXCEPTIONS = True
CELERY_IGNORE_RESULT = True
CELERY_SEND_EVENTS = False
CELERY_RESULT_BACKEND = None
CELERY_TASK_RESULT_EXPIRES = 1
CELERY_DISABLE_RATE_LIMITS = True
CELERY_DEFAULT_QUEUE = "default"
CELERY_DEFAULT_EXCHANGE = "default"
CELERY_DEFAULT_EXCHANGE_TYPE = "direct"
CELERY_DEFAULT_ROUTING_KEY = "default"
CELERY_CREATE_MISSING_QUEUES = True
CELERY_REDIRECT_STDOUTS = False
CELERYD_HIJACK_ROOT_LOGGER = False
CELERY_TASK_SERIALIZER = "pickle"
CELERY_RESULT_SERIALIZER = "pickle"
CELERY_ACCEPT_CONTENT = {"pickle"}
CELERY_IMPORTS = (
"sentry.data_export.tasks",
"sentry.discover.tasks",
"sentry.hybridcloud.tasks.deliver_webhooks",
"sentry.incidents.tasks",
"sentry.snuba.tasks",
"sentry.replays.tasks",
"sentry.monitors.tasks",
"sentry.tasks.ai_autofix",
"sentry.tasks.app_store_connect",
"sentry.tasks.assemble",
"sentry.tasks.auth",
"sentry.tasks.auto_remove_inbox",
"sentry.tasks.auto_resolve_issues",
"sentry.tasks.backfill_outboxes",
"sentry.tasks.beacon",
"sentry.tasks.check_auth",
"sentry.tasks.clear_expired_snoozes",
"sentry.tasks.clear_expired_rulesnoozes",
"sentry.tasks.codeowners.code_owners_auto_sync",
"sentry.tasks.codeowners.update_code_owners_schema",
"sentry.tasks.collect_project_platforms",
"sentry.tasks.commits",
"sentry.tasks.commit_context",
"sentry.tasks.deletion",
"sentry.tasks.deletion.scheduled",
"sentry.tasks.deletion.groups",
"sentry.tasks.deletion.hybrid_cloud",
"sentry.tasks.deliver_from_outbox",
"sentry.tasks.digests",
"sentry.tasks.email",
"sentry.tasks.files",
"sentry.tasks.groupowner",
"sentry.tasks.integrations",
"sentry.tasks.invite_missing_org_members",
"sentry.tasks.low_priority_symbolication",
"sentry.tasks.merge",
"sentry.tasks.options",
"sentry.tasks.ping",
"sentry.tasks.post_process",
"sentry.tasks.process_buffer",
"sentry.tasks.recap_servers",
"sentry.tasks.relay",
"sentry.tasks.release_registry",
"sentry.tasks.relocation",
"sentry.tasks.summaries.weekly_reports",
"sentry.tasks.summaries.daily_summary",
"sentry.tasks.reprocessing",
"sentry.tasks.reprocessing2",
"sentry.tasks.sentry_apps",
"sentry.tasks.servicehooks",
"sentry.tasks.spans",
"sentry.tasks.store",
"sentry.tasks.symbolication",
"sentry.tasks.unmerge",
"sentry.tasks.update_user_reports",
"sentry.tasks.user_report",
"sentry.profiles.task",
"sentry.release_health.tasks",
"sentry.dynamic_sampling.tasks.boost_low_volume_projects",
"sentry.dynamic_sampling.tasks.boost_low_volume_transactions",
"sentry.dynamic_sampling.tasks.recalibrate_orgs",
"sentry.dynamic_sampling.tasks.sliding_window_org",
"sentry.dynamic_sampling.tasks.utils",
"sentry.dynamic_sampling.tasks.custom_rule_notifications",
"sentry.utils.suspect_resolutions.get_suspect_resolutions",
"sentry.utils.suspect_resolutions_releases.get_suspect_resolutions_releases",
"sentry.tasks.derive_code_mappings",
"sentry.ingest.transaction_clusterer.tasks",
"sentry.tasks.auto_enable_codecov",
"sentry.tasks.weekly_escalating_forecast",
"sentry.tasks.auto_ongoing_issues",
"sentry.tasks.check_am2_compatibility",
"sentry.dynamic_sampling.tasks.collect_orgs",
"sentry.tasks.statistical_detectors",
"sentry.debug_files.tasks",
"sentry.tasks.on_demand_metrics",
"sentry.middleware.integrations.tasks",
"sentry.replays.usecases.ingest.issue_creation",
)
default_exchange = Exchange("default", type="direct")
control_exchange = default_exchange
if SILO_DEVSERVER:
control_exchange = Exchange("control", type="direct")
CELERY_QUEUES_CONTROL = [
Queue("app_platform.control", routing_key="app_platform.control", exchange=control_exchange),
Queue("auth.control", routing_key="auth.control", exchange=control_exchange),
Queue("cleanup.control", routing_key="cleanup.control", exchange=control_exchange),
Queue("email.control", routing_key="email.control", exchange=control_exchange),
Queue("integrations.control", routing_key="integrations.control", exchange=control_exchange),
Queue("files.delete.control", routing_key="files.delete.control", exchange=control_exchange),
Queue(
"hybrid_cloud.control_repair",
routing_key="hybrid_cloud.control_repair",
exchange=control_exchange,
),
Queue("options.control", routing_key="options.control", exchange=control_exchange),
Queue("outbox.control", routing_key="outbox.control", exchange=control_exchange),
Queue("webhook.control", routing_key="webhook.control", exchange=control_exchange),
]
CELERY_ISSUE_STATES_QUEUE = Queue(
"auto_transition_issue_states", routing_key="auto_transition_issue_states"
)
CELERY_QUEUES_REGION = [
Queue("activity.notify", routing_key="activity.notify"),
Queue("auth", routing_key="auth"),
Queue("alerts", routing_key="alerts"),
Queue("app_platform", routing_key="app_platform"),
Queue("appstoreconnect", routing_key="sentry.tasks.app_store_connect.#"),
Queue("assemble", routing_key="assemble"),
Queue("buffers.process_pending", routing_key="buffers.process_pending"),
Queue("buffers.incr", routing_key="buffers.incr"),
Queue("cleanup", routing_key="cleanup"),
Queue("code_owners", routing_key="code_owners"),
Queue("commits", routing_key="commits"),
Queue("data_export", routing_key="data_export"),
Queue("default", routing_key="default"),
Queue("digests.delivery", routing_key="digests.delivery"),
Queue("digests.scheduling", routing_key="digests.scheduling"),
Queue("email", routing_key="email"),
Queue("email.inbound", routing_key="email.inbound"),
Queue("events.preprocess_event", routing_key="events.preprocess_event"),
Queue("events.process_event", routing_key="events.process_event"),
Queue("events.process_event_proguard", routing_key="events.process_event_proguard"),
Queue("events.reprocess_events", routing_key="events.reprocess_events"),
Queue(
"events.reprocessing.preprocess_event", routing_key="events.reprocessing.preprocess_event"
),
Queue("events.reprocessing.process_event", routing_key="events.reprocessing.process_event"),
Queue(
"events.reprocessing.symbolicate_event", routing_key="events.reprocessing.symbolicate_event"
),
Queue(
"events.reprocessing.symbolicate_event_low_priority",
routing_key="events.reprocessing.symbolicate_event_low_priority",
),
Queue("events.save_event", routing_key="events.save_event"),
Queue("events.save_event_highcpu", routing_key="events.save_event_highcpu"),
Queue("events.save_event_transaction", routing_key="events.save_event_transaction"),
Queue("events.save_event_attachments", routing_key="events.save_event_attachments"),
Queue("events.symbolicate_event", routing_key="events.symbolicate_event"),
Queue(
"events.symbolicate_event_low_priority", routing_key="events.symbolicate_event_low_priority"
),
Queue("events.symbolicate_js_event", routing_key="events.symbolicate_js_event"),
Queue(
"events.symbolicate_js_event_low_priority",
routing_key="events.symbolicate_js_event_low_priority",
),
Queue("files.copy", routing_key="files.copy"),
Queue("files.delete", routing_key="files.delete"),
Queue(
"group_owners.process_suspect_commits", routing_key="group_owners.process_suspect_commits"
),
Queue("group_owners.process_commit_context", routing_key="group_owners.process_commit_context"),
Queue("integrations", routing_key="integrations"),
Queue(
"releasemonitor",
routing_key="releasemonitor",
),
Queue(
"dynamicsampling",
routing_key="dynamicsampling",
),
Queue("incidents", routing_key="incidents"),
Queue("incident_snapshots", routing_key="incident_snapshots"),
Queue("incidents", routing_key="incidents"),
Queue("merge", routing_key="merge"),
Queue("notifications", routing_key="notifications"),
Queue("options", routing_key="options"),
Queue("outbox", routing_key="outbox"),
Queue("post_process_errors", routing_key="post_process_errors"),
Queue("post_process_issue_platform", routing_key="post_process_issue_platform"),
Queue("post_process_transactions", routing_key="post_process_transactions"),
Queue("relay_config", routing_key="relay_config"),
Queue("relay_config_bulk", routing_key="relay_config_bulk"),
Queue("reports.deliver", routing_key="reports.deliver"),
Queue("reports.prepare", routing_key="reports.prepare"),
Queue("search", routing_key="search"),
Queue("sentry_metrics.indexer", routing_key="sentry_metrics.indexer"),
Queue("similarity.index", routing_key="similarity.index"),
Queue("sleep", routing_key="sleep"),
Queue("stats", routing_key="stats"),
Queue("subscriptions", routing_key="subscriptions"),
Queue(
"symbolications.compute_low_priority_projects",
routing_key="symbolications.compute_low_priority_projects",
),
Queue("unmerge", routing_key="unmerge"),
Queue("update", routing_key="update"),
Queue("profiles.process", routing_key="profiles.process"),
Queue("get_suspect_resolutions", routing_key="get_suspect_resolutions"),
Queue("get_suspect_resolutions_releases", routing_key="get_suspect_resolutions_releases"),
Queue("replays.ingest_replay", routing_key="replays.ingest_replay"),
Queue("replays.delete_replay", routing_key="replays.delete_replay"),
Queue("counters-0", routing_key="counters-0"),
Queue("triggers-0", routing_key="triggers-0"),
Queue("derive_code_mappings", routing_key="derive_code_mappings"),
Queue("transactions.name_clusterer", routing_key="transactions.name_clusterer"),
Queue("auto_enable_codecov", routing_key="auto_enable_codecov"),
Queue("weekly_escalating_forecast", routing_key="weekly_escalating_forecast"),
Queue("relocation", routing_key="relocation"),
Queue("recap_servers", routing_key="recap_servers"),
Queue("performance.statistical_detector", routing_key="performance.statistical_detector"),
Queue("profiling.statistical_detector", routing_key="profiling.statistical_detector"),
CELERY_ISSUE_STATES_QUEUE,
Queue("nudge.invite_missing_org_members", routing_key="invite_missing_org_members"),
Queue("auto_resolve_issues", routing_key="auto_resolve_issues"),
Queue("on_demand_metrics", routing_key="on_demand_metrics"),
Queue("spans.process_segment", routing_key="spans.process_segment"),
]
from celery.schedules import crontab
# Only tasks that work with users/integrations and shared subsystems
# are run in control silo.
CELERYBEAT_SCHEDULE_CONTROL = {
"check-auth": {
"task": "sentry.tasks.check_auth",
# Run every 1 minute
"schedule": crontab(minute="*/1"),
"options": {"expires": 60, "queue": "auth.control"},
},
"sync-options-control": {
"task": "sentry.tasks.options.sync_options_control",
"schedule": timedelta(seconds=10),
"options": {"expires": 10, "queue": "options.control"},
},
"deliver-from-outbox-control": {
"task": "sentry.tasks.enqueue_outbox_jobs_control",
# Run every 10 seconds to keep consistency times low
"schedule": timedelta(seconds=10),
"options": {"expires": 60, "queue": "outbox.control"},
},
"schedule-deletions-control": {
"task": "sentry.tasks.deletion.run_scheduled_deletions_control",
# Run every 15 minutes
"schedule": crontab(minute="*/15"),
"options": {"expires": 60 * 25, "queue": "cleanup.control"},
},
"reattempt-deletions-control": {
"task": "sentry.tasks.deletion.reattempt_deletions_control",
"schedule": crontab(hour="10", minute="0"), # 03:00 PDT, 07:00 EDT, 10:00 UTC
"options": {"expires": 60 * 25, "queue": "cleanup.control"},
},
"schedule-hybrid-cloud-foreign-key-jobs-control": {
"task": "sentry.tasks.deletion.hybrid_cloud.schedule_hybrid_cloud_foreign_key_jobs_control",
# Run every 15 minutes
"schedule": crontab(minute="*/15"),
"options": {"queue": "cleanup.control"},
},
"schedule-vsts-integration-subscription-check": {
"task": "sentry.tasks.integrations.kickoff_vsts_subscription_check",
"schedule": crontab_with_minute_jitter(hour="*/6"),
"options": {"expires": 60 * 25, "queue": "integrations.control"},
},
"deliver-webhooks-control": {
"task": "sentry.hybridcloud.tasks.deliver_webhooks.schedule_webhook_delivery",
# Run every 10 seconds as integration webhooks are delivered by this task
"schedule": timedelta(seconds=10),
"options": {"expires": 60, "queue": "webhook.control"},
},
}
# Most tasks run in the regions
CELERYBEAT_SCHEDULE_REGION = {
"send-beacon": {
"task": "sentry.tasks.send_beacon",
# Run every hour