3030 validate_int_setter ,
3131 validate_path_setter
3232)
33- from bugsnag .delivery import (create_default_delivery , DEFAULT_ENDPOINT ,
34- DEFAULT_SESSIONS_ENDPOINT )
33+ from bugsnag .delivery import (create_default_delivery ,
34+ DEFAULT_ENDPOINT ,
35+ DEFAULT_SESSIONS_ENDPOINT ,
36+ HUB_ENDPOINT ,
37+ HUB_SESSIONS_ENDPOINT )
3538from bugsnag .uwsgi import warn_if_running_uwsgi_without_threads
3639from bugsnag .error import Error
3740
5558_sentinel = object ()
5659
5760
61+ def _is_hub_api_key (api_key : str ) -> bool :
62+ hub_prefix = "00000"
63+ return api_key is not None and api_key .startswith (hub_prefix )
64+
65+
5866class Configuration :
5967 """
6068 Global app-level Bugsnag configuration settings.
@@ -83,8 +91,8 @@ def __init__(self, logger=_sentinel):
8391 "django.http.Http404" ,
8492 "django.http.response.Http404" ,
8593 ]
86- self .endpoint = DEFAULT_ENDPOINT
87- self .session_endpoint = DEFAULT_SESSIONS_ENDPOINT
94+ self .endpoint = None
95+ self .session_endpoint = None
8896 self .auto_capture_sessions = True
8997 self .traceback_exclude_modules = []
9098
@@ -126,8 +134,6 @@ def configure(self, api_key=None, app_type=None, app_version=None,
126134 Validate and set configuration options. Will warn if an option is of an
127135 incorrect type.
128136 """
129- if api_key is not None :
130- self .api_key = api_key
131137 if app_type is not None :
132138 self .app_type = app_type
133139 if app_version is not None :
@@ -140,8 +146,6 @@ def configure(self, api_key=None, app_type=None, app_version=None,
140146 self .auto_capture_sessions = auto_capture_sessions
141147 if delivery is not None :
142148 self .delivery = delivery
143- if endpoint is not None :
144- self .endpoint = endpoint
145149 if hostname is not None :
146150 self .hostname = hostname
147151 if ignore_classes is not None :
@@ -162,8 +166,6 @@ def configure(self, api_key=None, app_type=None, app_version=None,
162166 self .send_code = send_code
163167 if send_environment is not None :
164168 self .send_environment = send_environment
165- if session_endpoint is not None :
166- self .session_endpoint = session_endpoint
167169 if traceback_exclude_modules is not None :
168170 self .traceback_exclude_modules = traceback_exclude_modules
169171 if logger is not _sentinel :
@@ -175,6 +177,11 @@ def configure(self, api_key=None, app_type=None, app_version=None,
175177 if max_breadcrumbs is not None :
176178 self .max_breadcrumbs = max_breadcrumbs
177179
180+ # Default endpoints depend on the API key
181+ if api_key is not None :
182+ self .api_key = api_key
183+ self ._initialize_endpoints (endpoint , session_endpoint , self .api_key )
184+
178185 return self
179186
180187 def get (self , name ):
@@ -584,6 +591,26 @@ def _create_null_logger(self) -> logging.Logger:
584591
585592 return logger
586593
594+ def _initialize_endpoints (self , endpoint , session_endpoint , api_key ):
595+ # Default endpoints depending on the API key, if not already set
596+ if (
597+ endpoint is None and
598+ session_endpoint is None and
599+ self .endpoint is None and
600+ self .session_endpoint is None
601+ ):
602+ if _is_hub_api_key (api_key ):
603+ self .endpoint = HUB_ENDPOINT
604+ self .session_endpoint = HUB_SESSIONS_ENDPOINT
605+ else :
606+ self .endpoint = DEFAULT_ENDPOINT
607+ self .session_endpoint = DEFAULT_SESSIONS_ENDPOINT
608+ # Do set endpoints if explicitly provided
609+ if endpoint is not None :
610+ self .endpoint = endpoint
611+ if session_endpoint is not None :
612+ self .session_endpoint = session_endpoint
613+
587614
588615class RequestConfiguration :
589616 """
0 commit comments