use of io.opentelemetry.api.common.AttributesBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class HttpServerAttributesExtractorTest method extractClientIpFromX_Forwarded_For.
@Test
void extractClientIpFromX_Forwarded_For() {
Map<String, String> request = new HashMap<>();
request.put("header.x-forwarded-for", "1.1.1.1");
HttpServerAttributesExtractor<Map<String, String>, Map<String, String>> extractor = HttpServerAttributesExtractor.builder(new TestHttpServerAttributesExtractor()).setCapturedRequestHeaders(emptyList()).setCapturedResponseHeaders(emptyList()).build();
AttributesBuilder attributes = Attributes.builder();
extractor.onStart(attributes, Context.root(), request);
assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.HTTP_CLIENT_IP, "1.1.1.1"));
extractor.onEnd(attributes, Context.root(), request, null, null);
assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.HTTP_CLIENT_IP, "1.1.1.1"));
}
use of io.opentelemetry.api.common.AttributesBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class InetSocketAddressNetClientAttributesGetterTest method noInetSocketAddress.
@Test
void noInetSocketAddress() {
AttributesBuilder attributes = Attributes.builder();
extractor.onEnd(attributes, Context.root(), null, null, 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 NetClientAttributesExtractorTest 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");
TestNetClientAttributesGetter getter = new TestNetClientAttributesGetter();
NetClientAttributesExtractor<Map<String, String>, Map<String, String>> extractor = NetClientAttributesExtractor.create(getter);
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()).containsOnly(entry(SemanticAttributes.NET_PEER_PORT, 42L), entry(SemanticAttributes.NET_PEER_IP, "4.3.2.1"));
}
use of io.opentelemetry.api.common.AttributesBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class NetClientAttributesExtractorTest 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");
TestNetClientAttributesGetter getter = new TestNetClientAttributesGetter();
NetClientAttributesExtractor<Map<String, String>, Map<String, String>> extractor = NetClientAttributesExtractor.create(getter);
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 RpcAttributesExtractorTest method normal.
@Test
void normal() {
Map<String, String> request = new HashMap<>();
request.put("service", "my.Service");
request.put("method", "Method");
Context context = Context.root();
TestExtractor extractor = new TestExtractor();
AttributesBuilder attributes = Attributes.builder();
extractor.onStart(attributes, context, request);
assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.RPC_SYSTEM, "test"), entry(SemanticAttributes.RPC_SERVICE, "my.Service"), entry(SemanticAttributes.RPC_METHOD, "Method"));
extractor.onEnd(attributes, context, request, null, null);
assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.RPC_SYSTEM, "test"), entry(SemanticAttributes.RPC_SERVICE, "my.Service"), entry(SemanticAttributes.RPC_METHOD, "Method"));
}
Aggregations