1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package ochttp
16
17 import (
18 "go.opencensus.io/stats"
19 "go.opencensus.io/stats/view"
20 "go.opencensus.io/tag"
21 )
22
23
24 var (
25
26 ClientRequestCount = stats.Int64(
27 "opencensus.io/http/client/request_count",
28 "Number of HTTP requests started",
29 stats.UnitDimensionless)
30
31 ClientRequestBytes = stats.Int64(
32 "opencensus.io/http/client/request_bytes",
33 "HTTP request body size if set as ContentLength (uncompressed)",
34 stats.UnitBytes)
35
36 ClientResponseBytes = stats.Int64(
37 "opencensus.io/http/client/response_bytes",
38 "HTTP response body size (uncompressed)",
39 stats.UnitBytes)
40
41 ClientLatency = stats.Float64(
42 "opencensus.io/http/client/latency",
43 "End-to-end latency",
44 stats.UnitMilliseconds)
45 )
46
47
48 var (
49 ClientSentBytes = stats.Int64(
50 "opencensus.io/http/client/sent_bytes",
51 "Total bytes sent in request body (not including headers)",
52 stats.UnitBytes,
53 )
54 ClientReceivedBytes = stats.Int64(
55 "opencensus.io/http/client/received_bytes",
56 "Total bytes received in response bodies (not including headers but including error responses with bodies)",
57 stats.UnitBytes,
58 )
59 ClientRoundtripLatency = stats.Float64(
60 "opencensus.io/http/client/roundtrip_latency",
61 "Time between first byte of request headers sent to last byte of response received, or terminal error",
62 stats.UnitMilliseconds,
63 )
64 )
65
66
67 var (
68 ServerRequestCount = stats.Int64(
69 "opencensus.io/http/server/request_count",
70 "Number of HTTP requests started",
71 stats.UnitDimensionless)
72 ServerRequestBytes = stats.Int64(
73 "opencensus.io/http/server/request_bytes",
74 "HTTP request body size if set as ContentLength (uncompressed)",
75 stats.UnitBytes)
76 ServerResponseBytes = stats.Int64(
77 "opencensus.io/http/server/response_bytes",
78 "HTTP response body size (uncompressed)",
79 stats.UnitBytes)
80 ServerLatency = stats.Float64(
81 "opencensus.io/http/server/latency",
82 "End-to-end latency",
83 stats.UnitMilliseconds)
84 )
85
86
87
88
89 var (
90
91
92
93
94
95 Host = tag.MustNewKey("http.host")
96
97
98
99 StatusCode = tag.MustNewKey("http.status")
100
101
102
103
104
105
106 Path = tag.MustNewKey("http.path")
107
108
109 Method = tag.MustNewKey("http.method")
110
111
112
113
114 KeyServerRoute = tag.MustNewKey("http_server_route")
115 )
116
117
118 var (
119
120 KeyClientMethod = tag.MustNewKey("http_client_method")
121
122 KeyClientPath = tag.MustNewKey("http_client_path")
123
124 KeyClientStatus = tag.MustNewKey("http_client_status")
125
126 KeyClientHost = tag.MustNewKey("http_client_host")
127 )
128
129
130 var (
131 DefaultSizeDistribution = view.Distribution(1024, 2048, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216, 67108864, 268435456, 1073741824, 4294967296)
132 DefaultLatencyDistribution = view.Distribution(1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80, 100, 130, 160, 200, 250, 300, 400, 500, 650, 800, 1000, 2000, 5000, 10000, 20000, 50000, 100000)
133 )
134
135
136
137 var (
138 ClientSentBytesDistribution = &view.View{
139 Name: "opencensus.io/http/client/sent_bytes",
140 Measure: ClientSentBytes,
141 Aggregation: DefaultSizeDistribution,
142 Description: "Total bytes sent in request body (not including headers), by HTTP method and response status",
143 TagKeys: []tag.Key{KeyClientMethod, KeyClientStatus},
144 }
145
146 ClientReceivedBytesDistribution = &view.View{
147 Name: "opencensus.io/http/client/received_bytes",
148 Measure: ClientReceivedBytes,
149 Aggregation: DefaultSizeDistribution,
150 Description: "Total bytes received in response bodies (not including headers but including error responses with bodies), by HTTP method and response status",
151 TagKeys: []tag.Key{KeyClientMethod, KeyClientStatus},
152 }
153
154 ClientRoundtripLatencyDistribution = &view.View{
155 Name: "opencensus.io/http/client/roundtrip_latency",
156 Measure: ClientRoundtripLatency,
157 Aggregation: DefaultLatencyDistribution,
158 Description: "End-to-end latency, by HTTP method and response status",
159 TagKeys: []tag.Key{KeyClientMethod, KeyClientStatus},
160 }
161
162 ClientCompletedCount = &view.View{
163 Name: "opencensus.io/http/client/completed_count",
164 Measure: ClientRoundtripLatency,
165 Aggregation: view.Count(),
166 Description: "Count of completed requests, by HTTP method and response status",
167 TagKeys: []tag.Key{KeyClientMethod, KeyClientStatus},
168 }
169 )
170
171
172 var (
173
174 ClientRequestCountView = &view.View{
175 Name: "opencensus.io/http/client/request_count",
176 Description: "Count of HTTP requests started",
177 Measure: ClientRequestCount,
178 Aggregation: view.Count(),
179 }
180
181
182 ClientRequestBytesView = &view.View{
183 Name: "opencensus.io/http/client/request_bytes",
184 Description: "Size distribution of HTTP request body",
185 Measure: ClientSentBytes,
186 Aggregation: DefaultSizeDistribution,
187 }
188
189
190 ClientResponseBytesView = &view.View{
191 Name: "opencensus.io/http/client/response_bytes",
192 Description: "Size distribution of HTTP response body",
193 Measure: ClientReceivedBytes,
194 Aggregation: DefaultSizeDistribution,
195 }
196
197
198 ClientLatencyView = &view.View{
199 Name: "opencensus.io/http/client/latency",
200 Description: "Latency distribution of HTTP requests",
201 Measure: ClientRoundtripLatency,
202 Aggregation: DefaultLatencyDistribution,
203 }
204
205
206 ClientRequestCountByMethod = &view.View{
207 Name: "opencensus.io/http/client/request_count_by_method",
208 Description: "Client request count by HTTP method",
209 TagKeys: []tag.Key{Method},
210 Measure: ClientSentBytes,
211 Aggregation: view.Count(),
212 }
213
214
215 ClientResponseCountByStatusCode = &view.View{
216 Name: "opencensus.io/http/client/response_count_by_status_code",
217 Description: "Client response count by status code",
218 TagKeys: []tag.Key{StatusCode},
219 Measure: ClientRoundtripLatency,
220 Aggregation: view.Count(),
221 }
222 )
223
224
225
226 var (
227 ServerRequestCountView = &view.View{
228 Name: "opencensus.io/http/server/request_count",
229 Description: "Count of HTTP requests started",
230 Measure: ServerRequestCount,
231 Aggregation: view.Count(),
232 }
233
234 ServerRequestBytesView = &view.View{
235 Name: "opencensus.io/http/server/request_bytes",
236 Description: "Size distribution of HTTP request body",
237 Measure: ServerRequestBytes,
238 Aggregation: DefaultSizeDistribution,
239 }
240
241 ServerResponseBytesView = &view.View{
242 Name: "opencensus.io/http/server/response_bytes",
243 Description: "Size distribution of HTTP response body",
244 Measure: ServerResponseBytes,
245 Aggregation: DefaultSizeDistribution,
246 }
247
248 ServerLatencyView = &view.View{
249 Name: "opencensus.io/http/server/latency",
250 Description: "Latency distribution of HTTP requests",
251 Measure: ServerLatency,
252 Aggregation: DefaultLatencyDistribution,
253 }
254
255 ServerRequestCountByMethod = &view.View{
256 Name: "opencensus.io/http/server/request_count_by_method",
257 Description: "Server request count by HTTP method",
258 TagKeys: []tag.Key{Method},
259 Measure: ServerRequestCount,
260 Aggregation: view.Count(),
261 }
262
263 ServerResponseCountByStatusCode = &view.View{
264 Name: "opencensus.io/http/server/response_count_by_status_code",
265 Description: "Server response count by status code",
266 TagKeys: []tag.Key{StatusCode},
267 Measure: ServerLatency,
268 Aggregation: view.Count(),
269 }
270 )
271
272
273
274 var DefaultClientViews = []*view.View{
275 ClientRequestCountView,
276 ClientRequestBytesView,
277 ClientResponseBytesView,
278 ClientLatencyView,
279 ClientRequestCountByMethod,
280 ClientResponseCountByStatusCode,
281 }
282
283
284
285 var DefaultServerViews = []*view.View{
286 ServerRequestCountView,
287 ServerRequestBytesView,
288 ServerResponseBytesView,
289 ServerLatencyView,
290 ServerRequestCountByMethod,
291 ServerResponseCountByStatusCode,
292 }
293
View as plain text