Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only set server.port when server.address is set #9737

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ public InternalClientAttributesExtractor(
public void onStart(AttributesBuilder attributes, REQUEST request) {
AddressAndPort clientAddressAndPort = addressAndPortExtractor.extract(request);

if (emitStableUrlAttributes) {
internalSet(attributes, SemanticAttributes.CLIENT_ADDRESS, clientAddressAndPort.address);
if (clientAddressAndPort.port != null && clientAddressAndPort.port > 0) {
internalSet(attributes, SemanticAttributes.CLIENT_PORT, (long) clientAddressAndPort.port);
if (clientAddressAndPort.address != null) {
if (emitStableUrlAttributes) {
internalSet(attributes, SemanticAttributes.CLIENT_ADDRESS, clientAddressAndPort.address);
if (clientAddressAndPort.port != null && clientAddressAndPort.port > 0) {
internalSet(attributes, SemanticAttributes.CLIENT_PORT, (long) clientAddressAndPort.port);
}
}
if (emitOldHttpAttributes) {
internalSet(attributes, SemanticAttributes.HTTP_CLIENT_IP, clientAddressAndPort.address);
}
}
if (emitOldHttpAttributes) {
internalSet(attributes, SemanticAttributes.HTTP_CLIENT_IP, clientAddressAndPort.address);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,23 @@ public InternalServerAttributesExtractor(
public void onStart(AttributesBuilder attributes, REQUEST request) {
AddressAndPort serverAddressAndPort = addressAndPortExtractor.extract(request);

if (emitStableUrlAttributes) {
internalSet(attributes, SemanticAttributes.SERVER_ADDRESS, serverAddressAndPort.address);
}
if (emitOldHttpAttributes) {
internalSet(attributes, oldSemconvMode.address, serverAddressAndPort.address);
}

if (serverAddressAndPort.port != null
&& serverAddressAndPort.port > 0
&& captureServerPortCondition.test(serverAddressAndPort.port, request)) {
if (serverAddressAndPort.address != null) {
if (emitStableUrlAttributes) {
internalSet(attributes, SemanticAttributes.SERVER_PORT, (long) serverAddressAndPort.port);
internalSet(attributes, SemanticAttributes.SERVER_ADDRESS, serverAddressAndPort.address);
}
if (emitOldHttpAttributes) {
internalSet(attributes, oldSemconvMode.port, (long) serverAddressAndPort.port);
internalSet(attributes, oldSemconvMode.address, serverAddressAndPort.address);
}

if (serverAddressAndPort.port != null
&& serverAddressAndPort.port > 0
&& captureServerPortCondition.test(serverAddressAndPort.port, request)) {
if (emitStableUrlAttributes) {
internalSet(attributes, SemanticAttributes.SERVER_PORT, (long) serverAddressAndPort.port);
}
if (emitOldHttpAttributes) {
internalSet(attributes, oldSemconvMode.port, (long) serverAddressAndPort.port);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,21 @@ void doesNotSetNegativePortValue() {
extractor.onEnd(endAttributes, Context.root(), request, null, null);
assertThat(endAttributes.build()).isEmpty();
}

@Test
void portWithoutAddress() {
Map<String, String> request = new HashMap<>();
request.put("port", "80");

AttributesExtractor<Map<String, String>, Void> extractor =
ClientAttributesExtractor.create(new TestClientAttributesGetter());

AttributesBuilder startAttributes = Attributes.builder();
extractor.onStart(startAttributes, Context.root(), request);
assertThat(startAttributes.build()).isEmpty();

AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), request, null, null);
assertThat(endAttributes.build()).isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,21 @@ void doesNotSetNegativePortValue() {
assertThat(startAttributes.build())
.containsOnly(entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"));
}

@Test
void portWithoutAddress() {
Map<String, String> request = new HashMap<>();
request.put("port", "80");

AttributesExtractor<Map<String, String>, Void> extractor =
ServerAttributesExtractor.create(new TestServerAttributesGetter());

AttributesBuilder startAttributes = Attributes.builder();
extractor.onStart(startAttributes, Context.root(), request);
assertThat(startAttributes.build()).isEmpty();

AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), request, null, null);
assertThat(endAttributes.build()).isEmpty();
}
}
Loading