� B�g�(���UddlmZddlZddlZddlZddlZddlmZmZm Z m Z m Z m Z ddl mZddlmZeje��ZeZe d��Ze d��Zej��Zded <dad ed <d d gZded<Gd�d��ZGd�de eefej���Zej d%d���Z!d&d�Z"d'd�Z#d(d�Z$d)d �Z%d*d$�Z&dS)+�)� annotationsN)�Any� Generator�Generic�List�Optional�TypeVar)�cygrpc)�ChannelArgumentType�ClientCallTracerCapsule�ServerCallTracerFactoryCapsulezthreading.RLock� _plugin_lockzOptional['ObservabilityPlugin']�_OBSERVABILITY_PLUGINs"google.monitoring.v3.MetricServices*google.devtools.cloudtrace.v2.TraceServicez List[bytes]�_SERVICES_TO_EXCLUDEc��eZdZdZd�Zd�ZdS)�ServerCallTracerFactoryz�An encapsulation of a ServerCallTracerFactory. Instances of this class can be passed to a Channel as values for the grpc.experimental.server_call_tracer_factory option c��||_dS�N��_address)�self�addresss �c/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/grpc/_observability.py�__init__z ServerCallTracerFactory.__init__/s ���� � � �c��|jSrr�rs r�__int__zServerCallTracerFactory.__int__2s ���}�rN)�__name__� __module__� __qualname__�__doc__rr�rrrr(s<��������  � � �����rrc��eZdZUdZdZded<dZded<ejd$d ���Z ejd%d���Z ejdd�d&d���Z ejd'd���Z d(d�Z d(d�Zd)d�Zed*d ���Zed*d!���Zed*d"���Zd#S)+�ObservabilityPlugina�Abstract base class for observability plugin. *This is a semi-private class that was intended for the exclusive use of the gRPC team.* The ClientCallTracerCapsule and ClientCallTracerCapsule created by this plugin should be inject to gRPC core using observability_init at the start of a program, before any channels/servers are built. Any future methods added to this interface cannot have the @abc.abstractmethod annotation. Attributes: _stats_enabled: A bool indicates whether tracing is enabled. _tracing_enabled: A bool indicates whether stats(metrics) is enabled. _registered_methods: A set which stores the registered method names in bytes. F�bool�_tracing_enabled�_stats_enabled� method_name�bytes�target�returnr c��t���)a�Creates a ClientCallTracerCapsule. After register the plugin, if tracing or stats is enabled, this method will be called after a call was created, the ClientCallTracer created by this method will be saved to call context. The ClientCallTracer is an object which implements `grpc_core::ClientCallTracer` interface and wrapped in a PyCapsule using `client_call_tracer` as name. Args: method_name: The method name of the call in byte format. target: The channel target of the call in byte format. registered_method: Wether this method is pre-registered. Returns: A PyCapsule which stores a ClientCallTracer object. ��NotImplementedError)rr)r+s r�create_client_call_tracerz-ObservabilityPlugin.create_client_call_tracerP���*"�#�#�#r�trace_id�str�span_id� is_sampled�Nonec��t���)a�Saves the trace_id and span_id related to the current span. After register the plugin, if tracing is enabled, this method will be called after the server finished sending response. This method can be used to propagate census context. Args: trace_id: The identifier for the trace associated with the span as a 32-character hexadecimal encoded string, e.g. 26ed0036f2eff2b7317bccce3e28d01f span_id: The identifier for the span as a 16-character hexadecimal encoded string. e.g. 113ec879e62583bc is_sampled: A bool indicates whether the span is sampled. r.)rr2r4r5s r�save_trace_contextz&ObservabilityPlugin.save_trace_contextgs��&"�#�#�#r)�xdsr9�(Optional[ServerCallTracerFactoryCapsule]c��t���)apCreates a ServerCallTracerFactoryCapsule. This method will be called at server initialization time to create a ServerCallTracerFactory, which will be registered to gRPC core. The ServerCallTracerFactory is an object which implements `grpc_core::ServerCallTracerFactory` interface and wrapped in a PyCapsule using `server_call_tracer_factory` as name. Args: xds: Whether the server is xds server. Returns: A PyCapsule which stores a ServerCallTracerFactory object. Or None if plugin decides not to create ServerCallTracerFactory. r.)rr9s r�!create_server_call_tracer_factoryz5ObservabilityPlugin.create_server_call_tracer_factory|r1r�method� rpc_latency�float� status_coderc��t���)aaRecord the latency of the RPC. After register the plugin, if stats is enabled, this method will be called at the end of each RPC. Args: method: The fully-qualified name of the RPC method being invoked. target: The target name of the RPC method being invoked. rpc_latency: The latency for the RPC in seconds, equals to the time between when the client invokes the RPC and when the client receives the status. status_code: An element of grpc.StatusCode in string format representing the final status for the RPC. r.)rr=r+r>r@s r�record_rpc_latencyz&ObservabilityPlugin.record_rpc_latency�s��""�#�#�#r�enablec��||_dS)zxEnable or disable tracing. Args: enable: A bool indicates whether tracing should be enabled. N�r'�rrCs r� set_tracingzObservabilityPlugin.set_tracing�s�� !'����rc��||_dS)z}Enable or disable stats(metrics). Args: enable: A bool indicates whether stats should be enabled. N�r(rFs r� set_statszObservabilityPlugin.set_stats�s�� %����rc��t���)z�Saves the method name to registered_method list. When exporting metrics, method name for unregistered methods will be replaced with 'other' by default. Args: method_name: The method name in bytes. r.)rr)s r�save_registered_methodz*ObservabilityPlugin.save_registered_method�s��"�#�#�#rc��|jSrrErs r�tracing_enabledz#ObservabilityPlugin.tracing_enabled�s ���$�$rc��|jSrrIrs r� stats_enabledz!ObservabilityPlugin.stats_enabled�s ���"�"rc��|jp|jSr)rNrPrs r�observability_enabledz)ObservabilityPlugin.observability_enabled�s���#�9�t�'9�9rN)r)r*r+r*r,r )r2r3r4r3r5r&r,r6)r9r&r,r:) r=r3r+r3r>r?r@rr,r6)rCr&r,r6)r)r*r,r6)r,r&)rr r!r"r'�__annotations__r(�abc�abstractmethodr0r8r<rBrGrJrL�propertyrNrPrRr#rrr%r%6s~���������&#��"�"�"�"� �N� � � � ���$�$�$���$�, ��$�$�$���$�( ���$�$�$�$�$���$�, ��$�$�$���$�$'�'�'�'�%�%�%�%� $� $� $� $��%�%�%��X�%��#�#�#��X�#��:�:�:��X�:�:�:rr%)� metaclassr,�4Generator[Optional[ObservabilityPlugin], None, None]c#�\K�t5tV�ddd��dS#1swxYwYdS)z�Get the ObservabilityPlugin in _observability module. Returns: The ObservabilityPlugin currently registered with the _observability module. Or None if no plugin exists at the time of calling this method. N)rrr#rr� get_pluginrZ�s~���� �$�$�#�#�#�#�$�$�$�$�$�$�$�$�$�$�$�$����$�$�$�$�$�$s � !�%�%�observability_plugin�Optional[ObservabilityPlugin]r6c�z�t5|rtrtd���|addd��dS#1swxYwYdS)z�Save ObservabilityPlugin to _observability module. Args: observability_plugin: The ObservabilityPlugin to save. Raises: ValueError: If an ObservabilityPlugin was already registered at the time of calling this method. z%observability_plugin was already set!N)rr� ValueError�r[s r� set_pluginr`�s��� �5�5� � F�$9� F��D�E�E� E� 4��5�5�5�5�5�5�5�5�5�5�5�5����5�5�5�5�5�5s �0�4�4c�$�t|��dS)ahInitialize observability with provided ObservabilityPlugin. This method have to be called at the start of a program, before any channels/servers are built. Args: observability_plugin: The ObservabilityPlugin to use. Raises: ValueError: If an ObservabilityPlugin was already registered at the time of calling this method. N)r`r_s r�observability_initrb�s���#�$�$�$�$�$rc�J�td��tj��dS)z�Clear the observability context, including ObservabilityPlugin and ServerCallTracerFactory This method have to be called after exit observability context so that it's possible to re-initialize again. N)r`�_cygrpc� clear_server_call_tracer_factoryr#rr�observability_deinitrf�s'���t���� �,�.�.�.�.�.r�state�'_channel._RPCState'c�.�tD]!}||j�d��vrdS�"t��5}|rB|jr;|j|jz }|dz}|�|j|j||j ��ddd��dS#1swxYwYdS)z�Record the latency of the RPC, if the plugin is registered and stats is enabled. This method will be called at the end of each RPC. Args: state: a grpc._channel._RPCState object which contains the stats related to the RPC. �utf8Ni�) rr=�encoderZrP� rpc_end_time�rpc_start_timerBr+�code)rg�exclude_prefix�plugin� rpc_latency_s�rpc_latency_mss r�maybe_record_rpc_latencyrss���/���� �U�\�0�0��8�8� 8� 8� �F�F� 9� ����� � �f�*� �!�.��1E�E�M�*�T�1�N� � %� %�� �e�l�N�E�J� � � � ��������������������s�AB � B�Br9r&r c���t��5}|r<|jr5tj||��}|rdt |��ffcddd��S ddd��dS#1swxYwYdS)Nz,grpc.experimental.server_call_tracer_factoryr#)rZrPrd�&get_server_call_tracer_factory_addressr)r9rp�"server_call_tracer_factory_addresss r�(create_server_call_tracer_factory_optionrws��� ����� � �f�*� ��>�v�s�K�K� /�2� �G�/�>����� �����������������������������s�2A�A�A �#A )r,rX)r[r\r,r6)r[r%r,r6)r,r6)rgrhr,r6)r9r&r,r )'� __future__rrT� contextlib�logging� threading�typingrrrrrr � grpc._cythonr rd� grpc._typingr � getLoggerr�_LOGGER�_channelr r �RLockrrSrrr�ABCMetar%�contextmanagerrZr`rbrfrsrwr#rr�<module>r�s'��#�"�"�"�"�"�"� � � � �������������C�C�C�C�C�C�C�C�C�C�C�C�C�C�C�C�*�*�*�*�*�*�,�,�,�,�,�,� �'� �H� %� %�� ��!�'�";�<�<��!(��)I�!J�!J�� /� �� 1� 1� �1�1�1�1�9=��=�=�=�=�)�1�%������ � � � � � � � �U:�U:�U:�U:�U:� � #�%C� C�D��k�U:�U:�U:�U:�p ��$�$�$���$�5�5�5�5�" %� %� %� %� /�/�/�/�����,�����r
Memory