forked from open-telemetry/opentelemetry-java-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelegatingSamplerTest.java
More file actions
62 lines (47 loc) · 1.79 KB
/
DelegatingSamplerTest.java
File metadata and controls
62 lines (47 loc) · 1.79 KB
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
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.contrib.dynamic.sampler;
import static org.assertj.core.api.Assertions.assertThat;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import io.opentelemetry.sdk.trace.samplers.SamplingDecision;
import io.opentelemetry.sdk.trace.samplers.SamplingResult;
import java.util.Collections;
import org.junit.jupiter.api.Test;
class DelegatingSamplerTest {
@Test
void defaultDelegateIsAlwaysOn() {
DelegatingSampler sampler = new DelegatingSampler();
SamplingDecision decision = doSample(sampler);
assertThat(decision).isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
}
@Test
void setDelegateNullFallsBackToAlwaysOn() {
DelegatingSampler sampler = new DelegatingSampler(Sampler.alwaysOff());
sampler.setDelegate(null);
SamplingDecision decision = doSample(sampler);
assertThat(decision).isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
}
@Test
void shouldSampleDelegatesToCurrentSamplerAfterUpdate() {
DelegatingSampler sampler = new DelegatingSampler(Sampler.alwaysOff());
assertThat(doSample(sampler)).isEqualTo(SamplingDecision.DROP);
sampler.setDelegate(Sampler.alwaysOn());
assertThat(doSample(sampler)).isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
}
private static SamplingDecision doSample(DelegatingSampler sampler) {
SamplingResult result =
sampler.shouldSample(
Context.root(),
"00000000000000000000000000000001",
"test-span",
SpanKind.INTERNAL,
Attributes.empty(),
Collections.emptyList());
return result.getDecision();
}
}