
    (ph(                       % S SK Jr  S SKrS SKrS SKrS SKrS SKJrJrJ	r	J
r
JrJr  S SKJr  S SKJr  \R$                  " \5      r\r\" S5      r\" S5      r\R0                  " 5       rS\S	'   SqS
\S'   SS/rS\S'    " S S5      r " S S\	\\4   \R<                  S9r\R@                  SS j5       r!SS jr"SS jr#SS jr$SS jr%S S jr&g)!    )annotationsN)Any	GeneratorGenericListOptionalTypeVar)cygrpc)ChannelArgumentTypeClientCallTracerCapsuleServerCallTracerFactoryCapsulezthreading.RLock_plugin_lockzOptional['ObservabilityPlugin']_OBSERVABILITY_PLUGINs"   google.monitoring.v3.MetricServices*   google.devtools.cloudtrace.v2.TraceServicezList[bytes]_SERVICES_TO_EXCLUDEc                  $    \ rS rSrSrS rS rSrg)ServerCallTracerFactory(   zAn 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                    Xl         g N_address)selfaddresss     F/var/www/html/venv/lib/python3.13/site-packages/grpc/_observability.py__init__ ServerCallTracerFactory.__init__/   s        c                    U R                   $ r   r   r   s    r   __int__ServerCallTracerFactory.__int__2   s    }}r   r   N)__name__
__module____qualname____firstlineno____doc__r   r    __static_attributes__ r   r   r   r   (   s     r   r   c                  n   \ rS rSr% SrSrS\S'   SrS\S'   \R                        SS j5       r
\R                          SS j5       r\R                  SS	.   SS
 jj5       r\R                            SS j5       rSS jrSS jrSS jr\SS j5       r\SS j5       r\SS j5       rSrg)ObservabilityPlugin6   a  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 injected 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_enabledc                    [        5       e)aq  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: Whether this method is pre-registered.

Returns:
  A PyCapsule which stores a ClientCallTracer object.
NotImplementedError)r   method_nametargets      r   create_client_call_tracer-ObservabilityPlugin.create_client_call_tracerP       * "##r   c                    [        5       e)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.
r0   )r   trace_idspan_id
is_sampleds       r   save_trace_context&ObservabilityPlugin.save_trace_contextg   s    & "##r   )xdsc                   [        5       e)a  Creates 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.
r0   )r   r=   s     r   !create_server_call_tracer_factory5ObservabilityPlugin.create_server_call_tracer_factory|   r6   r   c                    [        5       e)a  Record 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.
r0   )r   methodr3   rpc_latencystatus_codes        r   record_rpc_latency&ObservabilityPlugin.record_rpc_latency   s    " "##r   c                    Xl         g)z`Enable or disable tracing.

Args:
  enable: A bool indicates whether tracing should be enabled.
Nr-   r   enables     r   set_tracingObservabilityPlugin.set_tracing   s
     !'r   c                    Xl         g)zeEnable or disable stats(metrics).

Args:
  enable: A bool indicates whether stats should be enabled.
Nr.   rI   s     r   	set_statsObservabilityPlugin.set_stats   s
     %r   c                    [        5       e)zSaves 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.
r0   )r   r2   s     r   save_registered_method*ObservabilityPlugin.save_registered_method   s     "##r   c                    U R                   $ r   rH   r   s    r   tracing_enabled#ObservabilityPlugin.tracing_enabled   s    $$$r   c                    U R                   $ r   rN   r   s    r   stats_enabled!ObservabilityPlugin.stats_enabled   s    """r   c                @    U R                   =(       d    U R                  $ r   )rU   rX   r   s    r   observability_enabled)ObservabilityPlugin.observability_enabled   s    ##9t'9'99r   )r.   r-   N)r2   bytesr3   r]   returnr   )r8   strr9   r_   r:   r,   r^   None)r=   r,   r^   z(Optional[ServerCallTracerFactoryCapsule])
rB   r_   r3   r_   rC   floatrD   r   r^   r`   )rJ   r,   r^   r`   )r2   r]   r^   r`   )r^   r,   )r"   r#   r$   r%   r&   r-   __annotations__r.   abcabstractmethodr4   r;   r?   rE   rK   rO   rR   propertyrU   rX   r[   r'   r(   r   r   r*   r*   6   sH   & #d" ND $ $*/$	 $ $, 	$$&)$7;$	$ $( 	 $ $ 
2	$ $, 	$$#&$5:$IL$	$ $$'%	$ % % # # : :r   r*   )	metaclassc               #  \   #    [            [        v   SSS5        g! , (       d  f       g= f7f)zGet 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)r   r   r(   r   r   
get_pluginrh      s      
## 
s   ,		,
),c                    [            U (       a  [        (       a  [        S5      eU qSSS5        g! , (       d  f       g= f)zSave 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)r   r   
ValueErrorobservability_plugins    r   
set_pluginrm      s,     
$9$9DEE 4 
s    0
>c                    [        U 5        g)aH  Initialize 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)rm   rk   s    r   observability_initro      s     #$r   c                 D    [        S5        [        R                  " 5         g)zClear 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)rm   _cygrpc clear_server_call_tracer_factoryr(   r   r   observability_deinitrs      s     t,,.r   c                t   [          H#  nXR                  R                  S5      ;   d  M#    g   [        5        nU(       a`  UR                  (       aO  U R
                  U R                  -
  nUS-  nUR                  U R                  U R                  X@R                  5        SSS5        g! , (       d  f       g= f)zRecord 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  )
r   rB   encoderh   rX   rpc_end_timerpc_start_timerE   r3   code)stateexclude_prefixpluginrpc_latency_srpc_latency_mss        r   maybe_record_rpc_latencyr     s     /\\0088 / 
f**!..1E1EEM*T1N%%ellNJJ	 
s   A(B))
B7c                    [        5        nU(       aE  UR                  (       a4  [        R                  " X5      nU(       a  S[	        U5      44sS S S 5        $  S S S 5        g! , (       d  f       g = f)Nz,grpc.experimental.server_call_tracer_factoryr(   )rh   rX   rq   &get_server_call_tracer_factory_addressr   )r=   r|   "server_call_tracer_factory_addresss      r   (create_server_call_tracer_factory_optionr     s]    	f**>>vK / 2 G/> 
  
s   AA"A""
A0)r^   z4Generator[Optional[ObservabilityPlugin], None, None])rl   zOptional[ObservabilityPlugin]r^   r`   )rl   r*   r^   r`   )r^   r`   )rz   z'_channel._RPCState'r^   r`   )r=   r,   r^   r   )'
__future__r   rc   
contextliblogging	threadingtypingr   r   r   r   r   r	   grpc._cythonr
   rq   grpc._typingr   	getLoggerr"   _LOGGER_channelr   r   RLockr   rb   r   r   r   ABCMetar*   contextmanagerrh   rm   ro   rs   r   r   r(   r   r   <module>r      s    # 
    C C * ,


H
%!";< !()I!J  ) 1o 19= 6 =)1% k  U:#%CCDkkU:p $ $5"% /,r   