22
33import static org .junit .jupiter .api .Assertions .assertEquals ;
44import static org .junit .jupiter .api .Assertions .assertNull ;
5+ import static org .junit .jupiter .api .Assertions .assertTrue ;
56
7+ import datadog .trace .api .TagMap ;
68import org .junit .jupiter .api .Test ;
79
810class SpanPrototypeTest {
911
12+ @ Test
13+ void noneHasNoIdentityAndNoTags () {
14+ assertNull (SpanPrototype .NONE .instrumentationName ());
15+ assertNull (SpanPrototype .NONE .operationName ());
16+ assertNull (SpanPrototype .NONE .spanType ());
17+ assertNull (SpanPrototype .NONE .integrationName ());
18+ assertTrue (SpanPrototype .NONE .tags ().isEmpty ());
19+ }
20+
21+ @ Test
22+ void gettersReflectBuilderState () {
23+ final SpanPrototype proto =
24+ SpanPrototype .builder ()
25+ .initInstrumentationName ("instr" )
26+ .initOperationName ("op" )
27+ .initSpanType ("web" )
28+ .initComponentAndIntegration ("netty" ) // sets integration name + component tag
29+ .build ();
30+
31+ assertEquals ("instr" , proto .instrumentationName ());
32+ assertEquals ("op" , proto .operationName ());
33+ assertEquals ("web" , proto .spanType ());
34+ assertEquals ("netty" , proto .integrationName ());
35+ assertEquals ("netty" , proto .tags ().getString (Tags .COMPONENT ));
36+ }
37+
38+ @ Test
39+ void initInstrumentationNamesTakesFirstElement () {
40+ final SpanPrototype proto =
41+ SpanPrototype .builder ().initInstrumentationNames (new String [] {"first" , "second" }).build ();
42+
43+ assertEquals ("first" , proto .instrumentationName ());
44+ }
45+
46+ @ Test
47+ void initInstrumentationNamesNullArrayLeavesNameUnset () {
48+ final SpanPrototype proto = SpanPrototype .builder ().initInstrumentationNames (null ).build ();
49+
50+ assertNull (proto .instrumentationName ());
51+ }
52+
53+ @ Test
54+ void initInstrumentationNamesEmptyArrayLeavesNameUnset () {
55+ final SpanPrototype proto =
56+ SpanPrototype .builder ().initInstrumentationNames (new String [0 ]).build ();
57+
58+ assertNull (proto .instrumentationName ());
59+ }
60+
61+ @ Test
62+ void extendsNullBaseIsNoOp () {
63+ final SpanPrototype proto = SpanPrototype .builder ().extends_ (null ).build ();
64+
65+ assertNull (proto .instrumentationName ());
66+ assertNull (proto .operationName ());
67+ assertNull (proto .spanType ());
68+ assertNull (proto .integrationName ());
69+ assertTrue (proto .tags ().isEmpty ());
70+ }
71+
72+ @ Test
73+ void extendsCopiesAllIdentityAndTags () {
74+ final SpanPrototype base =
75+ SpanPrototype .builder ()
76+ .initInstrumentationName ("base" )
77+ .initOperationName ("base.op" )
78+ .initSpanType ("base-type" )
79+ .initComponentAndIntegration ("base-comp" ) // integration name + component tag
80+ .initKind ("server" )
81+ .build ();
82+ final SpanPrototype derived = SpanPrototype .builder ().extends_ (base ).build ();
83+
84+ assertEquals ("base" , derived .instrumentationName ());
85+ assertEquals ("base.op" , derived .operationName ());
86+ assertEquals ("base-type" , derived .spanType ());
87+ assertEquals ("base-comp" , derived .integrationName ());
88+ assertEquals ("base-comp" , derived .tags ().getString (Tags .COMPONENT ));
89+ assertEquals ("server" , derived .tags ().getString (Tags .SPAN_KIND ));
90+ }
91+
1092 @ Test
1193 void extendsInheritsBaseIdentityAndTagsThenOverrides () {
1294 final SpanPrototype base =
@@ -28,6 +110,30 @@ void extendsInheritsBaseIdentityAndTagsThenOverrides() {
28110 assertEquals ("netty" , derived .tags ().getString (Tags .COMPONENT )); // added tag
29111 }
30112
113+ @ Test
114+ void initComponentAndIntegrationSetsBothComponentTagAndIntegrationName () {
115+ final SpanPrototype proto =
116+ SpanPrototype .builder ().initComponentAndIntegration ("netty" ).build ();
117+
118+ assertEquals ("netty" , proto .tags ().getString (Tags .COMPONENT ));
119+ assertEquals ("netty" , proto .integrationName ());
120+ }
121+
122+ @ Test
123+ void initComponentAndIntegrationEmptyIsNoOpForBoth () {
124+ final SpanPrototype proto = SpanPrototype .builder ().initComponentAndIntegration ("" ).build ();
125+
126+ assertNull (proto .tags ().getString (Tags .COMPONENT ));
127+ assertNull (proto .integrationName ());
128+ }
129+
130+ @ Test
131+ void initKindSetsSpanKindTag () {
132+ final SpanPrototype proto = SpanPrototype .builder ().initKind ("client" ).build ();
133+
134+ assertEquals ("client" , proto .tags ().getString (Tags .SPAN_KIND ));
135+ }
136+
31137 @ Test
32138 void emptyOrNullConstantsAreDroppedNotBaked () {
33139 // Match AgentSpan.setTag / the cached-Entry path: a null or empty constant is "no tag", not an
@@ -49,4 +155,26 @@ void emptyOrNullConstantsAreDroppedNotBaked() {
49155 assertNull (proto .tags ().getString ("null.obj" ));
50156 assertEquals ("v" , proto .tags ().getString ("kept" )); // sanity: non-empty still stored
51157 }
158+
159+ @ Test
160+ void initTagObjectStoresNonEmptyValue () {
161+ final SpanPrototype proto = SpanPrototype .builder ().initTag ("count" , (Object ) 42 ).build ();
162+
163+ assertEquals (42 , proto .tags ().get ("count" ));
164+ }
165+
166+ @ Test
167+ void initTagEntryReaderStoresEntry () {
168+ final TagMap .EntryReader entry = TagMap .Entry .create ("cached" , "value" );
169+ final SpanPrototype proto = SpanPrototype .builder ().initTag (entry ).build ();
170+
171+ assertEquals ("value" , proto .tags ().getString ("cached" ));
172+ }
173+
174+ @ Test
175+ void initTagNullEntryReaderIsNoOp () {
176+ final SpanPrototype proto = SpanPrototype .builder ().initTag ((TagMap .EntryReader ) null ).build ();
177+
178+ assertTrue (proto .tags ().isEmpty ());
179+ }
52180}
0 commit comments