Skip to content

Commit

Permalink
Add protocol name&version to net attribute getters (#7994)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek authored Mar 9, 2023
1 parent 998e781 commit 1649a90
Show file tree
Hide file tree
Showing 24 changed files with 111 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST
SemanticAttributes.MESSAGING_DESTINATION_NAME,
getter.getDestination(request));
}
internalSet(attributes, SemanticAttributes.NET_APP_PROTOCOL_NAME, getter.getProtocol(request));
internalSet(
attributes,
SemanticAttributes.NET_APP_PROTOCOL_VERSION,
getter.getProtocolVersion(request));
internalSet(
attributes,
SemanticAttributes.MESSAGING_MESSAGE_CONVERSATION_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static java.util.Collections.emptyList;

import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import java.util.List;
import javax.annotation.Nullable;

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

boolean isTemporaryDestination(REQUEST request);

/**
* Returns the application protocol used.
*
* @deprecated Use {@link NetClientAttributesGetter#getProtocolName(Object, Object)} instead.
*/
@Deprecated
@Nullable
String getProtocol(REQUEST request);
default String getProtocol(REQUEST request) {
return null;
}

/**
* Returns the version of the application protocol used.
*
* @deprecated Use {@link NetClientAttributesGetter#getProtocolVersion(Object, Object)} instead.
*/
@Deprecated
@Nullable
String getProtocolVersion(REQUEST request);
default String getProtocolVersion(REQUEST request) {
return null;
}

/**
* Returns the application protocol used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ public interface NetClientAttributesGetter<REQUEST, RESPONSE> {
@Nullable
String getTransport(REQUEST request, @Nullable RESPONSE response);

// TODO: make required after the 1.24 release
/**
* Returns the application protocol used.
*
* <p>Examples: `amqp`, `http`, `mqtt`.
*/
@Nullable
default String getProtocolName(REQUEST request, @Nullable RESPONSE response) {
return null;
}

// TODO: make required after the 1.24 release
/**
* Returns the version of the application protocol used.
*
* <p>Examples: `3.1.1`.
*/
@Nullable
default String getProtocolVersion(REQUEST request, @Nullable RESPONSE response) {
return null;
}

@Nullable
String getPeerName(REQUEST request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ public interface NetServerAttributesGetter<REQUEST> {
@Nullable
String getTransport(REQUEST request);

/**
* Returns the application protocol used.
*
* <p>Examples: `amqp`, `http`, `mqtt`.
*/
@Nullable
default String getProtocolName(REQUEST request) {
return null;
}

/**
* Returns the version of the application protocol used.
*
* <p>Examples: `3.1.1`.
*/
@Nullable
default String getProtocolVersion(REQUEST request) {
return null;
}

@Nullable
String getHostName(REQUEST request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPO

internalSet(
attributes, SemanticAttributes.NET_TRANSPORT, getter.getTransport(request, response));
internalSet(
attributes,
SemanticAttributes.NET_APP_PROTOCOL_NAME,
getter.getProtocolName(request, response));
internalSet(
attributes,
SemanticAttributes.NET_APP_PROTOCOL_VERSION,
getter.getProtocolVersion(request, response));

String peerName = extractPeerName(request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ public InternalNetServerAttributesExtractor(
}

public void onStart(AttributesBuilder attributes, REQUEST request) {

internalSet(attributes, SemanticAttributes.NET_TRANSPORT, getter.getTransport(request));
internalSet(
attributes, SemanticAttributes.NET_APP_PROTOCOL_NAME, getter.getProtocolName(request));
internalSet(
attributes,
SemanticAttributes.NET_APP_PROTOCOL_VERSION,
getter.getProtocolVersion(request));

boolean setSockFamily = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ void shouldExtractAllAvailableAttributes(
if (temporary) {
request.put("temporaryDestination", "y");
}
request.put("protocol", "AMQP");
request.put("protocolVersion", "1.0.0");
request.put("url", "http://broker/topic");
request.put("conversationId", "42");
request.put("payloadSize", "100");
Expand All @@ -70,8 +68,6 @@ void shouldExtractAllAvailableAttributes(
if (temporary) {
expectedEntries.add(entry(SemanticAttributes.MESSAGING_DESTINATION_TEMPORARY, true));
}
expectedEntries.add(entry(SemanticAttributes.NET_APP_PROTOCOL_NAME, "AMQP"));
expectedEntries.add(entry(SemanticAttributes.NET_APP_PROTOCOL_VERSION, "1.0.0"));
expectedEntries.add(entry(SemanticAttributes.MESSAGING_MESSAGE_CONVERSATION_ID, "42"));
expectedEntries.add(entry(SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES, 100L));
expectedEntries.add(
Expand Down Expand Up @@ -137,16 +133,6 @@ public boolean isTemporaryDestination(Map<String, String> request) {
return request.containsKey("temporaryDestination");
}

@Override
public String getProtocol(Map<String, String> request) {
return request.get("protocol");
}

@Override
public String getProtocolVersion(Map<String, String> request) {
return request.get("protocolVersion");
}

@Override
public String getConversationId(Map<String, String> request) {
return request.get("conversationId");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

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

@Nullable
@Override
public String getProtocolName(
Map<String, String> request, @Nullable Map<String, String> response) {
return request.get("protocolName");
}

@Nullable
@Override
public String getProtocolVersion(
Map<String, String> request, @Nullable Map<String, String> response) {
return request.get("protocolVersion");
}

@Override
public String getPeerName(Map<String, String> request) {
return request.get("peerName");
Expand Down Expand Up @@ -71,6 +86,8 @@ void normal() {
// given
Map<String, String> map = new HashMap<>();
map.put("transport", IP_TCP);
map.put("protocolName", "http");
map.put("protocolVersion", "1.1");
map.put("peerName", "opentelemetry.io");
map.put("peerPort", "42");
map.put("sockFamily", "inet6");
Expand All @@ -96,6 +113,8 @@ void normal() {
assertThat(endAttributes.build())
.containsOnly(
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP),
entry(SemanticAttributes.NET_APP_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NET_APP_PROTOCOL_VERSION, "1.1"),
entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"),
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"),
entry(SemanticAttributes.NET_SOCK_PEER_NAME, "proxy.opentelemetry.io"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ public String getTransport(Map<String, String> request) {
return request.get("transport");
}

@Nullable
@Override
public String getProtocolName(Map<String, String> request) {
return request.get("protocolName");
}

@Nullable
@Override
public String getProtocolVersion(Map<String, String> request) {
return request.get("protocolVersion");
}

@Nullable
@Override
public String getHostName(Map<String, String> request) {
Expand Down Expand Up @@ -83,6 +95,8 @@ void normal() {
// given
Map<String, String> map = new HashMap<>();
map.put("transport", IP_TCP);
map.put("protocolName", "http");
map.put("protocolVersion", "1.1");
map.put("hostName", "opentelemetry.io");
map.put("hostPort", "80");
map.put("sockFamily", "inet6");
Expand All @@ -104,6 +118,8 @@ void normal() {
assertThat(startAttributes.build())
.containsOnly(
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP),
entry(SemanticAttributes.NET_APP_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NET_APP_PROTOCOL_VERSION, "1.1"),
entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"),
entry(SemanticAttributes.NET_HOST_PORT, 80L),
entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@ public boolean isTemporaryDestination(Message<?> message) {
return false;
}

@Nullable
@Override
public String getProtocol(Message<?> message) {
return null;
}

@Nullable
@Override
public String getProtocolVersion(Message<?> message) {
return null;
}

@Nullable
@Override
public String getConversationId(Message<?> message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@ public boolean isTemporaryDestination(MessageWithDestination messageWithDestinat
return messageWithDestination.isTemporaryDestination();
}

@Nullable
@Override
public String getProtocol(MessageWithDestination messageWithDestination) {
return null;
}

@Nullable
@Override
public String getProtocolVersion(MessageWithDestination messageWithDestination) {
return null;
}

@Nullable
@Override
public String getConversationId(MessageWithDestination messageWithDestination) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@ public boolean isTemporaryDestination(KafkaProcessRequest request) {
return false;
}

@Override
@Nullable
public String getProtocol(KafkaProcessRequest request) {
return null;
}

@Override
@Nullable
public String getProtocolVersion(KafkaProcessRequest request) {
return null;
}

@Override
@Nullable
public String getConversationId(KafkaProcessRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,6 @@ public boolean isTemporaryDestination(KafkaProducerRequest request) {
return false;
}

@Override
@Nullable
public String getProtocol(KafkaProducerRequest request) {
return null;
}

@Override
@Nullable
public String getProtocolVersion(KafkaProducerRequest request) {
return null;
}

@Override
@Nullable
public String getConversationId(KafkaProducerRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ public boolean isTemporaryDestination(KafkaReceiveRequest request) {
return false;
}

@Override
@Nullable
public String getProtocol(KafkaReceiveRequest request) {
return null;
}

@Override
@Nullable
public String getProtocolVersion(KafkaReceiveRequest request) {
return null;
}

@Override
@Nullable
public String getConversationId(KafkaReceiveRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@ public boolean isTemporaryDestination(ChannelAndMethod channelAndMethod) {
return false;
}

@Nullable
@Override
public String getProtocol(ChannelAndMethod channelAndMethod) {
return null;
}

@Nullable
@Override
public String getProtocolVersion(ChannelAndMethod channelAndMethod) {
return null;
}

@Nullable
@Override
public String getConversationId(ChannelAndMethod channelAndMethod) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,6 @@ public boolean isTemporaryDestination(DeliveryRequest request) {
return false;
}

@Nullable
@Override
public String getProtocol(DeliveryRequest request) {
return null;
}

@Nullable
@Override
public String getProtocolVersion(DeliveryRequest request) {
return null;
}

@Nullable
@Override
public String getConversationId(DeliveryRequest request) {
Expand Down
Loading

0 comments on commit 1649a90

Please sign in to comment.