Skip to content

Commit 56bf70c

Browse files
committed
spotless apply
1 parent cc7af45 commit 56bf70c

File tree

2 files changed

+118
-107
lines changed

2 files changed

+118
-107
lines changed

awsagentprovider/src/main/java/software/amazon/opentelemetry/javaagent/providers/AwsUnsampledOnlySpanProcessorBuilder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515

1616
package software.amazon.opentelemetry.javaagent.providers;
1717

18+
import static java.util.Objects.requireNonNull;
19+
1820
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
19-
import io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder;
2021
import io.opentelemetry.sdk.trace.export.SpanExporter;
2122

22-
import static java.util.Objects.requireNonNull;
23-
2423
final class AwsUnsampledOnlySpanProcessorBuilder {
2524

2625
// Default exporter is OtlpUdpSpanExporter with unsampled payload prefix
27-
private SpanExporter exporter = new OtlpUdpSpanExporterBuilder()
26+
private SpanExporter exporter =
27+
new OtlpUdpSpanExporterBuilder()
2828
.setPayloadSampleDecision(TracePayloadSampleDecision.UNSAMPLED)
2929
.build();
3030

@@ -40,7 +40,7 @@ public AwsUnsampledOnlySpanProcessorBuilder setMaxQueueSize(int maxQueueSize) {
4040
}
4141

4242
public AwsUnsampledOnlySpanProcessor build() {
43-
BatchSpanProcessor bsp =
43+
BatchSpanProcessor bsp =
4444
BatchSpanProcessor.builder(exporter).setExportUnsampledSpans(true).build();
4545
return new AwsUnsampledOnlySpanProcessor(bsp);
4646
}
Lines changed: 113 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,129 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
116
package software.amazon.opentelemetry.javaagent.providers;
217

18+
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.mockito.Mockito.*;
20+
321
import io.opentelemetry.api.trace.SpanContext;
422
import io.opentelemetry.context.Context;
523
import io.opentelemetry.sdk.common.CompletableResultCode;
624
import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter;
725
import io.opentelemetry.sdk.trace.ReadWriteSpan;
826
import io.opentelemetry.sdk.trace.ReadableSpan;
927
import io.opentelemetry.sdk.trace.SpanProcessor;
10-
import io.opentelemetry.sdk.trace.data.SpanData;
1128
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
1229
import io.opentelemetry.sdk.trace.export.SpanExporter;
1330
import org.junit.jupiter.api.Test;
14-
import org.mockito.ArgumentCaptor;
15-
16-
import java.util.Collection;
17-
18-
import static org.assertj.core.api.Assertions.assertThat;
19-
import static org.mockito.Mockito.*;
2031

2132
public class AwsUnsampledOnlySpanProcessorTest {
2233

23-
@Test
24-
public void testDefaultSpanProcessor() {
25-
AwsUnsampledOnlySpanProcessorBuilder builder = AwsUnsampledOnlySpanProcessor.builder();
26-
AwsUnsampledOnlySpanProcessor unsampledSP = builder.build();
27-
28-
assertThat(builder.getSpanExporter()).isInstanceOf(OtlpUdpSpanExporter.class);
29-
SpanProcessor delegate = unsampledSP.getDelegate();
30-
assertThat(delegate).isInstanceOf(BatchSpanProcessor.class);
31-
BatchSpanProcessor delegateBsp = (BatchSpanProcessor) delegate;
32-
String delegateBspString = delegateBsp.toString();
33-
assertThat(delegateBspString).contains("spanExporter=software.amazon.opentelemetry.javaagent.providers.OtlpUdpSpanExporter");
34-
assertThat(delegateBspString).contains("exportUnsampledSpans=true");
35-
}
36-
37-
@Test
38-
public void testSpanProcessorWithExporter() {
39-
AwsUnsampledOnlySpanProcessorBuilder builder = AwsUnsampledOnlySpanProcessor
40-
.builder()
41-
.setSpanExporter(InMemorySpanExporter.create());
42-
AwsUnsampledOnlySpanProcessor unsampledSP = builder.build();
43-
44-
assertThat(builder.getSpanExporter()).isInstanceOf(InMemorySpanExporter.class);
45-
SpanProcessor delegate = unsampledSP.getDelegate();
46-
assertThat(delegate).isInstanceOf(BatchSpanProcessor.class);
47-
BatchSpanProcessor delegateBsp = (BatchSpanProcessor) delegate;
48-
String delegateBspString = delegateBsp.toString();
49-
assertThat(delegateBspString).contains("spanExporter=io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter");
50-
assertThat(delegateBspString).contains("exportUnsampledSpans=true");
51-
}
52-
53-
@Test
54-
public void testStartAddsAttributeToSampledSpan() {
55-
SpanContext mockSpanContext = mock(SpanContext.class);
56-
when(mockSpanContext.isSampled()).thenReturn(true);
57-
Context parentContextMock = mock(Context.class);
58-
ReadWriteSpan spanMock = mock(ReadWriteSpan.class);
59-
when(spanMock.getSpanContext()).thenReturn(mockSpanContext);
60-
61-
AwsUnsampledOnlySpanProcessor processor = AwsUnsampledOnlySpanProcessor.builder().build();
62-
processor.onStart(parentContextMock, spanMock);
63-
64-
//verify setAttribute was called with the correct arguments
65-
verify(spanMock, times(1)).setAttribute(AwsAttributeKeys.AWS_TRACE_FLAG_SAMPLED, true);
66-
}
67-
68-
@Test
69-
public void testStartAddsAttributeToUnsampledSpan() {
70-
SpanContext mockSpanContext = mock(SpanContext.class);
71-
when(mockSpanContext.isSampled()).thenReturn(false);
72-
Context parentContextMock = mock(Context.class);
73-
ReadWriteSpan spanMock = mock(ReadWriteSpan.class);
74-
when(spanMock.getSpanContext()).thenReturn(mockSpanContext);
75-
76-
AwsUnsampledOnlySpanProcessor processor = AwsUnsampledOnlySpanProcessor.builder().build();
77-
processor.onStart(parentContextMock, spanMock);
78-
79-
//verify setAttribute was called with the correct arguments
80-
verify(spanMock, times(1)).setAttribute(AwsAttributeKeys.AWS_TRACE_FLAG_SAMPLED, false);
81-
}
82-
83-
@Test
84-
public void testExportsOnlyUnsampledSpans() {
85-
SpanExporter mockExporter = mock(SpanExporter.class);
86-
when(mockExporter.export(anyCollection())).thenReturn(CompletableResultCode.ofSuccess());
87-
88-
BatchSpanProcessor delegate = BatchSpanProcessor.builder(mockExporter)
89-
.setExportUnsampledSpans(true)
90-
.setMaxExportBatchSize(1)
91-
.setMaxQueueSize(1)
92-
.build();
93-
94-
AwsUnsampledOnlySpanProcessor processor = new AwsUnsampledOnlySpanProcessor(delegate);
95-
96-
// unsampled span
97-
SpanContext mockSpanContextUnsampled = mock(SpanContext.class);
98-
when(mockSpanContextUnsampled.isSampled()).thenReturn(false);
99-
ReadableSpan mockSpanUnsampled = mock(ReadableSpan.class);
100-
when(mockSpanUnsampled.getSpanContext()).thenReturn(mockSpanContextUnsampled);
101-
102-
// sampled span
103-
SpanContext mockSpanContextSampled = mock(SpanContext.class);
104-
when(mockSpanContextSampled.isSampled()).thenReturn(true);
105-
ReadableSpan mockSpanSampled = mock(ReadableSpan.class);
106-
when(mockSpanSampled.getSpanContext()).thenReturn(mockSpanContextSampled);
107-
108-
// flush the unsampled span and verify export was called once
109-
processor.onEnd(mockSpanUnsampled);
110-
processor.forceFlush();
111-
verify(mockExporter, times(1)).export(anyCollection());
112-
113-
// flush the sampled span and verify export was not called again
114-
processor.onEnd(mockSpanSampled);
115-
processor.forceFlush();
116-
verify(mockExporter, times(1)).export(anyCollection());
117-
}
34+
@Test
35+
public void testDefaultSpanProcessor() {
36+
AwsUnsampledOnlySpanProcessorBuilder builder = AwsUnsampledOnlySpanProcessor.builder();
37+
AwsUnsampledOnlySpanProcessor unsampledSP = builder.build();
38+
39+
assertThat(builder.getSpanExporter()).isInstanceOf(OtlpUdpSpanExporter.class);
40+
SpanProcessor delegate = unsampledSP.getDelegate();
41+
assertThat(delegate).isInstanceOf(BatchSpanProcessor.class);
42+
BatchSpanProcessor delegateBsp = (BatchSpanProcessor) delegate;
43+
String delegateBspString = delegateBsp.toString();
44+
assertThat(delegateBspString)
45+
.contains(
46+
"spanExporter=software.amazon.opentelemetry.javaagent.providers.OtlpUdpSpanExporter");
47+
assertThat(delegateBspString).contains("exportUnsampledSpans=true");
48+
}
49+
50+
@Test
51+
public void testSpanProcessorWithExporter() {
52+
AwsUnsampledOnlySpanProcessorBuilder builder =
53+
AwsUnsampledOnlySpanProcessor.builder().setSpanExporter(InMemorySpanExporter.create());
54+
AwsUnsampledOnlySpanProcessor unsampledSP = builder.build();
55+
56+
assertThat(builder.getSpanExporter()).isInstanceOf(InMemorySpanExporter.class);
57+
SpanProcessor delegate = unsampledSP.getDelegate();
58+
assertThat(delegate).isInstanceOf(BatchSpanProcessor.class);
59+
BatchSpanProcessor delegateBsp = (BatchSpanProcessor) delegate;
60+
String delegateBspString = delegateBsp.toString();
61+
assertThat(delegateBspString)
62+
.contains("spanExporter=io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter");
63+
assertThat(delegateBspString).contains("exportUnsampledSpans=true");
64+
}
65+
66+
@Test
67+
public void testStartAddsAttributeToSampledSpan() {
68+
SpanContext mockSpanContext = mock(SpanContext.class);
69+
when(mockSpanContext.isSampled()).thenReturn(true);
70+
Context parentContextMock = mock(Context.class);
71+
ReadWriteSpan spanMock = mock(ReadWriteSpan.class);
72+
when(spanMock.getSpanContext()).thenReturn(mockSpanContext);
73+
74+
AwsUnsampledOnlySpanProcessor processor = AwsUnsampledOnlySpanProcessor.builder().build();
75+
processor.onStart(parentContextMock, spanMock);
76+
77+
// verify setAttribute was called with the correct arguments
78+
verify(spanMock, times(1)).setAttribute(AwsAttributeKeys.AWS_TRACE_FLAG_SAMPLED, true);
79+
}
80+
81+
@Test
82+
public void testStartAddsAttributeToUnsampledSpan() {
83+
SpanContext mockSpanContext = mock(SpanContext.class);
84+
when(mockSpanContext.isSampled()).thenReturn(false);
85+
Context parentContextMock = mock(Context.class);
86+
ReadWriteSpan spanMock = mock(ReadWriteSpan.class);
87+
when(spanMock.getSpanContext()).thenReturn(mockSpanContext);
88+
89+
AwsUnsampledOnlySpanProcessor processor = AwsUnsampledOnlySpanProcessor.builder().build();
90+
processor.onStart(parentContextMock, spanMock);
91+
92+
// verify setAttribute was called with the correct arguments
93+
verify(spanMock, times(1)).setAttribute(AwsAttributeKeys.AWS_TRACE_FLAG_SAMPLED, false);
94+
}
95+
96+
@Test
97+
public void testExportsOnlyUnsampledSpans() {
98+
SpanExporter mockExporter = mock(SpanExporter.class);
99+
when(mockExporter.export(anyCollection())).thenReturn(CompletableResultCode.ofSuccess());
100+
101+
AwsUnsampledOnlySpanProcessor processor =
102+
AwsUnsampledOnlySpanProcessor.builder().setSpanExporter(mockExporter).build();
103+
104+
BatchSpanProcessor delegate =
105+
BatchSpanProcessor.builder(mockExporter).setExportUnsampledSpans(true).build();
106+
107+
// unsampled span
108+
SpanContext mockSpanContextUnsampled = mock(SpanContext.class);
109+
when(mockSpanContextUnsampled.isSampled()).thenReturn(false);
110+
ReadableSpan mockSpanUnsampled = mock(ReadableSpan.class);
111+
when(mockSpanUnsampled.getSpanContext()).thenReturn(mockSpanContextUnsampled);
112+
113+
// sampled span
114+
SpanContext mockSpanContextSampled = mock(SpanContext.class);
115+
when(mockSpanContextSampled.isSampled()).thenReturn(true);
116+
ReadableSpan mockSpanSampled = mock(ReadableSpan.class);
117+
when(mockSpanSampled.getSpanContext()).thenReturn(mockSpanContextSampled);
118+
119+
// flush the unsampled span and verify export was called once
120+
processor.onEnd(mockSpanUnsampled);
121+
processor.forceFlush();
122+
verify(mockExporter, times(1)).export(anyCollection());
123+
124+
// flush the sampled span and verify export was not called again
125+
processor.onEnd(mockSpanSampled);
126+
processor.forceFlush();
127+
verify(mockExporter, times(1)).export(anyCollection());
128+
}
118129
}

0 commit comments

Comments
 (0)