Explicitly check for key for attribute assertions using hasEntrySatis… (#3703)
* Explicitly check for key for attribute assertions using hasEntrySatisfying * Check test user agent set first
This commit is contained in:
parent
4617a0475a
commit
e4fcbb8f51
|
@ -997,6 +997,10 @@ public abstract class AbstractHttpClientTest<REQUEST> {
|
|||
if (httpClientAttributes.contains(SemanticAttributes.HTTP_USER_AGENT)) {
|
||||
String userAgent = userAgent();
|
||||
if (userAgent != null) {
|
||||
// TODO(anuraaga): Remove after updating to SDK 1.5.0 which adds this into
|
||||
// hasEntrySatisfying.
|
||||
// https://github.com/open-telemetry/opentelemetry-java/pull/3433
|
||||
assertThat(attrs.asMap()).containsKey(SemanticAttributes.HTTP_USER_AGENT);
|
||||
assertThat(attrs)
|
||||
.hasEntrySatisfying(
|
||||
SemanticAttributes.HTTP_USER_AGENT,
|
||||
|
@ -1004,6 +1008,10 @@ public abstract class AbstractHttpClientTest<REQUEST> {
|
|||
}
|
||||
}
|
||||
if (httpClientAttributes.contains(SemanticAttributes.HTTP_HOST)) {
|
||||
// TODO(anuraaga): Remove after updating to SDK 1.5.0 which adds this into
|
||||
// hasEntrySatisfying.
|
||||
// https://github.com/open-telemetry/opentelemetry-java/pull/3433
|
||||
assertThat(attrs.asMap()).containsKey(SemanticAttributes.HTTP_HOST);
|
||||
// TODO(anuraaga): It's not well defined when instrumentation records with and
|
||||
// without port. We should make this more uniform
|
||||
assertThat(attrs)
|
||||
|
@ -1012,12 +1020,22 @@ public abstract class AbstractHttpClientTest<REQUEST> {
|
|||
host -> assertThat(host).startsWith(uri.getHost()));
|
||||
}
|
||||
if (httpClientAttributes.contains(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH)) {
|
||||
// TODO(anuraaga): Remove after updating to SDK 1.5.0 which adds this into
|
||||
// hasEntrySatisfying.
|
||||
// https://github.com/open-telemetry/opentelemetry-java/pull/3433
|
||||
assertThat(attrs.asMap())
|
||||
.containsKey(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH);
|
||||
assertThat(attrs)
|
||||
.hasEntrySatisfying(
|
||||
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH,
|
||||
length -> assertThat(length).isNotNegative());
|
||||
}
|
||||
if (httpClientAttributes.contains(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH)) {
|
||||
// TODO(anuraaga): Remove after updating to SDK 1.5.0 which adds this into
|
||||
// hasEntrySatisfying.
|
||||
// https://github.com/open-telemetry/opentelemetry-java/pull/3433
|
||||
assertThat(attrs.asMap())
|
||||
.containsKey(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH);
|
||||
assertThat(attrs)
|
||||
.hasEntrySatisfying(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
|
|
Loading…
Reference in New Issue