|
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 | + |
14 | 15 | import java.util.List; |
15 | 16 |
|
16 | 17 | /** |
|
19 | 20 | * links, this Sampler will use the "root" sampler that it is built with. |
20 | 21 | */ |
21 | 22 | public final class LinksBasedSampler implements Sampler { |
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(); |
44 | | - } |
45 | | - } |
46 | | - return SamplingResult.drop(); |
| 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); |
47 | 32 | } |
48 | 33 |
|
49 | | - return this.root.shouldSample(parentContext, traceId, name, spanKind, attributes, parentLinks); |
50 | | - } |
| 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(); |
| 49 | + } |
51 | 50 |
|
52 | | - @Override |
53 | | - public String getDescription() { |
54 | | - return String.format("LinksBased{root:%s}", this.root.getDescription()); |
55 | | - } |
| 51 | + return this.root.shouldSample(parentContext, traceId, name, spanKind, attributes, parentLinks); |
| 52 | + } |
56 | 53 |
|
57 | | - @Override |
58 | | - public String toString() { |
59 | | - return getDescription(); |
60 | | - } |
| 54 | + @Override |
| 55 | + public String getDescription() { |
| 56 | + return String.format("LinksBased{root:%s}", this.root.getDescription()); |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + public String toString() { |
| 61 | + return getDescription(); |
| 62 | + } |
61 | 63 | } |
0 commit comments