;io*UddlmZddlZddlZddlZddlZddlmZmZm Z m Z m Z m Z m Z mZddlmZddlmZejeZeZe dZe dZejZded <dad ed <d d gZded<GddZGdde eefej Z!ej"d%dZ#d&dZ$d'dZ%d(dZ&d)d Z'd*d$Z(dS)+) annotationsN)Any GeneratorGenericListOptionalTupleTypeVarUnion)cygrpc)ChannelArgumentTypeClientCallTracerCapsuleServerCallTracerFactoryCapsulezthreading.RLock _plugin_lockzOptional['ObservabilityPlugin']_OBSERVABILITY_PLUGINs"google.monitoring.v3.MetricServices*google.devtools.cloudtrace.v2.TraceServicez List[bytes]_SERVICES_TO_EXCLUDEceZdZdZdZdZdS)ServerCallTracerFactoryzAn 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||_dSN_address)selfaddresss GC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\grpc/_observability.py__init__z ServerCallTracerFactory.__init__8s  c|jSrrrs r__int__zServerCallTracerFactory.__int__;s }rN)__name__ __module__ __qualname____doc__rr rrrr1s<    rrceZdZUdZdZded<dZded<ejd$d Z ejd%dZ ejddd&dZ ejd'dZ d(dZ d(dZd)dZed*d Zed*d!Zed*d"Zd#S)+ObservabilityPluginaAbstract 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. Fbool_tracing_enabled_stats_enabled method_namebytestargetreturnrct)aCreates 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)rr+r-s rcreate_client_call_tracerz-ObservabilityPlugin.create_client_call_tracerYs*"###rtrace_idstrspan_id is_sampledNonect)aSaves 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)rr3r5r6s rsave_trace_contextz&ObservabilityPlugin.save_trace_contextps&"###r)xdsr:(Optional[ServerCallTracerFactoryCapsule]ct)aqCreates 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)rr:s r!create_server_call_tracer_factoryz5ObservabilityPlugin.create_server_call_tracer_factorys,"###rmethod rpc_latencyfloat status_coderct)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. r0)rr>r-r?rAs rrecord_rpc_latencyz&ObservabilityPlugin.record_rpc_latencys""###renablec||_dS)zxEnable or disable tracing. Args: enable: A bool indicates whether tracing should be enabled. Nr)rrDs r set_tracingzObservabilityPlugin.set_tracings !'rc||_dS)z}Enable or disable stats(metrics). Args: enable: A bool indicates whether stats should be enabled. Nr*rGs r set_statszObservabilityPlugin.set_statss %rct)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)rr+s rsave_registered_methodz*ObservabilityPlugin.save_registered_methods"###rc|jSrrFrs rtracing_enabledz#ObservabilityPlugin.tracing_enableds $$rc|jSrrJrs r stats_enabledz!ObservabilityPlugin.stats_enableds ""rc|jp|jSr)rOrQrs robservability_enabledz)ObservabilityPlugin.observability_enableds#9t'99rN)r+r,r-r,r.r)r3r4r5r4r6r(r.r7)r:r(r.r;) r>r4r-r4r?r@rArr.r7)rDr(r.r7)r+r,r.r7)r.r()r!r"r#r$r)__annotations__r*abcabstractmethodr2r9r=rCrHrKrMpropertyrOrQrSr%rrr'r'?s~&#"""" N    $$$$, $$$$( $$$$$$. $$$$$''''%%%% $ $ $ $%%%X%###X#:::X:::rr') metaclassr.4Generator[Optional[ObservabilityPlugin], None, None]c#\Kt5tVddddS#1swxYwYdS)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)rrr%rr get_pluginr[s~ $$####$$$$$$$$$$$$$$$$$$s !%%observability_pluginOptional[ObservabilityPlugin]r7c~t5|rtrd}t||addddS#1swxYwYdS)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)rr ValueError)r\ error_msgs r set_pluginras 55  ($9 (?IY'' ' 4 555555555555555555s 266c$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)ra)r\s robservability_initrcs#$$$$$rcJtdtjdS)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)ra_cygrpc clear_server_call_tracer_factoryr%rrobservability_deinitrgs't ,.....rstate'_channel._RPCState'c.tD]!}||jdvrdS"t5}|rB|jr;|j|jz }|dz}||j|j||j ddddS#1swxYwYdS)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) rr>encoder[rQ rpc_end_timerpc_start_timerCr-code)rhexclude_prefixplugin rpc_latency_srpc_latency_mss rmaybe_record_rpc_latencyrts/ U\0088 8 8 FF 9   f* !.1EEM*T1N  % % elNEJ    sAB  BBr:r(,Union[Tuple[ChannelArgumentType], Tuple[()]]ct5}|r<|jr5tj||}|rdt |ffcdddS ddddS#1swxYwYdS)Nz,grpc.experimental.server_call_tracer_factoryr%)r[rQre&get_server_call_tracer_factory_addressr)r:rq"server_call_tracer_factory_addresss r(create_server_call_tracer_factory_optionry's   f* >vsKK /2 G/> s2AAA #A )r.rY)r\r]r.r7)r\r'r.r7)r.r7)rhrir.r7)r:r(r.ru)) __future__rrU contextliblogging threadingtypingrrrrrr r r grpc._cythonr re grpc._typingr getLoggerr!_LOGGER_channelrrRLockrrTrrrABCMetar'contextmanagerr[rarcrgrtryr%rrrs]#""""""                     +*****,,,,,, ' H % % !'";<<!()I!J!J /  1 1 11119=====)1%        V:V:V:V:V: #%C CDkV:V:V:V:r $$$$5555$ % % % % ////,r