-
Notifications
You must be signed in to change notification settings - Fork 791
/
SpanSuppressors.java
88 lines (71 loc) · 2.27 KB
/
SpanSuppressors.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
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.api.instrumenter;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.internal.SpanKey;
import java.util.Map;
import java.util.Set;
final class SpanSuppressors {
private SpanSuppressors() {}
enum Noop implements SpanSuppressor {
INSTANCE;
@Override
@CanIgnoreReturnValue
public Context storeInContext(Context context, SpanKind spanKind, Span span) {
return context;
}
@Override
public boolean shouldSuppress(Context parentContext, SpanKind spanKind) {
return false;
}
}
static final class DelegateBySpanKind implements SpanSuppressor {
private final Map<SpanKind, SpanSuppressor> delegates;
DelegateBySpanKind(Map<SpanKind, SpanSuppressor> delegates) {
this.delegates = delegates;
}
@Override
public Context storeInContext(Context context, SpanKind spanKind, Span span) {
SpanSuppressor delegate = delegates.get(spanKind);
if (delegate == null) {
return context;
}
return delegate.storeInContext(context, spanKind, span);
}
@Override
public boolean shouldSuppress(Context parentContext, SpanKind spanKind) {
SpanSuppressor delegate = delegates.get(spanKind);
if (delegate == null) {
return false;
}
return delegate.shouldSuppress(parentContext, spanKind);
}
}
static final class BySpanKey implements SpanSuppressor {
private final Set<SpanKey> spanKeys;
BySpanKey(Set<SpanKey> spanKeys) {
this.spanKeys = spanKeys;
}
@Override
public Context storeInContext(Context context, SpanKind spanKind, Span span) {
for (SpanKey spanKey : spanKeys) {
context = spanKey.storeInContext(context, span);
}
return context;
}
@Override
public boolean shouldSuppress(Context parentContext, SpanKind spanKind) {
for (SpanKey spanKey : spanKeys) {
if (spanKey.fromContextOrNull(parentContext) == null) {
return false;
}
}
return true;
}
}
}