Skip to content

Commit 1649a90

Browse files
author
Mateusz Rzeszutek
authored
Add protocol name&version to net attribute getters (#7994)
In preparation for open-telemetry/opentelemetry-specification#3272
1 parent 998e781 commit 1649a90

File tree

24 files changed

+111
-201
lines changed

24 files changed

+111
-201
lines changed

instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingAttributesExtractor.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST
8181
SemanticAttributes.MESSAGING_DESTINATION_NAME,
8282
getter.getDestination(request));
8383
}
84-
internalSet(attributes, SemanticAttributes.NET_APP_PROTOCOL_NAME, getter.getProtocol(request));
85-
internalSet(
86-
attributes,
87-
SemanticAttributes.NET_APP_PROTOCOL_VERSION,
88-
getter.getProtocolVersion(request));
8984
internalSet(
9085
attributes,
9186
SemanticAttributes.MESSAGING_MESSAGE_CONVERSATION_ID,

instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingAttributesGetter.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static java.util.Collections.emptyList;
99

10+
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
1011
import java.util.List;
1112
import javax.annotation.Nullable;
1213

@@ -30,11 +31,27 @@ public interface MessagingAttributesGetter<REQUEST, RESPONSE> {
3031

3132
boolean isTemporaryDestination(REQUEST request);
3233

34+
/**
35+
* Returns the application protocol used.
36+
*
37+
* @deprecated Use {@link NetClientAttributesGetter#getProtocolName(Object, Object)} instead.
38+
*/
39+
@Deprecated
3340
@Nullable
34-
String getProtocol(REQUEST request);
41+
default String getProtocol(REQUEST request) {
42+
return null;
43+
}
3544

45+
/**
46+
* Returns the version of the application protocol used.
47+
*
48+
* @deprecated Use {@link NetClientAttributesGetter#getProtocolVersion(Object, Object)} instead.
49+
*/
50+
@Deprecated
3651
@Nullable
37-
String getProtocolVersion(REQUEST request);
52+
default String getProtocolVersion(REQUEST request) {
53+
return null;
54+
}
3855

3956
/**
4057
* Returns the application protocol used.

instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesGetter.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,28 @@ public interface NetClientAttributesGetter<REQUEST, RESPONSE> {
2020
@Nullable
2121
String getTransport(REQUEST request, @Nullable RESPONSE response);
2222

23+
// TODO: make required after the 1.24 release
24+
/**
25+
* Returns the application protocol used.
26+
*
27+
* <p>Examples: `amqp`, `http`, `mqtt`.
28+
*/
29+
@Nullable
30+
default String getProtocolName(REQUEST request, @Nullable RESPONSE response) {
31+
return null;
32+
}
33+
34+
// TODO: make required after the 1.24 release
35+
/**
36+
* Returns the version of the application protocol used.
37+
*
38+
* <p>Examples: `3.1.1`.
39+
*/
40+
@Nullable
41+
default String getProtocolVersion(REQUEST request, @Nullable RESPONSE response) {
42+
return null;
43+
}
44+
2345
@Nullable
2446
String getPeerName(REQUEST request);
2547

instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesGetter.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ public interface NetServerAttributesGetter<REQUEST> {
2020
@Nullable
2121
String getTransport(REQUEST request);
2222

23+
/**
24+
* Returns the application protocol used.
25+
*
26+
* <p>Examples: `amqp`, `http`, `mqtt`.
27+
*/
28+
@Nullable
29+
default String getProtocolName(REQUEST request) {
30+
return null;
31+
}
32+
33+
/**
34+
* Returns the version of the application protocol used.
35+
*
36+
* <p>Examples: `3.1.1`.
37+
*/
38+
@Nullable
39+
default String getProtocolVersion(REQUEST request) {
40+
return null;
41+
}
42+
2343
@Nullable
2444
String getHostName(REQUEST request);
2545

instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetClientAttributesExtractor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPO
4949

5050
internalSet(
5151
attributes, SemanticAttributes.NET_TRANSPORT, getter.getTransport(request, response));
52+
internalSet(
53+
attributes,
54+
SemanticAttributes.NET_APP_PROTOCOL_NAME,
55+
getter.getProtocolName(request, response));
56+
internalSet(
57+
attributes,
58+
SemanticAttributes.NET_APP_PROTOCOL_VERSION,
59+
getter.getProtocolVersion(request, response));
5260

5361
String peerName = extractPeerName(request);
5462

instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetServerAttributesExtractor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ public InternalNetServerAttributesExtractor(
3232
}
3333

3434
public void onStart(AttributesBuilder attributes, REQUEST request) {
35+
3536
internalSet(attributes, SemanticAttributes.NET_TRANSPORT, getter.getTransport(request));
37+
internalSet(
38+
attributes, SemanticAttributes.NET_APP_PROTOCOL_NAME, getter.getProtocolName(request));
39+
internalSet(
40+
attributes,
41+
SemanticAttributes.NET_APP_PROTOCOL_VERSION,
42+
getter.getProtocolVersion(request));
3643

3744
boolean setSockFamily = false;
3845

instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingAttributesExtractorTest.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ void shouldExtractAllAvailableAttributes(
4343
if (temporary) {
4444
request.put("temporaryDestination", "y");
4545
}
46-
request.put("protocol", "AMQP");
47-
request.put("protocolVersion", "1.0.0");
4846
request.put("url", "http://broker/topic");
4947
request.put("conversationId", "42");
5048
request.put("payloadSize", "100");
@@ -70,8 +68,6 @@ void shouldExtractAllAvailableAttributes(
7068
if (temporary) {
7169
expectedEntries.add(entry(SemanticAttributes.MESSAGING_DESTINATION_TEMPORARY, true));
7270
}
73-
expectedEntries.add(entry(SemanticAttributes.NET_APP_PROTOCOL_NAME, "AMQP"));
74-
expectedEntries.add(entry(SemanticAttributes.NET_APP_PROTOCOL_VERSION, "1.0.0"));
7571
expectedEntries.add(entry(SemanticAttributes.MESSAGING_MESSAGE_CONVERSATION_ID, "42"));
7672
expectedEntries.add(entry(SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES, 100L));
7773
expectedEntries.add(
@@ -137,16 +133,6 @@ public boolean isTemporaryDestination(Map<String, String> request) {
137133
return request.containsKey("temporaryDestination");
138134
}
139135

140-
@Override
141-
public String getProtocol(Map<String, String> request) {
142-
return request.get("protocol");
143-
}
144-
145-
@Override
146-
public String getProtocolVersion(Map<String, String> request) {
147-
return request.get("protocolVersion");
148-
}
149-
150136
@Override
151137
public String getConversationId(Map<String, String> request) {
152138
return request.get("conversationId");

instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
1818
import java.util.HashMap;
1919
import java.util.Map;
20+
import javax.annotation.Nullable;
2021
import org.junit.jupiter.api.DisplayName;
2122
import org.junit.jupiter.api.Test;
2223

@@ -30,6 +31,20 @@ public String getTransport(Map<String, String> request, Map<String, String> resp
3031
return response.get("transport");
3132
}
3233

34+
@Nullable
35+
@Override
36+
public String getProtocolName(
37+
Map<String, String> request, @Nullable Map<String, String> response) {
38+
return request.get("protocolName");
39+
}
40+
41+
@Nullable
42+
@Override
43+
public String getProtocolVersion(
44+
Map<String, String> request, @Nullable Map<String, String> response) {
45+
return request.get("protocolVersion");
46+
}
47+
3348
@Override
3449
public String getPeerName(Map<String, String> request) {
3550
return request.get("peerName");
@@ -71,6 +86,8 @@ void normal() {
7186
// given
7287
Map<String, String> map = new HashMap<>();
7388
map.put("transport", IP_TCP);
89+
map.put("protocolName", "http");
90+
map.put("protocolVersion", "1.1");
7491
map.put("peerName", "opentelemetry.io");
7592
map.put("peerPort", "42");
7693
map.put("sockFamily", "inet6");
@@ -96,6 +113,8 @@ void normal() {
96113
assertThat(endAttributes.build())
97114
.containsOnly(
98115
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP),
116+
entry(SemanticAttributes.NET_APP_PROTOCOL_NAME, "http"),
117+
entry(SemanticAttributes.NET_APP_PROTOCOL_VERSION, "1.1"),
99118
entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"),
100119
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"),
101120
entry(SemanticAttributes.NET_SOCK_PEER_NAME, "proxy.opentelemetry.io"),

instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ public String getTransport(Map<String, String> request) {
3131
return request.get("transport");
3232
}
3333

34+
@Nullable
35+
@Override
36+
public String getProtocolName(Map<String, String> request) {
37+
return request.get("protocolName");
38+
}
39+
40+
@Nullable
41+
@Override
42+
public String getProtocolVersion(Map<String, String> request) {
43+
return request.get("protocolVersion");
44+
}
45+
3446
@Nullable
3547
@Override
3648
public String getHostName(Map<String, String> request) {
@@ -83,6 +95,8 @@ void normal() {
8395
// given
8496
Map<String, String> map = new HashMap<>();
8597
map.put("transport", IP_TCP);
98+
map.put("protocolName", "http");
99+
map.put("protocolVersion", "1.1");
86100
map.put("hostName", "opentelemetry.io");
87101
map.put("hostPort", "80");
88102
map.put("sockFamily", "inet6");
@@ -104,6 +118,8 @@ void normal() {
104118
assertThat(startAttributes.build())
105119
.containsOnly(
106120
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP),
121+
entry(SemanticAttributes.NET_APP_PROTOCOL_NAME, "http"),
122+
entry(SemanticAttributes.NET_APP_PROTOCOL_VERSION, "1.1"),
107123
entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"),
108124
entry(SemanticAttributes.NET_HOST_PORT, 80L),
109125
entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"),

instrumentation/apache-pulsar/apache-pulsar-2.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pulsar/v2_8/telemetry/PulsarMessagingAttributesGetter.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,6 @@ public boolean isTemporaryDestination(Message<?> message) {
3535
return false;
3636
}
3737

38-
@Nullable
39-
@Override
40-
public String getProtocol(Message<?> message) {
41-
return null;
42-
}
43-
44-
@Nullable
45-
@Override
46-
public String getProtocolVersion(Message<?> message) {
47-
return null;
48-
}
49-
5038
@Nullable
5139
@Override
5240
public String getConversationId(Message<?> message) {

0 commit comments

Comments
 (0)