Skip to content

Commit

Permalink
feat: Update OTel smoke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PerfectSlayer committed Nov 2, 2023
1 parent a401c87 commit e651b2d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
8 changes: 4 additions & 4 deletions dd-smoke-tests/play-2.8-otel/app/actions/AbstractAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

public abstract class AbstractAction extends Action.Simple {

private final String operationName;
private final String spanName;

protected AbstractAction(String operationName) {
this.operationName = operationName;
protected AbstractAction(String spanName) {
this.spanName = spanName;
}

@Override
public CompletionStage<Result> call(Http.Request req) {
Tracer tracer = GlobalOpenTelemetry.getTracer("play-test");
Span span = tracer.spanBuilder(operationName).startSpan();
Span span = tracer.spanBuilder(spanName).startSpan();
Scope scope = span.makeCurrent();
try {
return delegate.call(req);
Expand Down
15 changes: 7 additions & 8 deletions dd-smoke-tests/play-2.8-otel/app/filters/AbstractFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@

public abstract class AbstractFilter extends Filter {
private final HttpExecutionContext ec;
private final String operationName;
private final String spanName;
private final boolean wrap;

public AbstractFilter(String operationName, Materializer mat, HttpExecutionContext ec) {
this(operationName, false, mat, ec);
public AbstractFilter(String spanName, Materializer mat, HttpExecutionContext ec) {
this(spanName, false, mat, ec);
}

public AbstractFilter(
String operationName, boolean wrap, Materializer mat, HttpExecutionContext ec) {
public AbstractFilter(String spanName, boolean wrap, Materializer mat, HttpExecutionContext ec) {
super(mat);
this.operationName = operationName;
this.spanName = spanName;
this.wrap = wrap;
this.ec = ec;
}
Expand All @@ -32,14 +31,14 @@ public CompletionStage<Result> apply(
Function<Http.RequestHeader, CompletionStage<Result>> nextFilter,
Http.RequestHeader requestHeader) {
final Tracer tracer = GlobalOpenTelemetry.getTracer("play-test");
final Span startedSpan = wrap ? tracer.spanBuilder(operationName).startSpan() : null;
final Span startedSpan = wrap ? tracer.spanBuilder(spanName).startSpan() : null;
Scope outerScope = wrap ? startedSpan.makeCurrent() : null;
try {
return nextFilter
.apply(requestHeader)
.thenApplyAsync(
result -> {
Span span = wrap ? startedSpan : tracer.spanBuilder(operationName).startSpan();
Span span = wrap ? startedSpan : tracer.spanBuilder(spanName).startSpan();
try (Scope innerScope = span.makeCurrent()) {
// Yes this does no real work
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ abstract class Play28OTelSmokeTest extends AbstractServerSmokeTest {
+ " -Dhttp.port=${httpPort}"
+ " -Dhttp.address=127.0.0.1"
+ " -Dplay.server.provider=${serverProvider()}"
+ " -Ddd.writer.type=MultiWriter:TraceStructureWriter:${output.getAbsolutePath()},DDAgentWriter"
+ " -Ddd.integration.opentelemetry.experimental.enabled=true"
+ " -Ddd.writer.type=MultiWriter:TraceStructureWriter:${output.getAbsolutePath()}:includeresource,DDAgentWriter"
+ " -Ddd.integration.opentelemetry-1.enabled=true"
+ " -Dclient.request.base=${clientServer.address}/hello/")
return processBuilder
}
Expand All @@ -77,14 +77,14 @@ abstract class Play28OTelSmokeTest extends AbstractServerSmokeTest {
// that is completed is completed before the span is finished, the order of those filters and the request processing
// is undefined.
boolean isOk = true
def allowed = /|^\[${serverProviderName()}.request
|(\[filter1(\[filter\d])(\[filter\d])(\[filter\d])])?
|\[play.request\[action1\[action2\[do-get\[play-ws.request]]]]]
|(\[filter1(\[filter\d])(\[filter\d])(\[filter\d])])?
def allowed = /|^\[${serverProviderName()}.request:GET \/welcome[sj]
|(\[otel_unknown:filter1(\[otel_unknown:filter\d])(\[otel_unknown:filter\d])(\[otel_unknown:filter\d])])?
|\[play.request:GET \/welcome[sj]\[otel_unknown:action1\[otel_unknown:action2\[otel_unknown:do-get\[play-ws.request:GET \/hello\/\?]]]]]
|(\[otel_unknown:filter1(\[otel_unknown:filter\d])(\[otel_unknown:filter\d])(\[otel_unknown:filter\d])])?
|]$/.stripMargin().replaceAll("[\n\r]", "")

// Ignore [command_execution], which can be generated by hostname calls from Config/Telemetry on some systems.
traceCounts = traceCounts.findAll { it.key != "[command_execution]" }
traceCounts = traceCounts.findAll { it.key != "[command_execution:hostname]" }

traceCounts.entrySet().each {
def matcher = (it.key =~ allowed).findAll()
Expand All @@ -94,9 +94,9 @@ abstract class Play28OTelSmokeTest extends AbstractServerSmokeTest {
|traceCounts=${traceCounts}""".stripMargin()
def matches = matcher.head().findAll{ it != null }
isOk &= matches.size() == 5
isOk &= matches.contains("[filter2]")
isOk &= matches.contains("[filter3]")
isOk &= matches.contains("[filter4]")
isOk &= matches.contains("[otel_unknown:filter2]")
isOk &= matches.contains("[otel_unknown:filter3]")
isOk &= matches.contains("[otel_unknown:filter4]")
assert isOk : """\
|Trace ${it.key} does not match allowed pattern:
|pattern=${allowed}
Expand Down

0 comments on commit e651b2d

Please sign in to comment.