4141 _event_options ,
4242 _EventDefaults ,
4343 _fill_event_defaults ,
44+ _merge_groups ,
4445)
4546from .capture_send import _CAPTURE_V1_PATH
4647from .client import (
@@ -409,7 +410,6 @@ def _normalize_uuid(self, msg: dict[str, Any]) -> str:
409410 def _prepare_event (
410411 self ,
411412 msg : dict [str , Any ],
412- disable_geoip : Optional [bool ],
413413 property_allowlist = None ,
414414 ) -> tuple [Optional [dict [str , Any ]], Optional [str ]]:
415415 if self .disabled or not self ._accepting :
@@ -432,13 +432,7 @@ def _prepare_event(
432432 properties ["$lib" ] = "posthog-python"
433433 properties ["$lib_version" ] = VERSION
434434
435- if disable_geoip is None :
436- disable_geoip = self .disable_geoip
437- if disable_geoip :
438- properties ["$geoip_disable" ] = True
439435 msg ["options" ] = msg .get ("options" ) or {}
440- if self .is_server :
441- msg ["properties" ]["$is_server" ] = True
442436 if property_allowlist is not None :
443437 msg ["properties" ] = {
444438 key : value
@@ -481,7 +475,11 @@ def _event_defaults(
481475 context_options : Optional [dict [str , Any ]] = None ,
482476 derived_options : Optional [dict [str , Any ]] = None ,
483477 property_allowlist = None ,
478+ disable_geoip : Optional [bool ] = None ,
479+ system_properties : Optional [dict [str , Any ]] = None ,
484480 ) -> _EventDefaults :
481+ if disable_geoip is None :
482+ disable_geoip = self .disable_geoip
485483 return _build_event_defaults (
486484 super_properties = self .super_properties ,
487485 super_options = self .super_options ,
@@ -490,20 +488,23 @@ def _event_defaults(
490488 context_options = context_options ,
491489 derived_options = derived_options ,
492490 property_allowlist = property_allowlist ,
491+ is_server = self .is_server ,
492+ disable_geoip = disable_geoip ,
493+ system_properties = system_properties ,
493494 )
494495
495496 def _build_capture_event (
496497 self , event : str , kwargs : OptionalCaptureArgs
497- ) -> tuple [dict [str , Any ], Optional [ bool ], Any , _EventDefaults ]:
498- properties = { ** (kwargs .get ("properties" ) or {}), ** system_context ()}
498+ ) -> tuple [dict [str , Any ], Any , _EventDefaults ]:
499+ properties = dict (kwargs .get ("properties" ) or {})
499500 if self .capture_trace_context :
500501 properties = {** _get_current_otel_span_properties (), ** properties }
501502 properties = _add_context_session_id (properties )
502503
503504 distinct_id , personless = _get_identity_state (kwargs .get ("distinct_id" ))
504505 groups = kwargs .get ("groups" )
505506 if groups :
506- properties [ "$groups" ] = groups
507+ _merge_groups ( properties , groups )
507508
508509 flags_snapshot = kwargs .get ("flags" )
509510 send_feature_flags = kwargs .get ("send_feature_flags" )
@@ -526,13 +527,14 @@ def _build_capture_event(
526527 "uuid" : kwargs .get ("uuid" ),
527528 "options" : _event_options (kwargs .get ("options" )),
528529 },
529- kwargs .get ("disable_geoip" ),
530530 kwargs .get ("_property_allowlist" ),
531531 self ._event_defaults (
532532 context_properties = _context_tag_defaults (),
533533 context_options = _get_context_options (),
534534 derived_options = _personless_options (personless ),
535535 property_allowlist = kwargs .get ("_property_allowlist" ),
536+ disable_geoip = kwargs .get ("disable_geoip" ),
537+ system_properties = system_context (),
536538 ),
537539 )
538540
@@ -541,12 +543,8 @@ def capture(
541543 ) -> Optional [str ]:
542544 """Queue an event without blocking for network delivery."""
543545 try :
544- msg , disable_geoip , property_allowlist , defaults = (
545- self ._build_capture_event (event , kwargs )
546- )
547- prepared , sent_uuid = self ._prepare_event (
548- msg , disable_geoip , property_allowlist
549- )
546+ msg , property_allowlist , defaults = self ._build_capture_event (event , kwargs )
547+ prepared , sent_uuid = self ._prepare_event (msg , property_allowlist )
550548 if prepared is None or sent_uuid is None :
551549 return None
552550 if not self .send :
@@ -588,12 +586,8 @@ async def capture_immediate(
588586 self ._immediate_callers [current ] = self ._immediate_callers .get (current , 0 ) + 1
589587 error_batch : list [dict [str , Any ]] = []
590588 try :
591- msg , disable_geoip , property_allowlist , defaults = (
592- self ._build_capture_event (event , kwargs )
593- )
594- prepared , sent_uuid = self ._prepare_event (
595- msg , disable_geoip , property_allowlist
596- )
589+ msg , property_allowlist , defaults = self ._build_capture_event (event , kwargs )
590+ prepared , sent_uuid = self ._prepare_event (msg , property_allowlist )
597591 if prepared is None or sent_uuid is None :
598592 return None
599593 processed = await self ._process_event (prepared , defaults )
@@ -771,12 +765,14 @@ def _enqueue_built_event(
771765 disable_geoip : Optional [bool ],
772766 context_options : Optional [dict [str , Any ]] = None ,
773767 ) -> Optional [str ]:
774- prepared , sent_uuid = self ._prepare_event (msg , disable_geoip )
768+ prepared , sent_uuid = self ._prepare_event (msg )
775769 if prepared is None or sent_uuid is None :
776770 return None
777771 if not self .send :
778772 return sent_uuid
779- defaults = self ._event_defaults (context_options = context_options )
773+ defaults = self ._event_defaults (
774+ context_options = context_options , disable_geoip = disable_geoip
775+ )
780776 if not self ._enqueue_prepared_event (prepared , defaults ):
781777 return None
782778 return sent_uuid
0 commit comments