6767 from sentry_sdk .scope import Scope
6868 from sentry_sdk .session import Session
6969 from sentry_sdk .spotlight import SpotlightClient
70- from sentry_sdk .transport import Transport
70+ from sentry_sdk .transport import Transport , Item
7171 from sentry_sdk ._log_batcher import LogBatcher
7272 from sentry_sdk ._metrics_batcher import MetricsBatcher
73+ from sentry_sdk .utils import Dsn
7374
7475 I = TypeVar ("I" , bound = Integration ) # noqa: E741
7576
@@ -201,6 +202,11 @@ def dsn(self):
201202 # type: () -> Optional[str]
202203 return None
203204
205+ @property
206+ def parsed_dsn (self ):
207+ # type: () -> Optional[Dsn]
208+ return None
209+
204210 def should_send_default_pii (self ):
205211 # type: () -> bool
206212 return False
@@ -354,19 +360,23 @@ def _init_impl(self):
354360
355361 def _capture_envelope (envelope ):
356362 # type: (Envelope) -> None
363+ if self .spotlight is not None :
364+ self .spotlight .capture_envelope (envelope )
357365 if self .transport is not None :
358366 self .transport .capture_envelope (envelope )
359367
360368 def _record_lost_event (
361369 reason , # type: str
362370 data_category , # type: EventDataCategory
371+ item = None , # type: Optional[Item]
363372 quantity = 1 , # type: int
364373 ):
365374 # type: (...) -> None
366375 if self .transport is not None :
367376 self .transport .record_lost_event (
368377 reason = reason ,
369378 data_category = data_category ,
379+ item = item ,
370380 quantity = quantity ,
371381 )
372382
@@ -379,6 +389,18 @@ def _record_lost_event(
379389 if self .options ["enable_backpressure_handling" ]:
380390 self .monitor = Monitor (self .transport )
381391
392+ # Setup Spotlight before creating batchers so _capture_envelope can use it.
393+ # setup_spotlight handles all config/env var resolution per the SDK spec.
394+ from sentry_sdk .spotlight import setup_spotlight
395+
396+ self .spotlight = setup_spotlight (self .options )
397+ if self .spotlight is not None and not self .options ["dsn" ]:
398+ sample_all = lambda * _args , ** _kwargs : 1.0
399+ self .options ["send_default_pii" ] = True
400+ self .options ["error_sampler" ] = sample_all
401+ self .options ["traces_sampler" ] = sample_all
402+ self .options ["profiles_sampler" ] = sample_all
403+
382404 self .session_flusher = SessionFlusher (capture_func = _capture_envelope )
383405
384406 self .log_batcher = None
@@ -429,29 +451,6 @@ def _record_lost_event(
429451 options = self .options ,
430452 )
431453
432- spotlight_config = self .options .get ("spotlight" )
433- if spotlight_config is None and "SENTRY_SPOTLIGHT" in os .environ :
434- spotlight_env_value = os .environ ["SENTRY_SPOTLIGHT" ]
435- spotlight_config = env_to_bool (spotlight_env_value , strict = True )
436- self .options ["spotlight" ] = (
437- spotlight_config
438- if spotlight_config is not None
439- else spotlight_env_value
440- )
441-
442- if self .options .get ("spotlight" ):
443- # This is intentionally here to prevent setting up spotlight
444- # stuff we don't need unless spotlight is explicitly enabled
445- from sentry_sdk .spotlight import setup_spotlight
446-
447- self .spotlight = setup_spotlight (self .options )
448- if not self .options ["dsn" ]:
449- sample_all = lambda * _args , ** _kwargs : 1.0
450- self .options ["send_default_pii" ] = True
451- self .options ["error_sampler" ] = sample_all
452- self .options ["traces_sampler" ] = sample_all
453- self .options ["profiles_sampler" ] = sample_all
454-
455454 sdk_name = get_sdk_name (list (self .integrations .keys ()))
456455 SDK_INFO ["name" ] = sdk_name
457456 logger .debug ("Setting SDK name to '%s'" , sdk_name )
@@ -510,6 +509,12 @@ def dsn(self):
510509 """Returns the configured DSN as string."""
511510 return self .options ["dsn" ]
512511
512+ @property
513+ def parsed_dsn (self ):
514+ # type: () -> Optional[Dsn]
515+ """Returns the configured parsed DSN object."""
516+ return self .transport .parsed_dsn if self .transport else None
517+
513518 def _prepare_event (
514519 self ,
515520 event , # type: Event
0 commit comments