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

Some assertions refactoring #6618

Merged
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 @@ -209,12 +209,8 @@ void parseError() {
assertThat(attrs)
.containsEntry("exception.type", "InvalidSyntax");
String message =
String.valueOf(
attrs
.asMap()
.get(
AttributeKey.stringKey(
"exception.message")));
attrs.get(
AttributeKey.stringKey("exception.message"));
assertThat(message).startsWith("Invalid Syntax");
}))));
}
Expand Down Expand Up @@ -256,12 +252,8 @@ void validationError() {
.containsEntry(
"exception.type", "ValidationError");
String message =
String.valueOf(
attrs
.asMap()
.get(
AttributeKey.stringKey(
"exception.message")));
attrs.get(
AttributeKey.stringKey("exception.message"));
assertThat(message)
.startsWith(
"Validation error of type FieldUndefined");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -921,10 +921,10 @@ SpanDataAssert assertClientSpan(
if (uri.getPort() == PortUtils.UNUSABLE_PORT || uri.getHost().equals("192.0.2.1")) {
// TODO: net.peer.name and net.peer.port should always be populated from the URI or
// the Host header, verify these assertions below
if (attrs.asMap().containsKey(SemanticAttributes.NET_PEER_NAME)) {
if (attrs.get(SemanticAttributes.NET_PEER_NAME) != null) {
assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_NAME, uri.getHost());
}
if (attrs.asMap().containsKey(SemanticAttributes.NET_PEER_PORT)) {
if (attrs.get(SemanticAttributes.NET_PEER_PORT) != null) {
if (uri.getPort() > 0) {
assertThat(attrs)
.containsEntry(SemanticAttributes.NET_PEER_PORT, (long) uri.getPort());
Expand All @@ -945,13 +945,12 @@ SpanDataAssert assertClientSpan(

// In these cases the peer connection is not established, so the HTTP client should
// not report any socket-level attributes
// TODO https://github.com/open-telemetry/opentelemetry-java/pull/4723
assertThat(attrs.asMap())
.doesNotContainKey(AttributeKey.stringKey("net.sock.family"))
assertThat(attrs)
.doesNotContainKey("net.sock.family")
// TODO netty sometimes reports net.sock.peer.addr in connection error test
// .doesNotContainKey(AttributeKey.stringKey("net.sock.peer.addr"))
.doesNotContainKey(AttributeKey.stringKey("net.sock.peer.name"))
.doesNotContainKey(AttributeKey.stringKey("net.sock.peer.port"));
// .doesNotContainKey("net.sock.peer.addr")
.doesNotContainKey("net.sock.peer.name")
.doesNotContainKey("net.sock.peer.port");

} else {
if (httpClientAttributes.contains(SemanticAttributes.NET_PEER_NAME)) {
Expand All @@ -962,11 +961,11 @@ SpanDataAssert assertClientSpan(
}

// TODO: Move to test knob rather than always treating as optional
if (attrs.asMap().containsKey(AttributeKey.stringKey("net.sock.peer.addr"))) {
if (attrs.get(AttributeKey.stringKey("net.sock.peer.addr")) != null) {
assertThat(attrs)
.containsEntry(AttributeKey.stringKey("net.sock.peer.addr"), "127.0.0.1");
}
if (attrs.asMap().containsKey(AttributeKey.stringKey("net.sock.peer.port"))) {
if (attrs.get(AttributeKey.stringKey("net.sock.peer.port")) != null) {
assertThat(attrs)
.containsEntry(
AttributeKey.longKey("net.sock.peer.port"),
Expand Down