55
66package io .opentelemetry .javaagent .instrumentation .kafkaclients .v0_11 ;
77
8+ import static io .opentelemetry .instrumentation .api .internal .SemconvStability .emitStableMessagingSemconv ;
89import static io .opentelemetry .instrumentation .testing .util .TelemetryDataUtil .orderByRootSpanKind ;
910import static io .opentelemetry .sdk .testing .assertj .OpenTelemetryAssertions .assertThat ;
1011import static java .nio .charset .StandardCharsets .UTF_8 ;
@@ -82,7 +83,10 @@ void testKafkaProducerAndConsumerSpan(boolean testHeaders) throws Exception {
8283 trace .hasSpansSatisfyingExactly (
8384 span -> span .hasName ("parent" ).hasKind (SpanKind .INTERNAL ).hasNoParent (),
8485 span ->
85- span .hasName (SHARED_TOPIC + " publish" )
86+ span .hasName (
87+ emitStableMessagingSemconv ()
88+ ? "publish " + SHARED_TOPIC
89+ : SHARED_TOPIC + " publish" )
8690 .hasKind (SpanKind .PRODUCER )
8791 .hasParent (trace .getSpan (0 ))
8892 .hasAttributesSatisfyingExactly (sendAttributes ("10" , greeting , testHeaders )),
@@ -95,12 +99,18 @@ void testKafkaProducerAndConsumerSpan(boolean testHeaders) throws Exception {
9599 trace ->
96100 trace .hasSpansSatisfyingExactly (
97101 span ->
98- span .hasName (SHARED_TOPIC + " receive" )
102+ span .hasName (
103+ emitStableMessagingSemconv ()
104+ ? "receive " + SHARED_TOPIC
105+ : SHARED_TOPIC + " receive" )
99106 .hasKind (SpanKind .CONSUMER )
100107 .hasNoParent ()
101108 .hasAttributesSatisfyingExactly (receiveAttributes (testHeaders )),
102109 span ->
103- span .hasName (SHARED_TOPIC + " process" )
110+ span .hasName (
111+ emitStableMessagingSemconv ()
112+ ? "process " + SHARED_TOPIC
113+ : SHARED_TOPIC + " process" )
104114 .hasKind (SpanKind .CONSUMER )
105115 .hasLinks (LinkData .create (producerSpan .get ().getSpanContext ()))
106116 .hasParent (trace .getSpan (0 ))
@@ -129,7 +139,10 @@ void testPassThroughTombstone() throws Exception {
129139 trace -> {
130140 trace .hasSpansSatisfyingExactly (
131141 span ->
132- span .hasName (SHARED_TOPIC + " publish" )
142+ span .hasName (
143+ emitStableMessagingSemconv ()
144+ ? "publish " + SHARED_TOPIC
145+ : SHARED_TOPIC + " publish" )
133146 .hasKind (SpanKind .PRODUCER )
134147 .hasNoParent ()
135148 .hasAttributesSatisfyingExactly (sendAttributes (null , null , false )));
@@ -138,12 +151,18 @@ void testPassThroughTombstone() throws Exception {
138151 trace ->
139152 trace .hasSpansSatisfyingExactly (
140153 span ->
141- span .hasName (SHARED_TOPIC + " receive" )
154+ span .hasName (
155+ emitStableMessagingSemconv ()
156+ ? "receive " + SHARED_TOPIC
157+ : SHARED_TOPIC + " receive" )
142158 .hasKind (SpanKind .CONSUMER )
143159 .hasNoParent ()
144160 .hasAttributesSatisfyingExactly (receiveAttributes (false )),
145161 span ->
146- span .hasName (SHARED_TOPIC + " process" )
162+ span .hasName (
163+ emitStableMessagingSemconv ()
164+ ? "process " + SHARED_TOPIC
165+ : SHARED_TOPIC + " process" )
147166 .hasKind (SpanKind .CONSUMER )
148167 .hasLinks (LinkData .create (producerSpan .get ().getSpanContext ()))
149168 .hasParent (trace .getSpan (0 ))
@@ -188,7 +207,10 @@ void testRecordsWithTopicPartitionKafkaConsume(boolean testListIterator) throws
188207 trace -> {
189208 trace .hasSpansSatisfyingExactly (
190209 span ->
191- span .hasName (SHARED_TOPIC + " publish" )
210+ span .hasName (
211+ emitStableMessagingSemconv ()
212+ ? "publish " + SHARED_TOPIC
213+ : SHARED_TOPIC + " publish" )
192214 .hasKind (SpanKind .PRODUCER )
193215 .hasNoParent ()
194216 .hasAttributesSatisfyingExactly (sendAttributes (null , greeting , false )));
@@ -197,12 +219,18 @@ void testRecordsWithTopicPartitionKafkaConsume(boolean testListIterator) throws
197219 trace ->
198220 trace .hasSpansSatisfyingExactly (
199221 span ->
200- span .hasName (SHARED_TOPIC + " receive" )
222+ span .hasName (
223+ emitStableMessagingSemconv ()
224+ ? "receive " + SHARED_TOPIC
225+ : SHARED_TOPIC + " receive" )
201226 .hasKind (SpanKind .CONSUMER )
202227 .hasNoParent ()
203228 .hasAttributesSatisfyingExactly (receiveAttributes (false )),
204229 span ->
205- span .hasName (SHARED_TOPIC + " process" )
230+ span .hasName (
231+ emitStableMessagingSemconv ()
232+ ? "process " + SHARED_TOPIC
233+ : SHARED_TOPIC + " process" )
206234 .hasKind (SpanKind .CONSUMER )
207235 .hasLinks (LinkData .create (producerSpan .get ().getSpanContext ()))
208236 .hasParent (trace .getSpan (0 ))
@@ -253,7 +281,10 @@ void testKafkaHeaderNull() throws Exception {
253281 trace .hasSpansSatisfyingExactly (
254282 span -> span .hasName ("parent" ).hasKind (SpanKind .INTERNAL ).hasNoParent (),
255283 span ->
256- span .hasName (SHARED_TOPIC + " publish" )
284+ span .hasName (
285+ emitStableMessagingSemconv ()
286+ ? "publish " + SHARED_TOPIC
287+ : SHARED_TOPIC + " publish" )
257288 .hasKind (SpanKind .PRODUCER )
258289 .hasParent (trace .getSpan (0 ))
259290 .hasAttributesSatisfyingExactly (sendAttributes ("10" , greeting , false )),
@@ -266,12 +297,18 @@ void testKafkaHeaderNull() throws Exception {
266297 trace ->
267298 trace .hasSpansSatisfyingExactly (
268299 span ->
269- span .hasName (SHARED_TOPIC + " receive" )
300+ span .hasName (
301+ emitStableMessagingSemconv ()
302+ ? "receive " + SHARED_TOPIC
303+ : SHARED_TOPIC + " receive" )
270304 .hasKind (SpanKind .CONSUMER )
271305 .hasNoParent ()
272306 .hasAttributesSatisfyingExactly (receiveAttributes (false )),
273307 span ->
274- span .hasName (SHARED_TOPIC + " process" )
308+ span .hasName (
309+ emitStableMessagingSemconv ()
310+ ? "process " + SHARED_TOPIC
311+ : SHARED_TOPIC + " process" )
275312 .hasKind (SpanKind .CONSUMER )
276313 .hasLinks (LinkData .create (producerSpan .get ().getSpanContext ()))
277314 .hasParent (trace .getSpan (0 ))
0 commit comments