• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2023 gRPC authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from libcpp.string cimport string
16from libcpp.vector cimport vector
17
18ctypedef   signed long long int64_t
19
20cdef extern from "<queue>" namespace "std" nogil:
21  cdef cppclass queue[T]:
22    bint empty()
23    T& front()
24    void pop()
25
26cdef extern from "<mutex>" namespace "std" nogil:
27  cdef cppclass mutex:
28    mutex()
29
30  cdef cppclass unique_lock[Mutex]:
31    unique_lock(Mutex&)
32
33cdef extern from "<condition_variable>" namespace "std" nogil:
34  cdef cppclass condition_variable:
35    void notify_all()
36
37cdef extern from "src/core/telemetry/call_tracer.h" namespace "grpc_core":
38  cdef cppclass ClientCallTracer:
39    pass
40
41cdef extern from "python_observability_context.h" namespace "grpc_observability":
42  cdef void EnablePythonCensusStats(bint enable) nogil
43  cdef void EnablePythonCensusTracing(bint enable) nogil
44
45  union MeasurementValue:
46    double value_double
47    int64_t value_int
48
49  ctypedef struct Label:
50    string key
51    string value
52
53  ctypedef struct Annotation:
54    string time_stamp
55    string description
56
57  ctypedef struct Measurement:
58    cMetricsName name
59    MeasurementType type
60    MeasurementValue value
61    bint registered_method
62    bint include_exchange_labels
63
64  ctypedef struct SpanCensusData:
65    string name
66    string start_time
67    string end_time
68    string trace_id
69    string span_id
70    string parent_span_id
71    string status
72    vector[Label] span_labels
73    vector[Annotation] span_annotations
74    int64_t child_span_count
75    bint should_sample
76
77cdef extern from "observability_util.h" namespace "grpc_observability":
78  cdef cGcpObservabilityConfig ReadAndActivateObservabilityConfig() nogil
79  cdef void NativeObservabilityInit() except +
80  cdef void* CreateClientCallTracer(const char* method,
81                                    const char* target,
82                                    const char* trace_id,
83                                    const char* parent_span_id,
84                                    const char* identifier,
85                                    const vector[Label] exchange_labels,
86                                    bint add_csm_optional_labels,
87                                    bint registered_method) except +
88  cdef void* CreateServerCallTracerFactory(const vector[Label] exchange_labels, const char* identifier) except +
89  cdef queue[NativeCensusData]* g_census_data_buffer
90  cdef void AwaitNextBatchLocked(unique_lock[mutex]&, int) nogil
91  cdef bint PythonCensusStatsEnabled() nogil
92  cdef bint PythonCensusTracingEnabled() nogil
93  cdef mutex g_census_data_buffer_mutex
94  cdef condition_variable g_census_data_buffer_cv
95
96  cppclass NativeCensusData "::grpc_observability::CensusData":
97    DataType type
98    string identifier
99    Measurement measurement_data
100    SpanCensusData span_data
101    vector[Label] labels
102
103  ctypedef struct CloudMonitoring:
104    pass
105
106  ctypedef struct CloudTrace:
107    float sampling_rate
108
109  ctypedef struct CloudLogging:
110    pass
111
112  ctypedef struct cGcpObservabilityConfig "::grpc_observability::GcpObservabilityConfig":
113    CloudMonitoring cloud_monitoring
114    CloudTrace cloud_trace
115    CloudLogging cloud_logging
116    string project_id
117    vector[Label] labels
118    bint is_valid
119
120cdef extern from "constants.h" namespace "grpc_observability":
121  ctypedef enum DataType:
122    kSpanData
123    kMetricData
124
125  ctypedef enum MeasurementType:
126    kMeasurementDouble
127    kMeasurementInt
128
129  ctypedef enum cMetricsName "::grpc_observability::MetricsName":
130    # Client
131    kRpcClientApiLatencyMeasureName
132    kRpcClientSentMessagesPerRpcMeasureName
133    kRpcClientSentBytesPerRpcMeasureName
134    kRpcClientReceivedMessagesPerRpcMeasureName
135    kRpcClientReceivedBytesPerRpcMeasureName
136    kRpcClientRoundtripLatencyMeasureName
137    kRpcClientCompletedRpcMeasureName
138    kRpcClientServerLatencyMeasureName
139    kRpcClientStartedRpcsMeasureName
140    kRpcClientRetriesPerCallMeasureName
141    kRpcClientTransparentRetriesPerCallMeasureName
142    kRpcClientRetryDelayPerCallMeasureName
143    kRpcClientTransportLatencyMeasureName
144
145    # Server
146    kRpcServerSentMessagesPerRpcMeasureName
147    kRpcServerSentBytesPerRpcMeasureName
148    kRpcServerReceivedMessagesPerRpcMeasureName
149    kRpcServerReceivedBytesPerRpcMeasureName
150    kRpcServerServerLatencyMeasureName
151    kRpcServerCompletedRpcMeasureName
152    kRpcServerStartedRpcsMeasureName
153
154  string kClientMethod
155  string kClientTarget
156  string kClientStatus
157  string kRegisteredMethod
158
159cdef extern from "sampler.h" namespace "grpc_observability":
160  cdef cppclass ProbabilitySampler:
161    @staticmethod
162    ProbabilitySampler& Get()
163
164    void SetThreshold(double sampling_rate)
165