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

Better error messages from SpanDataAssert#hasAttributesSatisfyingExactly(AttributeAssertion...) #5025

Closed
knutwannheden opened this issue Dec 8, 2022 · 1 comment · Fixed by #5027
Labels
Feature Request Suggest an idea for this project

Comments

@knutwannheden
Copy link
Contributor

This issue pertains to version 1.19.0. I have not checked with newer versions.

In my tests I am using SpanDataAssert#hasAttributesSatisfyingExactly(AttributeAssertion...) like in this example:

        assertThat(serverSpan).hasAttributesSatisfyingExactly(
                satisfies(AttributeKey.stringKey("http.scheme"), v -> v.isEqualTo("http")),
                satisfies(AttributeKey.stringKey("http.method"), v -> v.isEqualTo("POST")),
                satisfies(AttributeKey.longKey("http.status_code"), v -> v.isEqualTo(200L)),
                satisfies(AttributeKey.stringKey("http.route"), v -> v.isEqualTo("/txoutbox-test/failing-tasks")),
                satisfies(AttributeKey.stringKey("http.flavor"), v -> v.isEqualTo("1.1")),
                satisfies(AttributeKey.stringKey("http.target"), v -> v.isEqualTo("/txoutbox-test/failing-tasks")),
                satisfies(AttributeKey.stringKey("http.client_ip"), AbstractAssert::isNotNull),
                satisfies(AttributeKey.stringKey("http.host"), AbstractAssert::isNotNull),
                satisfies(AttributeKey.stringKey("http.user_agent"), AbstractAssert::isNotNull),
                satisfies(AttributeKey.longKey("http.request_content_length"), AbstractAssert::isNotNull),
                satisfies(AttributeKey.longKey("http.response_content_length"), AbstractAssert::isNotNull));

When one of the attribute assertions with a isNotNull assertion fails, there is no indication of which attribute this assertion failure pertains to:

java.lang.AssertionError: 
Expecting actual not to be null

	at io.opentelemetry.sdk.testing.assertj.SpanDataAssert.hasAttributesSatisfyingExactly(SpanDataAssert.java:330)
	at io.opentelemetry.sdk.testing.assertj.SpanDataAssert.hasAttributesSatisfyingExactly(SpanDataAssert.java:312)

With SpanDataAssert#hasAttribute(AttributeAssertion) OTOH this is much better:

java.lang.AssertionError: [span [/txoutbox-test/failing-tasks] attribute keys] 
Expecting UnmodifiableSet:
  [net.host.name,
    http.target,
    http.route,
    http.user_agent,
    http.flavor,
    http.request_content_length,
    http.status_code,
    http.method,
    http.response_content_length,
    net.host.port,
    http.client_ip,
    http.scheme]
to contain:
  [http.host]
but could not find the following element(s):
  [http.host]


	at io.opentelemetry.sdk.testing.assertj.SpanDataAssert.hasAttribute(SpanDataAssert.java:267)
@breedx-splk
Copy link
Contributor

I've had a similarly frustrating experience with attribute assertions. ➕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Suggest an idea for this project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants