1
1
package io .quarkus .opentelemetry .deployment ;
2
2
3
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
4
+
3
5
import java .lang .reflect .InvocationTargetException ;
6
+ import java .util .concurrent .atomic .AtomicLong ;
4
7
8
+ import jakarta .enterprise .context .ApplicationScoped ;
9
+ import jakarta .enterprise .inject .Produces ;
5
10
import jakarta .inject .Inject ;
6
11
7
- import org .junit .jupiter .api .Disabled ;
12
+ import org .junit .jupiter .api .MethodOrderer ;
13
+ import org .junit .jupiter .api .Order ;
8
14
import org .junit .jupiter .api .Test ;
15
+ import org .junit .jupiter .api .TestMethodOrder ;
9
16
import org .junit .jupiter .api .extension .RegisterExtension ;
10
17
11
18
import io .opentelemetry .api .OpenTelemetry ;
12
- // import io.opentelemetry.contrib.awsxray.AwsXrayIdGenerator;
19
+ import io .opentelemetry .api .trace .Span ;
20
+ import io .opentelemetry .api .trace .Tracer ;
13
21
import io .opentelemetry .sdk .trace .IdGenerator ;
14
22
import io .quarkus .opentelemetry .deployment .common .TestUtil ;
15
23
import io .quarkus .test .QuarkusUnitTest ;
16
24
17
- @ Disabled ( "We need to move the AWS dependency testing to an independent module" )
25
+ @ TestMethodOrder ( MethodOrderer . OrderAnnotation . class )
18
26
public class OpenTelemetryIdGeneratorTest {
19
27
@ RegisterExtension
20
28
static final QuarkusUnitTest unitTest = new QuarkusUnitTest ()
@@ -24,18 +32,51 @@ public class OpenTelemetryIdGeneratorTest {
24
32
OpenTelemetry openTelemetry ;
25
33
26
34
@ Test
27
- void test () throws NoSuchFieldException , IllegalAccessException , InvocationTargetException , NoSuchMethodException {
35
+ @ Order (1 )
36
+ void testGenerateIds ()
37
+ throws NoSuchFieldException , IllegalAccessException , InvocationTargetException , NoSuchMethodException {
28
38
IdGenerator idGenerator = TestUtil .getIdGenerator (openTelemetry );
39
+ String spanId = idGenerator .generateSpanId ();
40
+ String traceId = idGenerator .generateTraceId ();
41
+
42
+ assertEquals (String .format ("%016d" , OtelConfiguration .SPAN_START_NUMBER + 1 ), spanId );
43
+ assertEquals (String .format ("%032d" , OtelConfiguration .TRACE_START_NUMBER + 1 ), traceId );
44
+ }
45
+
46
+ @ Test
47
+ @ Order (2 )
48
+ void testGenerateSpan () {
49
+ Tracer testTracer = openTelemetry .getTracer ("io.quarkus.opentelemetry.deployment" );
50
+ Span testSpan = testTracer .spanBuilder ("testSpan" ).startSpan ();
51
+ testSpan .end ();
29
52
30
- // assertThat(idGenerator, instanceOf(AwsXrayIdGenerator.class));
53
+ String generatedSpanId = testSpan .getSpanContext ().getSpanId ();
54
+ String generatedTraceId = testSpan .getSpanContext ().getTraceId ();
55
+ assertEquals (String .format ("%016d" , OtelConfiguration .SPAN_START_NUMBER + 2 ), generatedSpanId );
56
+ assertEquals (String .format ("%032d" , OtelConfiguration .TRACE_START_NUMBER + 2 ), generatedTraceId );
31
57
}
32
58
33
- // @ApplicationScoped
34
- // public static class OtelConfiguration {
35
- //
36
- // @Produces
37
- // public IdGenerator idGenerator() {
38
- // return AwsXrayIdGenerator.getInstance();
39
- // }
40
- // }
59
+ @ ApplicationScoped
60
+ public static class OtelConfiguration {
61
+ static final long TRACE_START_NUMBER = 42 ;
62
+ static final long SPAN_START_NUMBER = 42 ;
63
+
64
+ @ Produces
65
+ public IdGenerator idGenerator () {
66
+ return new IdGenerator () {
67
+ final AtomicLong traceId = new AtomicLong (OtelConfiguration .TRACE_START_NUMBER );
68
+ final AtomicLong spanId = new AtomicLong (OtelConfiguration .SPAN_START_NUMBER );
69
+
70
+ @ Override
71
+ public String generateSpanId () {
72
+ return String .format ("%016d" , spanId .incrementAndGet ());
73
+ }
74
+
75
+ @ Override
76
+ public String generateTraceId () {
77
+ return String .format ("%032d" , traceId .incrementAndGet ());
78
+ }
79
+ };
80
+ }
81
+ }
41
82
}
0 commit comments