Skip to content
Draft
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
1 change: 1 addition & 0 deletions .github/g2j-migrated-modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

buildSrc/call-site-instrumentation-plugin
components/json
dd-java-agent/instrumentation/opentelemetry/opentelemetry-1.4
dd-trace-api
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package datadog.trace.agent.test.assertions;

import static org.junit.jupiter.api.AssertionFailureBuilder.assertionFailure;

import java.util.Optional;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import org.opentest4j.AssertionFailedError;

/** This class is a utility class to create generic matchers. */
public final class Matchers {
Expand Down Expand Up @@ -103,12 +104,11 @@ public static <T> Matcher<T> any() {
static <T> void assertValue(Matcher<T> matcher, T value, String message) {
if (matcher != null && !matcher.test(value)) {
Optional<T> expected = matcher.expected();
if (expected.isPresent()) {
throw new AssertionFailedError(
message + ". " + matcher.failureReason(), expected.get(), value);
} else {
throw new AssertionFailedError(message + ": " + value + ". " + matcher.failureReason());
}
assertionFailure()
.message(message + ". " + matcher.failureReason())
.expected(expected.orElse(null))
.actual(value)
.buildAndThrow();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static datadog.trace.agent.test.assertions.Matchers.validates;
import static datadog.trace.core.DDSpanAccessor.spanLinks;
import static java.time.Duration.ofNanos;
import static org.junit.jupiter.api.AssertionFailureBuilder.assertionFailure;

import datadog.trace.api.TagMap;
import datadog.trace.bootstrap.instrumentation.api.AgentSpanLink;
Expand Down Expand Up @@ -322,7 +323,7 @@ private void assertSpanTags(TagMap tags) {
if (matcher == null) {
uncheckedTagNames.add(key);
} else {
assertValue(matcher, value, "Unexpected " + key + " tag value.");
assertValue(matcher, value, "Unexpected " + key + " tag value");
}
});
// Remove matchers that accept missing tags
Expand All @@ -344,10 +345,18 @@ private void assertSpanTags(TagMap tags) {
* It might evolve into partial link collection testing, matching links using TID/SIP.
*/
private void assertSpanLinks(List<AgentSpanLink> links) {
// Check if links should be asserted at all
if (this.linkMatchers == null) {
return;
}
int linkCount = links == null ? 0 : links.size();
int expectedLinkCount = this.linkMatchers == null ? 0 : this.linkMatchers.length;
int expectedLinkCount = this.linkMatchers.length;
if (linkCount != expectedLinkCount) {
throw new AssertionFailedError("Unexpected span link count", expectedLinkCount, linkCount);
assertionFailure()
.message("Unexpected span link count")
.expected(expectedLinkCount)
.actual(linkCount)
.buildAndThrow();
}
for (int i = 0; i < expectedLinkCount; i++) {
SpanLinkMatcher linkMatcher = this.linkMatchers[expectedLinkCount];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@
import static datadog.trace.agent.test.assertions.Matchers.any;
import static datadog.trace.agent.test.assertions.Matchers.is;
import static datadog.trace.agent.test.assertions.Matchers.isNonNull;
import static datadog.trace.api.DDTags.BASE_SERVICE;
import static datadog.trace.api.DDTags.DD_INTEGRATION;
import static datadog.trace.api.DDTags.DJM_ENABLED;
import static datadog.trace.api.DDTags.DSM_ENABLED;
import static datadog.trace.api.DDTags.ERROR_MSG;
import static datadog.trace.api.DDTags.ERROR_STACK;
import static datadog.trace.api.DDTags.ERROR_TYPE;
import static datadog.trace.api.DDTags.LANGUAGE_TAG_KEY;
import static datadog.trace.api.DDTags.PARENT_ID;
import static datadog.trace.api.DDTags.PID_TAG;
import static datadog.trace.api.DDTags.PROFILING_CONTEXT_ENGINE;
import static datadog.trace.api.DDTags.PROFILING_ENABLED;
import static datadog.trace.api.DDTags.REQUIRED_CODE_ORIGIN_TAGS;
import static datadog.trace.api.DDTags.RUNTIME_ID_TAG;
import static datadog.trace.api.DDTags.SCHEMA_VERSION_TAG_KEY;
import static datadog.trace.api.DDTags.SPAN_LINKS;
import static datadog.trace.api.DDTags.THREAD_ID;
import static datadog.trace.api.DDTags.THREAD_NAME;
import static datadog.trace.api.DDTags.TRACER_HOST;
import static datadog.trace.common.sampling.RateByServiceTraceSampler.SAMPLING_AGENT_RATE;
import static datadog.trace.common.writer.ddagent.TraceMapper.SAMPLING_PRIORITY_KEY;

import datadog.trace.api.DDTags;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -34,15 +44,17 @@ public static TagsMatcher defaultTags() {
tagMatchers.put(SAMPLING_AGENT_RATE, any());
tagMatchers.put(SAMPLING_PRIORITY_KEY.toString(), any());
tagMatchers.put("_sample_rate", any());
tagMatchers.put(DDTags.PID_TAG, any());
tagMatchers.put(DDTags.SCHEMA_VERSION_TAG_KEY, any());
tagMatchers.put(DDTags.PROFILING_ENABLED, any());
tagMatchers.put(DDTags.PROFILING_CONTEXT_ENGINE, any());
tagMatchers.put(DDTags.BASE_SERVICE, any());
tagMatchers.put(DDTags.DSM_ENABLED, any());
tagMatchers.put(DDTags.DJM_ENABLED, any());
tagMatchers.put(DDTags.PARENT_ID, any());
tagMatchers.put(DDTags.SPAN_LINKS, any()); // this is checked by LinksAsserter
tagMatchers.put(PID_TAG, any());
tagMatchers.put(SCHEMA_VERSION_TAG_KEY, any());
tagMatchers.put(PROFILING_ENABLED, any());
tagMatchers.put(PROFILING_CONTEXT_ENGINE, any());
tagMatchers.put(BASE_SERVICE, any());
tagMatchers.put(DSM_ENABLED, any());
tagMatchers.put(DJM_ENABLED, any());
tagMatchers.put(PARENT_ID, any());
tagMatchers.put(SPAN_LINKS, any()); // this is checked by LinksAsserter
tagMatchers.put(DD_INTEGRATION, any());
tagMatchers.put(TRACER_HOST, any());

for (String tagName : REQUIRED_CODE_ORIGIN_TAGS) {
tagMatchers.put(tagName, any());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package datadog.trace.agent.test.assertions;

import static java.util.function.Function.identity;
import static org.junit.jupiter.api.AssertionFailureBuilder.assertionFailure;

import datadog.trace.core.DDSpan;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import org.opentest4j.AssertionFailedError;

/**
* This class is a helper class to verify traces structure.
Expand Down Expand Up @@ -87,11 +87,19 @@ public static void assertTraces(
int traceCount = traces.size();
if (opts.ignoredAdditionalTraces) {
if (traceCount < expectedTraceCount) {
throw new AssertionFailedError("Not enough of traces", expectedTraceCount, traceCount);
assertionFailure()
.message("Not enough of traces")
.expected(expectedTraceCount)
.actual(traceCount)
.buildAndThrow();
}
} else {
if (traceCount != expectedTraceCount) {
throw new AssertionFailedError("Invalid number of traces", expectedTraceCount, traceCount);
assertionFailure()
.message("Invalid number of traces")
.expected(expectedTraceCount)
.actual(traceCount)
.buildAndThrow();
}
}
if (opts.sorter != null) {
Expand Down

This file was deleted.

Loading
Loading