|
11 | 11 | import io.opentelemetry.sdk.trace.data.LinkData; |
12 | 12 | import io.opentelemetry.sdk.trace.samplers.Sampler; |
13 | 13 | import io.opentelemetry.sdk.trace.samplers.SamplingResult; |
14 | | - |
15 | 14 | import java.util.List; |
16 | 15 |
|
17 | 16 | /** |
|
20 | 19 | * links, this Sampler will use the "root" sampler that it is built with. |
21 | 20 | */ |
22 | 21 | public final class LinksBasedSampler implements Sampler { |
23 | | - private final Sampler root; |
24 | | - |
25 | | - private LinksBasedSampler(Sampler root) { |
26 | | - this.root = root; |
27 | | - } |
28 | | - |
29 | | - public static LinksBasedSampler create( |
30 | | - Sampler root) { |
31 | | - return new LinksBasedSampler(root); |
32 | | - } |
33 | | - |
34 | | - @Override |
35 | | - public SamplingResult shouldSample( |
36 | | - Context parentContext, |
37 | | - String traceId, |
38 | | - String name, |
39 | | - SpanKind spanKind, |
40 | | - Attributes attributes, |
41 | | - List<LinkData> parentLinks) { |
42 | | - if (parentLinks.size() > 0) { |
43 | | - for (LinkData linkData : parentLinks) { |
44 | | - if (linkData.getSpanContext().isSampled()) { |
45 | | - return SamplingResult.recordAndSample(); |
46 | | - } |
47 | | - } |
48 | | - return SamplingResult.drop(); |
| 22 | + private final Sampler root; |
| 23 | + |
| 24 | + private LinksBasedSampler(Sampler root) { |
| 25 | + this.root = root; |
| 26 | + } |
| 27 | + |
| 28 | + public static LinksBasedSampler create(Sampler root) { |
| 29 | + return new LinksBasedSampler(root); |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + public SamplingResult shouldSample( |
| 34 | + Context parentContext, |
| 35 | + String traceId, |
| 36 | + String name, |
| 37 | + SpanKind spanKind, |
| 38 | + Attributes attributes, |
| 39 | + List<LinkData> parentLinks) { |
| 40 | + if (parentLinks.size() > 0) { |
| 41 | + for (LinkData linkData : parentLinks) { |
| 42 | + if (linkData.getSpanContext().isSampled()) { |
| 43 | + return SamplingResult.recordAndSample(); |
49 | 44 | } |
50 | | - |
51 | | - return this.root.shouldSample(parentContext, traceId, name, spanKind, attributes, parentLinks); |
| 45 | + } |
| 46 | + return SamplingResult.drop(); |
52 | 47 | } |
53 | 48 |
|
54 | | - @Override |
55 | | - public String getDescription() { |
56 | | - return String.format("LinksBased{root:%s}", this.root.getDescription()); |
57 | | - } |
| 49 | + return this.root.shouldSample(parentContext, traceId, name, spanKind, attributes, parentLinks); |
| 50 | + } |
58 | 51 |
|
59 | | - @Override |
60 | | - public String toString() { |
61 | | - return getDescription(); |
62 | | - } |
| 52 | + @Override |
| 53 | + public String getDescription() { |
| 54 | + return String.format("LinksBased{root:%s}", this.root.getDescription()); |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public String toString() { |
| 59 | + return getDescription(); |
| 60 | + } |
63 | 61 | } |
0 commit comments