Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
fix muzzle
  • Loading branch information
jpbempel committed Dec 3, 2024
1 parent 5bae273 commit 3de084c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
9 changes: 9 additions & 0 deletions dd-java-agent/instrumentation/micronaut/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

apply from: "$rootDir/gradle/java.gradle"

muzzle {
pass {
name = "micronaut-common"
group = "io.micronaut"
module = "micronaut-http-server-netty"
versions = "[2,)"
}
}

dependencies {
compileOnly group: 'io.micronaut', name: 'micronaut-http-server-netty', version: '2.0.0'
implementation project(':dd-java-agent:instrumentation:span-origin')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ addTestSuiteForDir('latestDepTest', 'test')

dependencies {
main_java17CompileOnly group: 'io.micronaut', name: 'micronaut-http-server-netty', version: '4.0.0'
implementation project(':dd-java-agent:instrumentation:micronaut')

// Added to ensure cross compatibility:
testImplementation project(':dd-java-agent:instrumentation:micronaut:http-server-netty-2.0')
testImplementation project(':dd-java-agent:instrumentation:micronaut:http-server-netty-3.0')
testImplementation project(':dd-java-agent:instrumentation:netty-4.1')
testImplementation project(':dd-java-agent:agent-debugger')
testImplementation group: 'io.micronaut', name: 'micronaut-http-server-netty', version: '4.0.0', {
exclude group: 'org.slf4j', module: 'slf4j-api'
exclude group: 'ch.qos.logback', module: 'logback-classic'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,55 @@
import datadog.trace.agent.test.asserts.TraceAssert
import datadog.trace.agent.test.base.HttpServer
import datadog.trace.agent.test.base.HttpServerTest
import datadog.trace.api.Config
import datadog.trace.api.DDSpanTypes
import datadog.trace.api.DDTags
import datadog.trace.api.config.TraceInstrumentationConfig
import datadog.trace.bootstrap.debugger.DebuggerContext
import datadog.trace.bootstrap.instrumentation.api.AgentTracer
import datadog.trace.bootstrap.instrumentation.api.Tags
import datadog.trace.instrumentation.micronaut.v4_0.MicronautDecorator
import datadog.trace.instrumentation.netty41.server.NettyHttpServerDecorator
import test.MicronautServer

import java.lang.reflect.Method

import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.ERROR
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_ENCODED_BOTH
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS
import static datadog.trace.api.DDTags.DD_CODE_ORIGIN_TYPE
import static datadog.trace.api.config.TraceInstrumentationConfig.CODE_ORIGIN_FOR_SPANS_ENABLED

class MicronautTest extends HttpServerTest<Object> {

def codeOriginRecorder

@Override
protected void configurePreAgent() {
super.configurePreAgent()
injectSysConfig(CODE_ORIGIN_FOR_SPANS_ENABLED, "true")
codeOriginRecorder = new DebuggerContext.CodeOriginRecorder() {
def invoked = false
@Override
String captureCodeOrigin(boolean entry) {
invoked = true
return "done"
}

@Override
String captureCodeOrigin(Method method, boolean entry) {
invoked = true
return "done"
}
}
DebuggerContext.initCodeOrigin(codeOriginRecorder)
}



@Override
HttpServer server() {
return new MicronautServer()
Expand Down Expand Up @@ -67,6 +101,9 @@ class MicronautTest extends HttpServerTest<Object> {

@Override
void handlerSpan(TraceAssert trace, ServerEndpoint endpoint = SUCCESS) {
if (endpoint != NOT_FOUND) {
assert codeOriginRecorder.invoked
}
trace.span {
serviceName expectedServiceName()
operationName "micronaut-controller"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public MicronautCodeOriginInstrumentation() {
super("micronaut", "micronaut-span-origin");
}

@Override
public String muzzleDirective() {
return "micronaut-common";
}

@Override
protected Set<String> getAnnotations() {
return new HashSet<>(
Expand Down

0 comments on commit 3de084c

Please sign in to comment.