@@ -362,9 +362,30 @@ def get_global_scope(cls) -> "Scope":
362362 global _global_scope
363363 if _global_scope is None :
364364 _global_scope = Scope (ty = ScopeType .GLOBAL )
365+ _global_scope ._set_global_attributes ()
365366
366367 return _global_scope
367368
369+ def _set_global_attributes (self ) -> None :
370+ from sentry_sdk .client import SDK_INFO
371+
372+ self .set_attribute ("sentry.sdk.name" , SDK_INFO ["name" ])
373+ self .set_attribute ("sentry.sdk.version" , SDK_INFO ["version" ])
374+
375+ options = sentry_sdk .get_client ().options
376+
377+ server_name = options .get ("server_name" )
378+ if server_name :
379+ self .set_attribute (SPANDATA .SERVER_ADDRESS , server_name )
380+
381+ environment = options .get ("environment" )
382+ if environment :
383+ self .set_attribute ("sentry.environment" , environment )
384+
385+ release = options .get ("release" )
386+ if release :
387+ self .set_attribute ("sentry.release" , release )
388+
368389 @classmethod
369390 def last_event_id (cls ) -> "Optional[str]" :
370391 """
@@ -1468,33 +1489,6 @@ def _apply_flags_to_event(
14681489 {"values" : flags }
14691490 )
14701491
1471- def _apply_global_attributes_to_telemetry (
1472- self , telemetry : "Union[Log, Metric]"
1473- ) -> None :
1474- # TODO: Global stuff like this should just be retrieved at init time and
1475- # put onto the global scope's attributes and then applied to events
1476- # from there
1477- from sentry_sdk .client import SDK_INFO
1478-
1479- attributes = telemetry ["attributes" ]
1480-
1481- attributes ["sentry.sdk.name" ] = SDK_INFO ["name" ]
1482- attributes ["sentry.sdk.version" ] = SDK_INFO ["version" ]
1483-
1484- options = self .get_client ().options
1485-
1486- server_name = options .get ("server_name" )
1487- if server_name is not None and SPANDATA .SERVER_ADDRESS not in attributes :
1488- attributes [SPANDATA .SERVER_ADDRESS ] = server_name
1489-
1490- environment = options .get ("environment" )
1491- if environment is not None and "sentry.environment" not in attributes :
1492- attributes ["sentry.environment" ] = environment
1493-
1494- release = options .get ("release" )
1495- if release is not None and "sentry.release" not in attributes :
1496- attributes ["sentry.release" ] = release
1497-
14981492 def _apply_scope_attributes_to_telemetry (
14991493 self , telemetry : "Union[Log, Metric]"
15001494 ) -> None :
@@ -1638,7 +1632,6 @@ def apply_to_telemetry(self, telemetry: "Union[Log, Metric]") -> None:
16381632
16391633 self ._apply_scope_attributes_to_telemetry (telemetry )
16401634 self ._apply_user_attributes_to_telemetry (telemetry )
1641- self ._apply_global_attributes_to_telemetry (telemetry )
16421635
16431636 def update_from_scope (self , scope : "Scope" ) -> None :
16441637 """Update the scope with another scope's data."""
0 commit comments