use of io.opentelemetry.api.common.AttributesBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class MessagingAttributesExtractorTest method shouldExtractNoAttributesIfNoneAreAvailable.
@Test
void shouldExtractNoAttributesIfNoneAreAvailable() {
// given
TestMessagingAttributesExtractor underTest = new TestMessagingAttributesExtractor(MessageOperation.SEND);
Context context = Context.root();
// when
AttributesBuilder startAttributes = Attributes.builder();
underTest.onStart(startAttributes, context, Collections.emptyMap());
AttributesBuilder endAttributes = Attributes.builder();
underTest.onEnd(endAttributes, context, Collections.emptyMap(), null, null);
// then
assertThat(startAttributes.build().isEmpty()).isTrue();
assertThat(endAttributes.build().isEmpty()).isTrue();
}
use of io.opentelemetry.api.common.AttributesBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class PeerServiceAttributesExtractorTest method shouldSetPeerIpIfItMatchesAndNameDoesNot.
@Test
void shouldSetPeerIpIfItMatchesAndNameDoesNot() {
// given
Map<String, String> peerServiceMapping = new HashMap<>();
peerServiceMapping.put("example.com", "myService");
peerServiceMapping.put("1.2.3.4", "someOtherService");
PeerServiceAttributesExtractor<String, String> underTest = new PeerServiceAttributesExtractor<>(peerServiceMapping, netAttributesExtractor);
given(netAttributesExtractor.peerName(any(), any())).willReturn("test.com");
given(netAttributesExtractor.peerIp(any(), any())).willReturn("1.2.3.4");
Context context = Context.root();
// when
AttributesBuilder startAttributes = Attributes.builder();
underTest.onStart(startAttributes, context, "request");
AttributesBuilder endAttributes = Attributes.builder();
underTest.onEnd(endAttributes, context, "request", "response", null);
// then
assertThat(startAttributes.build()).isEmpty();
assertThat(endAttributes.build()).containsOnly(entry(SemanticAttributes.PEER_SERVICE, "someOtherService"));
}
use of io.opentelemetry.api.common.AttributesBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class PeerServiceAttributesExtractorTest method shouldSetPeerNameIfItMatches.
@Test
void shouldSetPeerNameIfItMatches() {
// given
Map<String, String> peerServiceMapping = new HashMap<>();
peerServiceMapping.put("example.com", "myService");
peerServiceMapping.put("1.2.3.4", "someOtherService");
PeerServiceAttributesExtractor<String, String> underTest = new PeerServiceAttributesExtractor<>(peerServiceMapping, netAttributesExtractor);
given(netAttributesExtractor.peerName(any(), any())).willReturn("example.com");
Context context = Context.root();
// when
AttributesBuilder startAttributes = Attributes.builder();
underTest.onStart(startAttributes, context, "request");
AttributesBuilder endAttributes = Attributes.builder();
underTest.onEnd(endAttributes, context, "request", "response", null);
// then
assertThat(startAttributes.build()).isEmpty();
assertThat(endAttributes.build()).containsOnly(entry(SemanticAttributes.PEER_SERVICE, "myService"));
}
use of io.opentelemetry.api.common.AttributesBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class PeerServiceAttributesExtractorTest method shouldNotSetAnyValueIfNetExtractorReturnsNulls.
@Test
void shouldNotSetAnyValueIfNetExtractorReturnsNulls() {
// given
Map<String, String> peerServiceMapping = singletonMap("1.2.3.4", "myService");
PeerServiceAttributesExtractor<String, String> underTest = new PeerServiceAttributesExtractor<>(peerServiceMapping, netAttributesExtractor);
Context context = Context.root();
// when
AttributesBuilder attributes = Attributes.builder();
underTest.onStart(attributes, context, "request");
underTest.onEnd(attributes, context, "request", "response", null);
// then
assertTrue(attributes.build().isEmpty());
}
use of io.opentelemetry.api.common.AttributesBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class HttpServerAttributesExtractorTest method extractClientIpFromX_Forwarded_Proto.
@Test
void extractClientIpFromX_Forwarded_Proto() {
Map<String, String> request = new HashMap<>();
request.put("header.x-forwarded-proto", "https");
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_SCHEME, "https"));
extractor.onEnd(attributes, Context.root(), request, null, null);
assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.HTTP_SCHEME, "https"));
}
Aggregations