Skip to content

Commit 4db94c9

Browse files
bm1549claude
andcommitted
Restore full span assertions in Synapse proxy client test
Replace the minimal span-existence-only assertions added to tolerate extra traces with full TraceAssert.assertTrace() calls using the existing serverSpan/proxySpan/clientSpan helpers. The test now validates service name, operation name, resource name, span type, error flag, parent–child relationships, tags (component, span kind, HTTP method/status/URL, peer IP/port), and distributed tracing — while still tolerating the variable number of internal Synapse traces by locating each expected trace by its root span resource name before asserting. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent bfbf557 commit 4db94c9

1 file changed

Lines changed: 32 additions & 23 deletions

File tree

  • dd-java-agent/instrumentation/synapse-3.0/src/test/groovy/datadog/trace/instrumentation/synapse3

dd-java-agent/instrumentation/synapse-3.0/src/test/groovy/datadog/trace/instrumentation/synapse3/SynapseTest.groovy

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -215,35 +215,44 @@ abstract class SynapseTest extends VersionedNamingTestBase {
215215
int statusCode = client.newCall(request).execute().code()
216216

217217
then:
218-
// Wait for at least 2 traces; Synapse proxy requests can sometimes produce
219-
// an additional trace from internal activity, so we tolerate extra traces.
218+
// Synapse proxy handling can occasionally produce extra internal traces beyond the expected two
219+
// (proxy+client trace and backend server trace), so we wait for at least 2 and filter to the
220+
// traces we care about rather than asserting on an exact count.
220221
TEST_WRITER.waitForTraces(2)
221-
def traces = new ArrayList<>(TEST_WRITER)
222-
assert traces.size() >= 2
223-
Collections.sort(traces, SORT_TRACES_BY_NAMES)
224-
225-
// Find key spans across all traces. Synapse can produce variable numbers of traces and spans
226-
// (e.g. extra internal activity), so we identify spans by resource name across all traces.
227-
def allSpans = traces.flatten()
228-
def proxyServerSpan = allSpans.find {
229-
it.resourceName.toString() == "POST /services/StockQuoteProxy"
222+
def allTraces = new ArrayList<>(TEST_WRITER)
223+
224+
// Identify the two expected traces by their root span resource name.
225+
def proxyTrace = allTraces.find { trace ->
226+
trace.any { it.resourceName.toString() == "POST /services/StockQuoteProxy" }
230227
}
231-
def clientSpan = allSpans.find {
232-
it.resourceName.toString() == "POST /services/SimpleStockQuoteService" &&
233-
it.spanType == DDSpanTypes.HTTP_CLIENT
228+
def serverTrace = allTraces.find { trace ->
229+
trace.any {
230+
it.resourceName.toString() == "POST /services/SimpleStockQuoteService" &&
231+
it.spanType == DDSpanTypes.HTTP_SERVER
232+
} && !trace.any { it.resourceName.toString() == "POST /services/StockQuoteProxy" }
234233
}
235-
def serverSpan = allSpans.find {
234+
235+
def allSpanDescriptions = allTraces.flatten().collect { it.resourceName.toString() + "(" + it.spanType + ")" }
236+
assert proxyTrace != null : "Expected proxy trace not found in ${allTraces.size()} traces: ${allSpanDescriptions}"
237+
assert serverTrace != null : "Expected backend server trace not found in ${allTraces.size()} traces: ${allSpanDescriptions}"
238+
239+
// Identify the client span so we can use it as the expected parent for the backend server span.
240+
def clientSpanFromProxyTrace = proxyTrace.find {
236241
it.resourceName.toString() == "POST /services/SimpleStockQuoteService" &&
237-
it.spanType == DDSpanTypes.HTTP_SERVER
242+
it.spanType == DDSpanTypes.HTTP_CLIENT
238243
}
244+
assert clientSpanFromProxyTrace != null : "Expected client span in proxy trace"
239245

240-
def allSpanDescriptions = allSpans.collect { it.resourceName.toString() + "(" + it.spanType + ")" }
241-
assert proxyServerSpan != null : "Expected proxy server span, found: ${allSpanDescriptions}"
242-
assert clientSpan != null : "Expected HTTP client span for forwarded call, found: ${allSpanDescriptions}"
243-
assert serverSpan != null : "Expected server span for forwarded call, found: ${allSpanDescriptions}"
244-
245-
// Verify distributed tracing: the client span's traceId was propagated to the server span
246-
assert clientSpan.traceId == serverSpan.traceId : "Expected client and server spans to share traceId, client traceId=${clientSpan.traceId}, server traceId=${serverSpan.traceId}"
246+
// Full span assertions using the existing helper methods, applied to each located trace.
247+
TraceAssert.assertTrace(serverTrace, 1) {
248+
serverSpan(it, 0, 'POST', statusCode, null, clientSpanFromProxyTrace, true)
249+
}
250+
TraceAssert.assertTrace(proxyTrace, 2) {
251+
proxySpan(it, 0, 'POST', statusCode)
252+
clientSpan(it, 1, 'POST', statusCode, span(0))
253+
// Verify distributed tracing: client span's traceId was propagated to the backend server span.
254+
assert span(1).traceId == clientSpanFromProxyTrace.traceId
255+
}
247256

248257
statusCode == 200
249258
}

0 commit comments

Comments
 (0)