Ë
    tPêjg  ã                   óª  — U d Z ddlZddlmZmZ ddlmZ ddlmZ ddl	m
Z
mZ ej                  d„ ej                  d„ ej                  d	„ ej                  d
„ ej                   d„ e
j"                  d„ ej$                  d„ iZeeeeeedz  eedf   gedz  f   f      ed<   ej                  ej                  ej                  ej                  e
j"                  ej$                  fZeeedf      ed<   dZeeedf      ed<   dZeeedf      ed<   eefdededz  deedf   deedf   deedf   deeef   fd„Zdeeef   dz  deedf   dedz  fd„Zy)aí  Baggage promotion: request-identity values carried across child spans.

A bounded set of identity values is written into OpenTelemetry Baggage on the
LLM-call span so that child spans (guardrail, service) inherit them.
``providers.LiteLLMBaggageSpanProcessor`` reads Baggage at span start and stamps
the allowlisted keys onto every span.

This module is the single place baggage is defined: ``_PROMOTABLE`` maps each
promotable attribute key to how its value is read, and the ``*_KEYS`` defaults
select what is promoted unless the config overrides them. ``TEAM_METADATA``'s
extractor filters the team's free-form metadata to the sub-keys an operator
allowlists via ``baggage_team_metadata_keys`` (default none), so the blob is
never promoted whole.
é    N)ÚCallableÚMapping)ÚFinal)ÚRequestIdentity)ÚGenAIÚLiteLLMc                 ó   — | j                   S ©N)Úteam_id©ÚidentityÚmodelÚteam_metadata_keyss      úl/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/integrations/otel/model/baggage.pyú<lambda>r      s   € À×AQÑAQ€ ó    c                 ó   — | j                   S r
   )Ú
team_aliasr   s      r   r   r      s   € ÀH×DWÑDW€ r   c                 ó.   — t        | j                  |«      S r
   )Ú_filtered_team_metadata_jsonÚteam_metadatar   s      r   r   r      s   € ÔGcØ×ÑÐ 2óH€ r   c                 ó   — | j                   S r
   )Úkey_hashr   s      r   r   r   !   ó   € À(×BSÑBS€ r   c                 ó   — | j                   S r
   )Úend_userr   s      r   r   r   "   r   r   c                 ó   — |S r
   © r   s      r   r   r   #   s   € ÀU€ r   c                 ó   — | j                   S r
   )Úprovider_modelr   s      r   r   r   $   s   € È×H_ÑH_€ r   .Ú_PROMOTABLEÚBAGGAGE_PROMOTED_KEYS)Úuser_api_key_org_idÚuser_api_key_user_idÚuser_api_key_aliasÚuser_api_key_end_user_idÚrequester_ip_addressÚDEFAULT_BAGGAGE_METADATA_KEYSr   Ú"DEFAULT_BAGGAGE_TEAM_METADATA_KEYSr   Úrequest_modelÚpromoted_keysÚmetadata_keysr   Úreturnc                 óè   — i }t         j                  «       D ]  \  }}||v sŒ || ||«      }|sŒ|||<   Œ |D ]7  }	| j                  j                  |	«      }|sŒ!||t        j
                  › |	› �<   Œ9 |S )au  Identity values to write into Baggage, filtered to ``promoted_keys``.

    ``promoted_keys`` selects from ``_PROMOTABLE``; ``metadata_keys`` selects
    sub-keys of ``identity.metadata`` to promote under ``litellm.metadata.*``;
    ``team_metadata_keys`` selects sub-keys of the team's metadata to promote
    under ``litellm.team.metadata``. Empty values are dropped.
    )r!   ÚitemsÚmetadataÚgetr   ÚMETADATA_PREFIX)
r   r*   r+   r,   r   ÚoutÚkeyÚextractÚvalueÚmeta_keys
             r   Úpromoted_baggager8   D   s•   € ð "$€CÜ#×)Ñ)Ó+ò !‰ˆˆWØ�-ÒÙ˜H mÐ5GÓHˆEÚØ ��C’ð	!ð
 "ò @ˆØ×!Ñ!×%Ñ% hÓ/ˆÚØ:?ˆC”7×*Ñ*Ð+¨H¨:Ð6Ò7ð@ð €Jr   r0   Úallowed_keysc                 ó    — t        | t        «      r|sy|D �ci c]  }|| v sŒ|| |   “Œ }}|syt        j                  |t        d¬«      S c c}w )a  JSON-serialize only the allowlisted sub-keys of a team's metadata.

    Returns ``None`` when nothing is allowlisted or no allowlisted key is
    present, so the empty case is dropped rather than promoting ``"{}"``. Keys
    are sorted for a stable, diff-friendly value.
    NT)ÚdefaultÚ	sort_keys)Ú
isinstancer   ÚjsonÚdumpsÚstr)r0   r9   r4   Úfiltereds       r   r   r   _   sT   € ô �h¤Ô(±ØØ5AÖU¨cÀSÈHÂ_�s˜H S™MÑ)ÐU€HÐUÙØÜ�:‰:�h¬°tÔ<Ð<ùò Vs
   ˜	A¢A)Ú__doc__r>   Úcollections.abcr   r   Útypingr   Ú(litellm.integrations.otel.model.metadatar   Ú'litellm.integrations.otel.model.semconvr   r   ÚTEAM_IDÚ
TEAM_ALIASÚTEAM_METADATAÚKEY_HASHÚEND_USERÚREQUEST_MODELÚPROVIDER_MODELr!   Údictr@   ÚtupleÚ__annotations__r"   r(   r)   r8   Úobjectr   r   r   r   ú<module>rR      sá  ðòó ß -Ý å Dß Bð ‡O�OÑQØ×ÑÑWØ×Ññ ð ×ÑÑSØ×ÑÑSØ	×ÑÑJØ×ÑÑ_ð
g€ˆU�4˜˜X ¸¸d¹
ÀEÈ#ÈsÈ(ÁOÐ&TÐVYÐ\`ÑV`Ð&`ÑaÐaÑbÑcó 
ð  ‡O�OØ×ÑØ×ÑØ×ÑØ	×ÑØ×Ñð1Ð �u˜U 3¨ 8™_Ñ-ó ð9Ð ˜u U¨3°¨8¡_Ñ5ó ð >@Ð " E¨%°°S°©/Ñ$:Ó ?ð &CØ*LñØðà˜‘:ðð ˜˜c˜‘?ðð ˜˜c˜‘?ð	ð
 ˜c 3˜h™ðð 
ˆ#ˆsˆ(�^óð6=Ø�c˜6�kÑ" TÑ)ð=à˜˜S˜‘/ð=ð 	ˆ4�Zô=r   