use of io.opentelemetry.api.common.AttributesBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class InetSocketAddressNetServerAttributesGetterTest method unresolved.
@Test
void unresolved() {
// given
InetSocketAddress request = InetSocketAddress.createUnresolved("github.com", 123);
assertThat(request.getAddress()).isNull();
InetSocketAddress response = InetSocketAddress.createUnresolved("api.github.com", 456);
assertThat(request.getAddress()).isNull();
Context context = Context.root();
// when
AttributesBuilder startAttributes = Attributes.builder();
extractor.onStart(startAttributes, context, request);
AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, context, request, response, null);
// then
assertThat(startAttributes.build()).containsOnly(entry(SemanticAttributes.NET_TRANSPORT, SemanticAttributes.NetTransportValues.IP_TCP), entry(SemanticAttributes.NET_PEER_PORT, 123L));
assertThat(endAttributes.build()).isEmpty();
}
use of io.opentelemetry.api.common.AttributesBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class InetSocketAddressNetServerAttributesGetterTest method noInetSocketAddress.
@Test
void noInetSocketAddress() {
AttributesBuilder attributes = Attributes.builder();
extractor.onStart(attributes, Context.root(), null);
assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.NET_TRANSPORT, SemanticAttributes.NetTransportValues.IP_TCP));
}
use of io.opentelemetry.api.common.AttributesBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class NetServerAttributesExtractorTest method doesNotSetDuplicateAttributes.
@Test
public void doesNotSetDuplicateAttributes() {
// given
Map<String, String> request = new HashMap<>();
request.put("transport", "TCP");
request.put("peerName", "1.2.3.4");
request.put("peerIp", "1.2.3.4");
request.put("peerPort", "123");
Map<String, String> response = new HashMap<>();
response.put("peerName", "4.3.2.1");
response.put("peerPort", "42");
response.put("peerIp", "4.3.2.1");
NetServerAttributesExtractor<Map<String, String>, Map<String, String>> extractor = createTestExtractor();
Context context = Context.root();
// when
AttributesBuilder startAttributes = Attributes.builder();
extractor.onStart(startAttributes, context, request);
AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, context, request, response, null);
// then
assertThat(startAttributes.build()).containsOnly(entry(SemanticAttributes.NET_TRANSPORT, "TCP"), entry(SemanticAttributes.NET_PEER_PORT, 123L), entry(SemanticAttributes.NET_PEER_IP, "1.2.3.4"));
assertThat(endAttributes.build()).isEmpty();
}
use of io.opentelemetry.api.common.AttributesBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class NetServerAttributesExtractorTest method doesNotSetNegativePort.
@Test
public void doesNotSetNegativePort() {
// given
Map<String, String> request = new HashMap<>();
request.put("peerPort", "-42");
Map<String, String> response = new HashMap<>();
response.put("peerPort", "-1");
NetServerAttributesExtractor<Map<String, String>, Map<String, String>> extractor = createTestExtractor();
Context context = Context.root();
// when
AttributesBuilder startAttributes = Attributes.builder();
extractor.onStart(startAttributes, context, request);
AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, context, request, response, null);
// then
assertThat(startAttributes.build()).isEmpty();
assertThat(endAttributes.build()).isEmpty();
}
use of io.opentelemetry.api.common.AttributesBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class DbClientAttributesExtractorTest method shouldExtractAllAvailableAttributes.
@Test
void shouldExtractAllAvailableAttributes() {
// given
Map<String, String> request = new HashMap<>();
request.put("db.system", "myDb");
request.put("db.user", "username");
request.put("db.name", "potatoes");
request.put("db.connection_string", "mydb:///potatoes");
request.put("db.statement", "SELECT * FROM potato");
request.put("db.operation", "SELECT");
Context context = Context.root();
DbClientAttributesExtractor<Map<String, String>, Void> underTest = DbClientAttributesExtractor.create(new TestAttributesGetter());
// when
AttributesBuilder startAttributes = Attributes.builder();
underTest.onStart(startAttributes, context, request);
AttributesBuilder endAttributes = Attributes.builder();
underTest.onEnd(endAttributes, context, request, null, null);
// then
assertThat(startAttributes.build()).containsOnly(entry(SemanticAttributes.DB_SYSTEM, "myDb"), entry(SemanticAttributes.DB_USER, "username"), entry(SemanticAttributes.DB_NAME, "potatoes"), entry(SemanticAttributes.DB_CONNECTION_STRING, "mydb:///potatoes"), entry(SemanticAttributes.DB_STATEMENT, "SELECT * FROM potato"), entry(SemanticAttributes.DB_OPERATION, "SELECT"));
assertThat(endAttributes.build().isEmpty()).isTrue();
}
Aggregations