-
Notifications
You must be signed in to change notification settings - Fork 779
/
TraceKeys.java
493 lines (396 loc) · 12.6 KB
/
TraceKeys.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth;
import java.util.Collection;
import java.util.LinkedHashSet;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Well-known {@link brave.Span#tag(String, String) span tag}
* keys.
*
* <h3>Overhead of adding Trace Data</h3>
*
* Overhead is directly related to the size of trace data exported out of process.
* Accordingly, it is better to tag what's important for latency troubleshooting, i.e. a
* whitelist vs. collecting everything and filtering downstream. The keys listed here are
* very common in tracing tools, and are considerate to the issue of overhead.
*
* <p>
* When evaluating new keys, consider how much additional data it implies, and if that
* data is critical to classifying, filtering or displaying traces. More data often means
* larger systems, less retention, or a lower sample rate.
*
* <p>
* For example, in zipkin, a thrift-encoded span with an "sr" annotation is 82 bytes plus
* the size of its name and associated service. The maximum size of an HTTP cookie is 4096
* bytes, roughly 50x that. Even if compression helps, if you aren't analyzing based on
* cookies, storing them displaces resources that could be used for more traces.
* Meanwhile, you have another system storing private data! The takeaway isn't never store
* cookies, as there are valid cases for this. The takeaway is to be conscious about
* what's you are storing.
*
* @since 1.0.0
*
* @deprecated the Brave's defaults are suggested to be used
*/
@ConfigurationProperties("spring.sleuth.keys")
@Deprecated
public class TraceKeys {
private Http http = new Http();
private Message message = new Message();
private Hystrix hystrix = new Hystrix();
private Async async = new Async();
private Mvc mvc = new Mvc();
public Http getHttp() {
return this.http;
}
public Message getMessage() {
return this.message;
}
public Hystrix getHystrix() {
return this.hystrix;
}
public Async getAsync() {
return this.async;
}
public Mvc getMvc() {
return this.mvc;
}
public void setHttp(Http http) {
this.http = http;
}
public void setMessage(Message message) {
this.message = message;
}
public void setHystrix(Hystrix hystrix) {
this.hystrix = hystrix;
}
public void setAsync(Async async) {
this.async = async;
}
public void setMvc(Mvc mvc) {
this.mvc = mvc;
}
public static class Message {
private Payload payload = new Payload();
public Payload getPayload() {
return this.payload;
}
public String getPrefix() {
return this.prefix;
}
public Collection<String> getHeaders() {
return this.headers;
}
public void setPayload(Payload payload) {
this.payload = payload;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public void setHeaders(Collection<String> headers) {
this.headers = headers;
}
public static class Payload {
/**
* An estimate of the size of the payload if available.
*/
private String size = "message/payload-size";
/**
* The type of the payload.
*/
private String type = "message/payload-type";
public String getSize() {
return this.size;
}
public String getType() {
return this.type;
}
public void setSize(String size) {
this.size = size;
}
public void setType(String type) {
this.type = type;
}
}
/**
* Prefix for header names if they are added as tags.
*/
private String prefix = "message/";
/**
* Additional headers that should be added as tags if they exist. If the header
* value is not a String it will be converted to a String using its toString()
* method.
*/
private Collection<String> headers = new LinkedHashSet<String>();
}
public static class Http {
/**
* The domain portion of the URL or host header. Example:
* "mybucket.s3.amazonaws.com". Used to filter by host as opposed to ip address.
*/
private String host = "http.host";
/**
* The HTTP method, or verb, such as "GET" or "POST". Used to filter against an
* http route.
*/
private String method = "http.method";
/**
* The absolute http path, without any query parameters. Example:
* "/objects/abcd-ff". Used to filter against an http route, portably with zipkin
* v1. In zipkin v1, only equals filters are supported. Dropping query parameters
* makes the number of distinct URIs less. For example, one can query for the same
* resource, regardless of signing parameters encoded in the query line. This does
* not reduce cardinality to a HTTP single route. For example, it is common to
* express a route as an http URI template like "/resource/{resource_id}". In
* systems where only equals queries are available, searching for
* {@code http.uri=/resource} won't match if the actual request was
* "/resource/abcd-ff". Historical note: This was commonly expressed as "http.uri"
* in zipkin, eventhough it was most often just a path.
*/
private String path = "http.path";
/**
* The entire URL, including the scheme, host and query parameters if available.
* Ex.
* "https://mybucket.s3.amazonaws.com/objects/abcd-ff?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Algorithm=AWS4-HMAC-SHA256..."
* Combined with {@link #method}, you can understand the fully-qualified
* request line. This is optional as it may include private data or be of
* considerable length.
*/
private String url = "http.url";
/**
* The HTTP response code, when not in 2xx range. Ex. "503" Used to filter for
* error status. 2xx range are not logged as success codes are less interesting
* for latency troubleshooting. Omitting saves at least 20 bytes per span.
*/
private String statusCode = "http.status_code";
/**
* The size of the non-empty HTTP request body, in bytes. Ex. "16384"
*
* <p>Large uploads can exceed limits or contribute directly to latency.
*/
private String requestSize = "http.request.size";
/**
* The size of the non-empty HTTP response body, in bytes. Ex. "16384"
*
* <p>Large downloads can exceed limits or contribute directly to latency.
*/
private String responseSize = "http.response.size";
/**
* Prefix for header names if they are added as tags.
*/
private String prefix = "http.";
/**
* Additional headers that should be added as tags if they exist. If the header
* value is multi-valued, the tag value will be a comma-separated, single-quoted
* list.
*/
private Collection<String> headers = new LinkedHashSet<String>();
public String getHost() {
return this.host;
}
public String getMethod() {
return this.method;
}
public String getPath() {
return this.path;
}
public String getUrl() {
return this.url;
}
public String getStatusCode() {
return this.statusCode;
}
public String getRequestSize() {
return this.requestSize;
}
public String getResponseSize() {
return this.responseSize;
}
public String getPrefix() {
return this.prefix;
}
public Collection<String> getHeaders() {
return this.headers;
}
public void setHost(String host) {
this.host = host;
}
public void setMethod(String method) {
this.method = method;
}
public void setPath(String path) {
this.path = path;
}
public void setUrl(String url) {
this.url = url;
}
public void setStatusCode(String statusCode) {
this.statusCode = statusCode;
}
public void setRequestSize(String requestSize) {
this.requestSize = requestSize;
}
public void setResponseSize(String responseSize) {
this.responseSize = responseSize;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public void setHeaders(Collection<String> headers) {
this.headers = headers;
}
}
/**
* Trace keys related to Hystrix processing
*/
public static class Hystrix {
/**
* Prefix for header names if they are added as tags.
*/
private String prefix = "";
/**
* Name of the command key. Describes the name for the given command.
* A key to represent a {@link com.netflix.hystrix.HystrixCommand} for
* monitoring, circuit-breakers, metrics publishing, caching and other such uses.
*
* @see com.netflix.hystrix.HystrixCommandKey
*/
private String commandKey = "commandKey";
/**
* Name of the command group. Hystrix uses the command group key to group
* together commands such as for reporting, alerting, dashboards,
* or team/library ownership.
*
* @see com.netflix.hystrix.HystrixCommandGroupKey
*/
private String commandGroup = "commandGroup";
/**
* Name of the thread pool key. The thread-pool key represents a {@link com.netflix.hystrix.HystrixThreadPool}
* for monitoring, metrics publishing, caching, and other such uses. A {@link com.netflix.hystrix.HystrixCommand}
* is associated with a single {@link com.netflix.hystrix.HystrixThreadPool} as
* retrieved by the {@link com.netflix.hystrix.HystrixThreadPoolKey} injected into it,
* or it defaults to one created using the {@link com.netflix.hystrix.HystrixCommandGroupKey}
* it is created with.
*
* @see com.netflix.hystrix.HystrixThreadPoolKey
*/
private String threadPoolKey = "threadPoolKey";
public String getPrefix() {
return this.prefix;
}
public String getCommandKey() {
return this.commandKey;
}
public String getCommandGroup() {
return this.commandGroup;
}
public String getThreadPoolKey() {
return this.threadPoolKey;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public void setCommandKey(String commandKey) {
this.commandKey = commandKey;
}
public void setCommandGroup(String commandGroup) {
this.commandGroup = commandGroup;
}
public void setThreadPoolKey(String threadPoolKey) {
this.threadPoolKey = threadPoolKey;
}
}
/**
* Trace keys related to async processing
*/
public static class Async {
/**
* Prefix for header names if they are added as tags.
*/
private String prefix = "";
/**
* Name of the thread that executed the async method
*
* @see org.springframework.scheduling.annotation.Async
*/
private String threadNameKey = "thread";
/**
* Simple name of the class with a method annotated with {@code @Async}
* from which the asynchronous process started
*
* @see org.springframework.scheduling.annotation.Async
*/
private String classNameKey = "class";
/**
* Name of the method annotated with {@code @Async}
*
* @see org.springframework.scheduling.annotation.Async
*/
private String methodNameKey = "method";
public String getPrefix() {
return this.prefix;
}
public String getThreadNameKey() {
return this.threadNameKey;
}
public String getClassNameKey() {
return this.classNameKey;
}
public String getMethodNameKey() {
return this.methodNameKey;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public void setThreadNameKey(String threadNameKey) {
this.threadNameKey = threadNameKey;
}
public void setClassNameKey(String classNameKey) {
this.classNameKey = classNameKey;
}
public void setMethodNameKey(String methodNameKey) {
this.methodNameKey = methodNameKey;
}
}
/**
* Trace keys related to MVC controller tags
*/
public static class Mvc {
/**
* The lower case, hyphen delimited name of the class that processes the request.
* Ex. class named "BookController" will result in "book-controller" tag value.
*/
private String controllerClass = "mvc.controller.class";
/**
* The lower case, hyphen delimited name of the class that processes the request.
* Ex. method named "listOfBooks" will result in "list-of-books" tag value.
*/
private String controllerMethod = "mvc.controller.method";
public String getControllerClass() {
return this.controllerClass;
}
public void setControllerClass(String controllerClass) {
this.controllerClass = controllerClass;
}
public String getControllerMethod() {
return this.controllerMethod;
}
public void setControllerMethod(String controllerMethod) {
this.controllerMethod = controllerMethod;
}
}
}